Plain Object Flags
JavaScript
Medium
4 views
Problem Description
You get a JSON array. For each item print PLAIN if it is a plain object (typeof object, not null, not array). Else print NO. One output per line.
Input Format
One line JSON array.
Output Format
n lines outputs.
Sample Test Case
Input:
[{},[],null,{"a":1},1]
Output:
PLAIN
NO
NO
PLAIN
NO
Constraints
Array length up to 2e5.
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s)process.exit(0);const arr=JSON.parse(s);let out=[];for(const v of arr){const ok=v!==null && typeof v==='object' && !Array.isArray(v);out.push(ok?'PLAIN':'NO');}process.stdout.write(out.join('\
'));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!