- 1
- 2
var a=new Array();
a['line']=document.getElementById('water_disconnection_search').value;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
var a=new Array();
a['line']=document.getElementById('water_disconnection_search').value;
array-oriented programming
https://www.teplosetspb.ru/water_disconnection
−1
var data = { //Списочек с русскими названиями
"Рыбы": {
"Форель": {},
"Щука": {}
},
"Деревья": {
"Хвойные": {
"Лиственница": {},
"Ель": {}
},
"Цветковые": {
"Берёза": {},
"Тополь": {}
}
}
};
function createTree(container, data) { // Создание списка из объекта
let mainUL = document.createElement('ul'); //Начало списка
let findLI = function(item, UL) { //рекурсивная функция
for(let k in item) { //перебор
let LI = document.createElement('li'); //Новый элемент списка
LI.textContent = k; //Устанавливаем текст элементу
UL.appendChild(LI); //Добавляем элемент в список
if(Object.keys(item[k]).length > 0) { //Есть ли там ещё элементы?
let newUl = document.createElement('ul'); //Новый список
UL.appendChild(newUl); //Фигачим его в список
findLI(item[k], newUl); //Тут мы посылаем ссылку поэтому всё робит
}
}
}
findLI(data, mainUL); //ищем все элементы
container.appendChild(mainUL); //добавляем в контейнер список (в конец)
}
var container = document.getElementById('container'); //ищем контейнер
createTree(container, data); // создаём спсиок
Комментатор 80-го уровня.
Жду ваших комментариев ублюдки!
0
const uuid = require('uuid');
const param = process.argv[2];
const count = Number(param);
if(typeof count !== 'number' || isNaN(count) || count < 0) {
console.error(`bad number parameter ${param}`);
return;
}
console.log('namespace LotsofClass {');
for(let i = 0; i <= count; i++) {
console.log(`class Class${uuid.v4().replace(/-/g, '')}{}`);
}
console.log('}');
+3
return query instanceof RegExp ?
(function () {
fn.each(function (id) {
if (id.match(query)) {
seatSet.push(id, this);
}
});
return seatSet;
})() :
(query.length == 1 ?
(function (character) {
//user searches just for a particual character
fn.each(function () {
if (this.char() == character) {
seatSet.push(this.settings.id, this);
}
});
return seatSet;
})(query) :
(function () {
//user runs a more sophisticated query, so let's see if there's a dot
return query.indexOf('.') > -1 ?
(function () {
//there's a dot which separates character and the status
var parts = query.split('.');
fn.each(function (seatId) {
if (this.char() == parts[0] && this.status() == parts[1]) {
seatSet.push(this.settings.id, this);
}
});
return seatSet;
})() :
(function () {
fn.each(function () {
if (this.status() == query) {
seatSet.push(this.settings.id, this);
}
});
return seatSet;
})();
})()
);
https://github.com/mateuszmarkowski/jQuery-Seat-Charts -- отсюда, заставила нелегкая использовать на одном мелком проекте. в пост запилил самый блистательный и ароматный кусок
−1
if (typeof _dragon_pic_shift[el]['did'] === typeof undefined || typeof _dragon_pic_shift[el]['pic_id'] === typeof undefined ) {
continue;
}
if (_dragon_pic_shift[el]['did'].indexOf(active_dragon_id) >= 0
&& _dragon_pic_shift[el]['pic_id'].indexOf(active_dragon_lvl) >= 0
&& _dragon_pic_shift[el]['place'] == this_place) {
css_shift_class = _dragon_pic_shift[el]['css_shift'];
break;
}
это какой то новый уровень построения условий в js
0
'use strict';
function map(fn, array) {
let arr = [];
for(let i of array)
arr.push(fn(i));
return arr;
}
function take(fn, count) {
var arr = [];
for(let i = 0; i < count; i++)
arr.push(fn());
return arr;
}
function sequence(start, step)
{
step = step || 1;
start = start || 0;
start-=step;
return function() {
return start+=step;
}
}
function fmap(a, gen) {
return (...args) => {
if(args.length > 0)
return a(gen(...args));
else
return a(gen());
};
}
function partial(fn, ...args) {
return (...twoArgs) => {
let newM = args.slice();
for(let k of twoArgs)
newM.push(k);
return fn(...newM);
};
}
function partialAny(fn, ...args) {
return (...twoArgs) => {
let newM = args.slice();
let k = 0;
for(let i = 0; i < newM.length; i++)
if(newM[i] === undefined)
newM[i] = twoArgs[k++];
while(twoArgs[k] !== undefined) {
newM.push(twoArgs[k]);
k++;
}
return fn(...newM);
};
}
function bind(fn, context) {
return (...args) => {
return fn.apply(context, args);
};
}
function pluck(objects, fieldName) {
let a = [];
for(let i = 0; i < objects.length; i++)
if(objects[i][fieldName] !== undefined)
a.push(objects[i][fieldName]);
return a;
}
function filter(arr, fn) {
let a = [];
arr.forEach((item, i, arr) => {
if(fn(item))
a.push(item);
});
return a;
}
function count(arr) {
return Object.keys(arr).length;
}
var a = { a: 1, b: 2 };
console.log(count(a)); // 2
var b = function () {};
console.log(count(b)); // 0
var c = [1, 2, 3];
console.log(count(c)); // 3
var d = [];
d[100] = 1;
console.log(count(d)); // 1
Ня (^_^)
Суперкодики!
−1
buildChartStaffNeed: function() {
Stat.staffNeedWithTopIs = [];
var levelEducation = $('#level_education_filter').selectpicker('val');
var specId = $('#spec_filter').selectpicker('val');
var specTitle = $('#spec_filter option:selected').text();
var filter = JSON.parse(getKeyByUrl('filter'));
filter.specialty_id = specId;
filter.level_education = levelEducation;
$('#stat_detalise').show();
if (specId) {
$.ajax({
url: "/index.php/ajax/staff/get_need_by_spec_id/",
type: "POST",
dataType:'json',
data: {filter: JSON.stringify(filter)},
success: function(r) {
var regions = [];
var regionPrognosis = [];
var staffNeed = r.data.need.staff_need;
for (var i in staffNeed) {
var exist = inArray(staffNeed[i].region_title, regions);
if (typeof exist == 'boolean' && exist == false) {
regions.push(staffNeed[i].region_title);
regionPrognosis.push([0,0,0,0,0,0,0,0,0,0]);
}
}
for (var i in staffNeed) {
if (typeof inArray(staffNeed[i].region_title, regions) != 'boolean') {
var index = inArray(staffNeed[i].region_title, regions);
var currPrognoise = staffNeed[i].years_prognoses.split('|');
for (var p in currPrognoise) {
var cp = currPrognoise[p].split('-');
regionPrognosis[index][p] += cp[1] * 1;
}
}
}
var regionsHtmlBody = '';
for (var i in regions) {
regionsHtmlBody += "<tr>";
regionsHtmlBody += "<td>"+ incrementNum(i) +"</td>";
var regionTitle = regions[i] == null ? 'Не определено' : regions[i];
regionsHtmlBody += "<td>"+ regionTitle +"</td>";
for (var p in regionPrognosis[i]) {
regionsHtmlBody += "<td>"+ regionPrognosis[i][p] +"</td>";
}
regionsHtmlBody += "</tr>";
}
$('#spec_subjects').find('tbody').html(regionsHtmlBody);
var allCount = [0,0,0,0,0,0,0,0,0,0];
for (var i in regionPrognosis) {
for (var j in regionPrognosis[i]) {
allCount[j] += regionPrognosis[i][j];
}
}
var allHtml = '<tr><td></td><td><b>Всего:</b></td>';
for (var i in allCount) {
allHtml += '<td><b>' + allCount[i] + '</b></td>';
}
allHtml += '</tr>';
$('#spec_subjects').find('tbody').append(allHtml);
var industrys = [];
var industryPrognosis = [];
for (var i in staffNeed) {
var exist = inArray(staffNeed[i].industry_title, industrys);
if (typeof exist == 'boolean' && exist == false) {
industrys.push(staffNeed[i].industry_title);
industryPrognosis.push([0,0,0,0,0,0,0,0,0,0]);
}
}
for (var i in staffNeed) {
if (typeof inArray(staffNeed[i].industry_title, industrys) != 'boolean') {
var index = inArray(staffNeed[i].industry_title, industrys);
var currPrognoise = staffNeed[i].years_prognoses.split('|');
for (var p in currPrognoise) {
var cp = currPrognoise[p].split('-');
industryPrognosis[index][p] += cp[1] * 1;
}
}
}
+7
console.log(24000);
0
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import { Provider } from 'react-redux';
import Store from './src/Store';
import { Header, CryptoContainer, ControlPanel, Homepage } from './src/components';
import Drawer from 'react-native-drawer';
import {
Scene,
Router,
Actions,
Reducer,
ActionConst,
Overlay,
Tabs,
Modal,
Stack,
Lightbox,
} from 'react-native-router-flux';
export default class App extends Component {
constructor(props) {
super(props);
this.state = { isOpen: false };
}
toggleSidebar = () => {
console.debug(this.state.isOpen);
if (this.state.isOpen) {
this._drawer.close();
} else {
this._drawer.open();
}
}
onOpen = () => {
console.debug('onOpen');
this.setState({ isOpen: true });
}
onClose = () => {
console.debug('onClose');
this.setState({ isOpen: false });
}
render() {
// <View>
// <Header toggleSidebar={this.toggleSidebar} />
// <CryptoContainer />
// </View>
return (
<Provider store={Store}>
<View>
<Drawer
content={<ControlPanel />}
ref={(ref) => this._drawer = ref}
openDrawerOffset={100}
onOpen={this.onOpen}
onClose={this.onClose}
openDrawerOffset={0.5}
tapToClose={true}
// open={true}
>
</Drawer>
<View>
<Header toggleSidebar={this.toggleSidebar} />
{/* <CryptoContainer /> */}
</View>
<Router>
<Stack key="root">
<Scene key="homepage" component={Homepage} title="Homepage" />
</Stack>
</Router>
</View>
</Provider>
);
}
}
0
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import { Provider } from 'react-redux';
import Store from './src/Store';
import { Header, CryptoContainer, ControlPanel, Homepage } from './src/components';
import Drawer from 'react-native-drawer';
import {
Scene,
Router,
Actions,
Reducer,
ActionConst,
Overlay,
Tabs,
Modal,
Stack,
Lightbox,
} from 'react-native-router-flux';
export default class App extends Component {
constructor(props) {
super(props);
this.state = { isOpen: false };
}
toggleSidebar = () => {
console.debug(this.state.isOpen);
if (this.state.isOpen) {
this._drawer.close();
} else {
this._drawer.open();
}
}
onOpen = () => {
console.debug('onOpen');
this.setState({ isOpen: true });
}
onClose = () => {
console.debug('onClose');
this.setState({ isOpen: false });
}
render() {
// <View>
// <Header toggleSidebar={this.toggleSidebar} />
// <CryptoContainer />
// </View>
return (
<Provider store={Store}>
<Drawer
content={<ControlPanel />}
ref={(ref) => this._drawer = ref}
openDrawerOffset={100}
onOpen={this.onOpen}
onClose={this.onClose}
openDrawerOffset={0.5}
tapToClose={true}
// open={true}
>
<View>
<Router>
<Stack key="root">
<Scene key="homepage" component={Homepage} title="Homepage" />
</Stack>
</Router>
</View>
</Drawer>
</Provider>
);
}
}