Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Split List by mortonfox
"use strict";
// jshint esversion: 6, node: true
function splitList(items) {
const mid = Math.floor((items.length + 1) / 2);
return [items.slice(0, mid), items.slice(mid)];
}
// var assert = require('assert');
// if (!global.is_checking) {
// 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!");
// }
April 23, 2020