Normalize to Number or NaN

JavaScript Medium 4 views
Back to Questions

Problem Description

Input is a JSON array with mixed values. Convert each item to a number using Number(). Print a JSON array where invalid conversions become null.

Input Format

One line JSON array.

Output Format

One line JSON array output.

Sample Test Case

Input:
["10"," 5 ",true,"abc",null]
Output:
[10,5,1,null,0]

Constraints

Array length up to 1e5.

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next