Write toArray(value): take one value or an array of values, and always return an array.
toArray("a") returns ["a"], typed string[], and toArray([1, 2]) returns [1, 2], typed number[]. It should accept readonly arrays too, and always return a new array the caller can change.
function toArray(value) { // Return a new array: value's elements if it's an array, or [value] if it isn't.} // toArray("a"); // ["a"], typed string[]// toArray([1, 2]); // [1, 2], typed number[]The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…