const result = allCass.filter(function(n) {
return !this.has(n.id);
}, new Set(defaultCass.map(n => n.id)));function* diff(data1, data2, key = n => n) {
const getKey = key instanceof Function ? key : n => n[key];
const keys = new Set;
for (const n of data2) {
keys.add(getKey(n));
}
for (const n of data1) {
if (!keys.has(getKey(n))) {
yield n;
}
}
}const result = [...diff(allCass, defaultCass, 'id')];Array.from(diff('abcdE', 'AcD', n => n.toLowerCase())) // ['b', 'E']for (const n of diff(Array(8).keys(), Array(5).keys())) {
console.log(n); // 5 6 7
} DELETE FROM `comments`
WHERE `user_id` = :user_id
and `id` = :comment_id
arr.sort((a, b) => a.surname.localeCompare(b.surname) || a.name.localeCompare(b.name));const sorted = (arr, keys) => arr
.map(n => [ n ].concat(keys(n)))
.sort((a, b) => {
let diff = 0;
a.find((n, i) => diff = i && ((n < b[i]) ? -1 : +(n > b[i])));
return diff;
})
.map(n => n[0]);
const sortedArr = sorted(arr, n => [ n.surname.toLowerCase(), n.name.toLowerCase() ]); function getTextNodes() {
var n, a=[], walk=document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
while (n=walk.nextNode()) a.push(n);
return a;
}
data.find(el => el.item === 'geovishap-hatchling') // => {id: 'enemies', item: 'geovishap-hatchling'}
data.find(el => el.item === 'geovishap-hatchling-3') // => undefineddata.findIndex(el => el.item === 'geovishap-hatchling') // => индекс элемента
data.find(el => el.item === 'geovishap-hatchling-3') // => -1 const isInitialMount = useRef(true);
useEffect(() => {
if (isInitialMount.current) {
isInitialMount.current = false;
} else {
// Your useEffect code here to be run on update
}
});
const weights = {
j: 11,
q: 12,
k: 13,
a: 14,
};
const isStraight = hand => hand
.map(n => weights[n] ?? +n)
.sort((a, b) => a - b)
.every((n, i, a) => !i || (n - a[i - 1] === 1));