Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Split List solution in Uncategorized category for Split List by Elena_Korljukova
import assert from "assert";
function splitList(values: number[]):number[][] {
var n = values.length - Math.trunc(values.length/2);
return [values.slice(0,n), values.slice(n)];
}
console.log('Example:');
console.log(splitList([1, 2, 3, 4, 5, 6]));
// These "asserts" are used for self-checking
assert.deepEqual(splitList([1, 2, 3, 4, 5, 6]), [[1, 2, 3], [4, 5, 6]]);
assert.deepEqual(splitList([1, 2, 3]), [[1, 2], [3]]);
assert.deepEqual(splitList([1, 2, 3, 4, 5]), [[1, 2, 3], [4, 5]]);
assert.deepEqual(splitList([1]), [[1], []]);
assert.deepEqual(splitList([]), [[], []]);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
June 21, 2020