K🦋
Size: a a a
K🦋
K🦋
Вキ
K🦋
K🦋
K🦋
VI
K🦋
VI
m
IB
const sum = (arr) => arr.reduce((acc, i) => acc + i, 0);
const sortFn = (a, b) => b - a;
const removeAt = (arr, index) => arr.slice(0,index).concat(arr.slice(index+1))
function kek(arr) {
const sorted = arr.sort(sortFn);
const diff = sum(sorted) % 3;
if (diff === 0) {
return +sorted.join('');
}
const index = sorted.findIndex((item) => item % 3 === diff);
if (index !== -1) {
return +removeAt(sorted, index).join('');
}
if (sorted.length <= 1) {
return 0;
}
const recurr = sorted
.map((i, index) => kek(removeAt(sorted, index)))
.sort(sortFn);
return recurr[0] || 0;
}
IB
Вキ
const sum = (arr) => arr.reduce((acc, i) => acc + i, 0);
const sortFn = (a, b) => b - a;
const removeAt = (arr, index) => arr.slice(0,index).concat(arr.slice(index+1))
function kek(arr) {
const sorted = arr.sort(sortFn);
const diff = sum(sorted) % 3;
if (diff === 0) {
return +sorted.join('');
}
const index = sorted.findIndex((item) => item % 3 === diff);
if (index !== -1) {
return +removeAt(sorted, index).join('');
}
if (sorted.length <= 1) {
return 0;
}
const recurr = sorted
.map((i, index) => kek(removeAt(sorted, index)))
.sort(sortFn);
return recurr[0] || 0;
}
IB
Вキ
IB
console.log(kek([5, 8, 3]));
console.log(kek([3, 1, 4, 1, 5, 9]));
console.log(kek([3, 1, 4, 1]));
console.log(kek([4]));
IB
3
94311
4311
0
IB