i’m looking for a one-liner to convert x or x into x

The concat solution doesn’t typecheck because of the empty array literal. You’d need to write

const arr = ([] as number[]).concat(input);

Alternatively, you can use flat:

const arr = [input].flat();

This would not only be shorter but also preferable because it doesn’t rely on the concat-spreadable property of the input but actually checks for arrays.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top