// Илья Кантор - http://learn.javascript.ru
// Николас Закас - JavaScript для профессиональных веб-разработчиков
let arr1 = ["Alex", "Nick", "John", "Sasha", "Bill", "Donald", "Pit"];
let arr2 = ["Nick", "Bill", "Alex", "Masha", "Pasha", "Pit"];
let obj = {};
for (let i = 0; i < arr1.length; i += 1) {
for (let j = 0; j < arr2.length; j += 1) {
if (arr1[i] === arr2[j]) {
obj[arr1[i]] = true;
}
}
}
// Или так
// for (let i = 0; i < arr1.length; i += 1) {
// if (arr2.includes(arr1[i])) {
// obj[arr1[i]] = true;
// }
// }
console.log(Object.keys(obj)); // ["Alex", "Nick", "Bill", "Pit"]
StationsSort.sort(function(s1,s2) {
// some code
})
let arr = [5, 4, 7, 2, 1, 8, 6, 0];
arr.sort((a, b) => {
if (a < b) {
return -1;
} else if (a > b) {
return 1;
} else {
return 0;
}
}); // [0, 1, 2, 4, 5, 6, 7, 8]
$.get(URL + '/stations.json', function(data) {
var j1 = 0;
$.each(data, function(j1) {
Stations[this.sindex] = this;
StationsSort[j1] = this;
j1++;
});
var date = new Date();
dstmp = date.getTime();
$.each(StationsSort, function() {
lastMsg = Math.floor(dstmp / 1000) - this.last_at;
style = '';
if (lastMsg < 10800) {
style = "style=\"background: #8affbb;\"";
}
StationsSort.sort(function(s1, s2) {
if (s1.sindex > s2.sindex)
return 1;
if (s1.sindex < s2.sindex)
return -1;
else
return 0;
});
$('#station-list').append("<div " + style + " class='st-btn' title='" + EncodeHTML(this.station_name) + "' onclick=\"StationProcess(this, '" + EncodeHTML(this.sindex) + "')\">" + EncodeHTML(this.sindex) + ' - ' + EncodeHTML(this.station_name) + "</div>");
});
});
var item_arr = new Array();
request.on("row", function(columns) {
if (0 == item_arr.length) {
var items = new Array();
items.push(columns[0].value);
items.push(columns[1].value);
items.push(columns[2].value);
items.push(columns[3].value);
if(columns[4].value == null){
items.push(0);
} else {
items.push(columns[4].value);
}
item_arr.push(items);
} else {
for (var i = 0; i < item_arr.length; i += 1) {
if (item_arr[i][0] == columns[0].value) {
item_arr[i][4] = Number(item_arr[i][4]) + Number(columns[4].value);
item_arr[i][3] = Number(item_arr[i][3]) + Number(columns[3].value);
} else {
var items = new Array();
items.push(columns[0].value);
items.push(columns[1].value);
items.push(columns[2].value);
items.push(columns[3].value);
if(columns[4].value == null) {
items.push(0);
} else {
items.push(columns[4].value);
}
item_arr.push(items);
}
}
}
function func() {
var arr = [];
for (var i = 0; i < 3; i++) {
var tmp = (function(i) {
return function() {
console.log(i);
};
})(i);
arr.push(tmp);
}
return arr;
}
var arr = func();
arr[0]();
arr[1]();
arr[2]();
let letFunc = () => {
let arr = [];
for (let i = 0; i < 3; i++) {
arr.push(() => console.log(i));
}
return arr;
}
let letArr = letFunc();
letArr[0]();
letArr[1]();
letArr[2]();
var mylist = ["first", "second", "thrid", "fourth", "fifth"];
for (var i = 0; i < mylist.length; i++) {
var button = document.createElement("button");
button.className = mylist[i];
button.textContent = mylist[i];
document.querySelector(".button-list").appendChild(button);
}