This is giving me any error when I click check solution. All checks in the console work fine. Any ideas?
function splitList(values: number[]): number[][] {
const arr = [
[ ...values].slice(0,Math.ceil(values.length / 2)),
[ ...values].slice(Math.ceil(values.length / 2))
];
return arr;
}
console.log("Example:");
console.log(JSON.stringify(splitList([1, 2, 3, 4, 5, 6])));
// These "asserts" are used for self-checking
assert.deepStrictEqual(splitList([1, 2, 3, 4, 5, 6]), [
[1, 2, 3],
[4, 5, 6],
]);
assert.deepStrictEqual(splitList([1, 2, 3]), [[1, 2], [3]]);
assert.deepStrictEqual(
splitList(["banana", "apple", "orange", "cherry", "watermelon"]),
[
["banana", "apple", "orange"],
["cherry", "watermelon"],
]
);
assert.deepStrictEqual(splitList([1]), [[1], []]);
assert.deepStrictEqual(splitList([]), [[], []]);
console.log("Coding complete? Click 'Check Solution' to earn rewards!");
FAILS:
21,16: Type 'string' is not assignable to type 'number'.
21,26: Type 'string' is not assignable to type 'number'.
21,35: Type 'string' is not assignable to type 'number'.
21,45: Type 'string' is not assignable to type 'number'.
21,55: Type 'string' is not assignable to type 'number'.
assert.deepStrictEqual(splitList([1,2,3,4,5,6]), [[1,2,3],[4,5,6]]); ...
Created at: 2023/06/17 22:15; Updated at: 2023/06/18 03:57
The question is resolved.