const promiseList = [
new Promise(resolve => setTimeout(resolve, 200, 15)),
new Promise(resolve => setTimeout(resolve, 600, 17)),
new Promise(resolve => setTimeout(resolve, 500, 42))
];
async function* promiseGenerator(arrPromise) {
const result = [];
const push = (val) => result.push(val);
const promises = arrPromise.map((promise) => promise.then(push));
await Promise.all(promises);
for (let i = result.length - 1; i >= 0; --i) {
yield result[i];
}
}
function example() {
for (let i = 1; i <= 3; i++) {
this['zp' + i] = prompt('Введите зарплату '+ [i]+ ' сотрудника');
}
console.log(zp1, zp2, zp3);
}
example();
new Set([...arr1, ...arr2]).size < arr1.length + arr2.length
arr1.find(v => arr2.includes(v))
function arrayHaveMatches(arr1, arr2) {
const arrays = [arr1, arr2]
const indexes = [0, 0]
let currArray = arr2[0] < arr1[0]
let val2 = arrays[!currArray][0]
while (indexes[currArray] < arrays[currArray].length) {
const val1 = arrays[currArray][indexes[currArray]]
if (val1 === val2) {
return true
} else if (val1 > val2) {
currArray = !currArray
val2 = val1
}
indexes[currArray] ++
}
return false
}
array.reduceRight((acc, n) => ({ ...n, children: [ ...n.children, acc ] }), { ...obj })
const array = Array.from({ length: 20 }, (v, i) =>
Math.floor(Math.random() * (10 - 1) + 1 ));
const set = new Set(array);
const result = [...set].slice(0, 5);
console.log(result);
const array = Array.from({ length: 10 }, (v, i) => i)
.sort((a, b) => 0.5 - Math.random())
.slice(0, 5);
console.log(array);
const compare= (v, v2) => {
const parts = String(v).split('.')
const pow = parts.length > 1 ? parts.pop().length : 0
return Math.round(Math.abs(v - v2) * Math.pow(10, pow)) <= 1
}
console.log(compare(7.98, 7.99)) // true
console.log(compare(7.98, 7.97)) // true
console.log(compare(7.98, 8)) // false
console.log(compare(0.1, 0.15)) // true
const compare= (v, v2) => {
const parts = [v, v2].map(v => String(v).split('.'))
const pow = Math.max(...parts.map(v => v.length > 1 ? v.pop().length : 0))
return Math.round(Math.abs(v - v2) * Math.pow(10, pow)) <= 1
}
console.log(compare(7.98, 7.99)) // true
console.log(compare(7.98, 7.97)) // true
console.log(compare(7.98, 8)) // false
console.log(compare(0.1, 0.15)) // false
Чтобы узнать подробнее, нужно иметь историю событий. Программа atop умеет вести учет процессов и ресурсов, позволяя позже проиграть историю, выяснив причину проблемы.
https://haydenjames.io/use-atop-linux-server-perfo...
https://haydenjames.io/linux-server-performance-di...
const createList = arr => arr.reduceRight((acc, n) => ({ val: n, next: acc }), null);
const list = createList([ 1, 2, 3, 4 ]);