function sumOfArray(arr) {
return arr.reduce((a, b) => a + b, 0);
}
var sub_array = [];
for (var i = 0; i < a.length; i++) {
for (var j = i + 1; j < a.length; j++) {
if (j - i > sub_array.length && sumOfArray(a.slice(i, j)) <= k) {
sub_array = a.slice(i, j);
}
}
}
return sub_array.length;
}
s/var/let/g
Not es6 but try to use map filter and reduce over for loops
What is this even supposed to do
Обсуждают сегодня