const net = require('net');
const crypto = require('crypto');
const handshake = `GET / HTTP/1.1
Host: 192.168.43.135:12345
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: file://
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4
Sec-WebSocket-Key: bKdPyn3u98cTfZJSh4TNeQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
`;
const s = net.connect(8080);
s.on('data', d => {
if (/HTTP\/1\.1 101 Switching Protocols/.test(d)) {
s.write(composeFrame('{"type": "handshake"}'));
setTimeout(
() => s.write(composeFrame('{"type":"action", "value":"move"}')),
10000
);
}
});
s.write(handshake);
function composeFrame(text) {
const mask = crypto.randomBytes(4);
return Buffer.from([
0b10000001,
0b10000000 | text.length,
...mask,
...[...Buffer.from(text)].map((e, i) => e ^ mask[i % 4])
]);
}const arr1 = [
[ 432432, 23423, 123123, 54364346],
[ 756456, 2423423, 645654, 23423423],
[ 12354, 123123, 23423423, 1235765]
]
const arr3 = [ 12354, 5345, 53456346 ]
const arrResult = arr1
.flat(Infinity)
.filter(el => arr3.includes(el))
console.log(arrResult)
// Array [ 12354 ]const arr1 = [
[ 432432, 23423, 123123, 54364346],
[ 756456, 2423423, 645654, 23423423],
[ 12354, 123123, 23423423, 1235765]
]
const arr3 = [ 12354, 5345, 53456346 ]
const arr1s = arr1.flat(Infinity)
arr1s.sort((a, b) => a - b)
const arr3s = arr3.slice()
arr3s.sort((a, b) => a - b)
const arrResult = []
for (let i = 0, let j = 0; i < arr1s.length, j < arr3s.length;) {
if (arr1s[i] === arr3s[j]) {
arrResult.push(arr1s[i])
i += 1
} else if (arr1s[i] < arr3s[j]) {
i += 1
} else {
j += 1
}
}
console.log(arrResult)
// Array [ 12354 ]
найти последний div
const last = document.querySelector('#container').lastElementChild;остальные удалить
Array.prototype.reduceRight.call(
document.getElementById('container').children,
(_, n) => n?.nextElementSibling && n.replaceWith(),
null
);const last = Array
.from(document.querySelectorAll('[id="container"] > *'))
.reduce((_, n, i, a) => i === ~-a.length ? n : n.remove(), null);
arr = [[11,22], [33,44]]
console.log ( arr.flat() )
const key = 'workplace';
const values = [ 'office', 'hotel' ];const result = arr.filter(function(n) {
return this.has(n[key]);
}, new Set(values));
// или
const result = values.flatMap(((grouped, n) => grouped[n] ?? []).bind(
null,
arr.reduce((acc, n) => ((acc[n[key]] = acc[n[key]] ?? []).push(n), acc), {})
));
// или
const result = [];
for (const n of arr) {
for (const m of values) {
if (m === n[key]) {
result.push(n);
break;
}
}
}
// или
const result = [];
for (let i = 0; i < arr.length; i++) {
if (~values.indexOf(arr[i][key])) {
result[result.length] = arr[i];
}
}
// или
const result = (function get(i, n = arr[i]) {
return n
? [].concat(values.includes(n[key]) ? n : [], get(-~i))
: [];
})(0); var members = API.friends.get({
"count": 5000,
"fields": "photo_max",
"offset": 0,
"v": 5.103
}).items;
members = members + API.friends.get({
"count": 5000,
"fields": "photo_max",
"offset": 5000,
"v": 5.103
}).items;
return members;