Count Data Fields in Object
JavaScript
Easy
4 views
Problem Description
Given a JSON object, count how many own properties have a value that is NOT a function. Print the count.
Input Format
One line JSON object.
Output Format
One integer count.
Sample Test Case
Input:
{"a":1,"b":"x","c":true}
Constraints
Input is valid JSON and contains only JSON-safe values (no functions inside).
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s)process.exit(0);const obj=JSON.parse(s);let c=0;for(const k of Object.keys(obj)){if(typeof obj[k]!=='function')c++;}process.stdout.write(String(c));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!