Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
split_list solution in Clear category for Split List by Jon_Red
import assert from'assert';
function splitList(values:number[]):number[][]{
return[
values.slice(0,Number((values.length/2).toFixed(0))),
values.slice(Number((values.length/2).toFixed(0)))
];
}
// self-checks
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([]),[[],[]]);
July 25, 2020
Comments: