Equilibrium index: Difference between revisions

Content added Content deleted
(→‎JS ES6 Functional: Restored and updated a functional version which returns all equilibrium indices)
Line 1,309: Line 1,309:
// ------------------------TEST------------------------
// ------------------------TEST------------------------
const main = () => {
const main = () => {
console.log(JSON.stringify(
console.log(JSON.stringify([
[
[-7, 1, 5, 2, -4, 3, 0],
[-7, 1, 5, 2, -4, 3, 0],
[2, 4, 6],
[2, 4, 6],
[2, 9, 2],
[2, 9, 2],
[1, -1, 1, -1, 1, -1, 1],
[1, -1, 1, -1, 1, -1, 1],
[1],
[1],
[]
].map(equilibriumIndices)));
[]
].map(equilibriumIndices)
));
// -> [[3, 6], [], [1], [0, 1, 2, 3, 4, 5, 6], [0], []]
// -> [[3, 6], [], [1], [0, 1, 2, 3, 4, 5, 6], [0], []]
};
};
Line 1,385: Line 1,383:
ys => Array.from({
ys => Array.from({
length: Math.min(xs.length, ys.length)
length: Math.min(xs.length, ys.length)
}, (_, i) => [xs[i], ys[i]]);
}, (_, i) => Tuple(xs[i])(ys[i]));


// MAIN ---
// MAIN ---