<\/span><\/h2>\n\n\n\nComplete the function in the editor. It has one parameter: an array, a<\/em><\/strong>, of objects. Each object in the array has two integer properties denoted by x<\/em><\/strong> and y<\/strong><\/em>. The function must return a count of all such objects o<\/em><\/strong> in array a<\/em><\/strong> that satisfy o<\/em>.x<\/em> == o<\/em>.y<\/em><\/strong>.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nThe first line contains an integer denoting n<\/em><\/strong>.
Each of the n<\/em><\/strong> subsequent lines contains two space-separated integers describing the values of x<\/em><\/strong> and y<\/em><\/strong>.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 5 <= n<\/em> <= 10<\/strong><\/li>
- 1 <= x<\/em>, y<\/em> <= 100<\/strong><\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nReturn a count of the total number of objects o<\/strong><\/em> such that o<\/em>.x<\/em> == o<\/em>.y<\/em><\/strong>. Locked stub code in the editor prints the returned value to STDOUT.<\/p>\n\n\n\nSample Input 0<\/strong><\/p>\n\n\n\n5\n1 1\n2 3\n3 3\n3 4\n4 5<\/code><\/pre>\n\n\n\nSample Output 0<\/strong><\/p>\n\n\n\n2<\/code><\/pre>\n\n\n\nExplanation 0<\/strong><\/p>\n\n\n\nThere are n<\/em> = 5<\/strong> objects in the objects<\/em><\/strong> array:<\/p>\n\n\n\n- objects0<\/em><\/strong> = {x: 1, y: 1}<\/strong><\/li>
- objects1<\/em><\/strong> = {x: 2, y: 3}<\/strong><\/li>
- objects2<\/em><\/strong> = {x: 3, y: 3}<\/strong><\/li>
- objects3<\/em><\/strong> = {x: 3, y: 4}<\/strong><\/li>
- objects4<\/em><\/strong> = {x: 4, y: 5}<\/strong><\/li><\/ul>\n\n\n\n
Because we have two objects o<\/em><\/strong> that satisfy o<\/em>.x<\/em> == o<\/em>.y<\/em><\/strong>(i.e., objects0<\/em><\/strong> and objects<\/em><\/strong>2<\/strong><\/em>), we return 2<\/strong> as our answer.<\/p>\n\n\n\n<\/span>Solution – Day 4: Count Objects <\/strong><\/span><\/h2>\n\n\n\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\/*\n * Return a count of the total number of objects 'o' satisfying o.x == o.y.\n * \n * Parameter(s):\n * objects: an array of objects with integer properties 'x' and 'y'\n *\/\nfunction getCount(objects) {\n var count = 0;\n for (var index in objects){\n if (objects[index].x == objects[index].y){\n count++;\n }\n }\n return count;\n}\n\n\n\nfunction main() {\n const n = +(readLine());\n let objects = [];\n \n for (let i = 0; i < n; i++) {\n const [a, b] = readLine().split(' ');\n \n objects.push({x: +(a), y: +(b)});\n }\n \n console.log(getCount(objects));\n}<\/pre>\n\n\n\n