Same Type or Not
JavaScript
Easy
8 views
Problem Description
Two JSON values are given on two lines. Print YES if both values have the same JavaScript type (treat null as its own type and array as its own type). Else print NO.
Input Format
Line1: JSON A. Line2: JSON B.
Constraints
Inputs are valid JSON.
Official Solution
const fs=require('fs');const txt=fs.readFileSync(0,'utf8');const lines=txt.split(/\
?\
/);const aLine=(lines[0]||'').trim();const bLine=lines.slice(1).join('\
').trim();if(!aLine||!bLine)process.exit(0);const A=JSON.parse(aLine);const B=JSON.parse(bLine);const type=v=>{if(v===null)return 'null';if(Array.isArray(v))return 'array';return typeof v;};process.stdout.write(type(A)===type(B)?'YES':'NO');
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!