Real Type Finder
JavaScript
Easy
4 views
Problem Description
Given one value as a string input, print its real JavaScript type in a friendly way: null, array, object, number, string, boolean, undefined, function.
Input Format
One line containing a JSON-like value. Examples: null, [1,2], {"a":1}, "hi", true, 10.
Output Format
One word type name.
Constraints
Input is valid JSON for primitives/arrays/objects.
Official Solution
const fs=require('fs');const t=fs.readFileSync(0,'utf8').trim();if(!t){process.exit(0);}let v=JSON.parse(t);let out='object';if(v===null)out='null';else if(Array.isArray(v))out='array';else out=typeof v;process.stdout.write(out);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!