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>");
});
});
int[] arr = new int[] { 1, 2, 3, 4, 5 };
for (int value : arr) { // перебор всех значений массива arr начиная с нулевого и до последнего включая
System.out.print(value); // 12345
}
System.out.println("");
// тоже самое можно переписать так:
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]); // 12345
}
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);
}
}
}