Deep Freeze One Level
JavaScript
Medium
2 views
Problem Description
Given a JSON object, freeze it and also freeze all direct child objects/arrays (one level deep). Print DONE.
Input Format
One line JSON object.
Sample Test Case
Input:
{"a":{"x":1},"b":[1,2],"c":3}
Constraints
Input JSON contains only objects/arrays/numbers/strings/booleans/null.
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s)process.exit(0);const obj=JSON.parse(s);Object.freeze(obj);for(const k of Object.keys(obj)){const v=obj[k];if(v && typeof v==='object')Object.freeze(v);}process.stdout.write('DONE');
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!