Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second. Array.splice() solution in Uncategorized category for Split List by vvm70
import assert from "assert";
function splitList(items: number[]):number[][] {
return [items.splice(Math.round(items.length / 2)), items].reverse();
}
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!");
July 27, 2020