Skip to main content

Coderbyte Node JS Age Counting Challenge

 

 

Node JS Age Counting Challenge:

As per response of get call count the total number of ages who has age value above or equal to 50.

Solution:

const https = require('https');
https.get('https://coderbyte.com/api/challenges/json/age-counting', (resp) => {
let data = ''
resp.on('data', (chunk) => {
data+=chunk;
});
resp.on('end', () => {
let jsonData = JSON.parse(data.toString());
let actualData = jsonData.data;
let arr1 = actualData.split(", ");
let totalCount = 0;
for(let i = 0; i < arr1.length; i++){
let item = arr1[i];
if(item.indexOf('age=') !== -1){
let age = item.split('=');
if(parseInt(age[1]) >= 50) {
totalCount++;
}
}
}
console.log(totalCount);
})
});

//OUTPUT: 128







Add your comments if you any better solution!!

Comments

Popular posts from this blog

eLitmus Placement Papers

This is all about placements.....  eLitmus is a first-of-its-kind service in the world. Since it was launched in 2005, eLitmus has been redefining how fresher and entry-level recruitment is done in  India . pH Test evaluates job seekers based on a variety of parameters, and grades them nationwide using an advanced  statistical model , resulting in a pH Score for each candidate. eLitmus has been one of the toughest test which requires  CAT  level preparation. And as there are no previous paper available anywhere it gets more tougher to even predict its pattern. As I was preparing for this particular exam I came across some papers which were tagged as eLitmus papers. I am sharing them here in links below. It is in  PDF format  so you can right click and select save as option to download the papers. Download Sample Papers for Practice(click on Elitmus.zip) Elitmus.zip P.S: A word of advice : the elitmus study material giv...
6 Questions to Ask Yourself About Your Resume You’ve found an online job posting that’s gotten you really excited. You’ve filled out the online form. Now it’s time to upload your resume, hit  submit , then sit back and wait for your phone to ring. But wait: Before you do that, why not take an extra five minutes to double and triple check your resume? You’ve probably looked it over a hundred times before, but it never hurts to verify that your resume is spotless, professional, and appealing. Read through your resume just one more time before you send it off, and as you read it ask yourself these quick questions: Is your contact information accurate, complete, and up to date?  Yes, this seems like a no-brainer—but you would be  amazed  at how many resumes we see where digits in the phone number are transposed, or there is a typo in the e-mail address, or there is no physical mailing address listed at all. Read through your contact information  c...