const propsCount = 3;
.const newObj = Object.fromEntries(Object
.entries(obj)
.sort((a, b) => a[1] - b[1])
.slice(-propsCount)
);
Object
.entries(obj)
.sort((a, b) => b[1] - a[1])
.slice(propsCount)
.forEach(n => delete obj[n[0]]);
''.concat(...Array.from(str, n => n.repeat(2)))
// или
str.replace(/./g, '$&$&')
// или
str.replace(/./g, m => Array(3).join(m))
// или
str.replace(/(?=.)/g, (m, i) => str[i])
// или
[...str].flatMap(n => Array(2).fill(n)).join('')
// или
[].map.call(str, n => `${n}${n}`).join``
// или
str.split('').reduce((acc, n) => acc + n + n, '')
Number.isNaN(a)
arr.reduce((acc, n, i) => (
(!i || n === 1) && acc.push([]),
acc[acc.length - 1].push(n),
acc
), [])
найти объект
найти самое большое значение
const obj = arr.flat().reduce((max, n) => max?.age > n.age ? max : n, null);
const val = Math.max(...arr.flat().map(n => n.age));
const objs = arr.reduce((acc, n) => (
n.forEach(m => (
m.age > acc[0] && (acc = [ m.age, [] ]),
m.age === acc[0] && acc[1].push(m)
)),
acc
), [ -Infinity, [] ])[1];
Math.max(0, ...arr.reduce((acc, n, i, a) => (
n !== a[i - 1] && acc.push(0),
acc[acc.length - 1]++,
acc
), []))
arr.reduce((acc, n, i, a) => (
n !== a[~-i] && (acc[1] = 0),
acc[0] = acc[+(++acc[1] > acc[0])],
acc
), [ 0, 0 ])[0]