Async Parse JSON Number
JavaScript
Easy
4 views
Problem Description
Input is a JSON value. If it is a number, print it. Otherwise print INVALID. Do parsing inside async/await.
Input Format
One line JSON value.
Output Format
Number or INVALID.
Constraints
Input length up to 1e5.
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s)process.exit(0);const parse=async t=>{await Promise.resolve();return JSON.parse(t);};(async()=>{try{const v=await parse(s);process.stdout.write(typeof v==='number'&&Number.isFinite(v)?String(v):'INVALID');}catch(e){process.stdout.write('INVALID');}})();
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!