I'm trying to get the data that's coming this way:
[
{
"name":"JONAS",
"languages":["php","javascript","java"],
"age":37,
"graduate_date":1044064800000,
"phone":"32-987-543"
},
{
"name":"FLAVIO",
"languages":["java","javascript"],
"age":26,
"graduate_date":1391220000000,
"phone":"32-988-998"
},
{
"name":"HENRIQUE",
"languages":["regex","javascript","perl","go","java"],
"age":21,
"graduate_date":1296525600000,
"phone":"32-888-777"
}
]
And turn this into:
Jonas - 26 years - 32-988-998
Flavio - 21 years - 32-888-777
Henrique - 37 years - 32-987-543
go (1)
java (3)
javascript (3)
perl (1)
php (1)
regex (1)
I'm using this code:
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
const todaydate = 1517577684000;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', => {
inputString = inputString
.replace(/\s$/, '')
.split('\n')
.map(str => str.replace(/\s$/, '')),
main();
});
function readLine() {
return inputString[currentLine++];
}
// Complete the selectCandidates function below.
const reportCandidates = (candidatesArray) => {
//aqui ta o problema
return reportObject;
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const candidates = JSON.parse(readLine());
let result = reportCandidates(candidates);
// Don't touch this code or you will die
for (let i=0; i<result.candidates.length; i++){
ws.write(result.candidates[i].name + " - " + result.candidates[i].age +" years - " + result.candidates[i].phone +"\n");
}
for (let i=0; i<result.languages.length; i++){
ws.write(result.languages[i].lang + " - " + result.languages[i].count +"\n");
}
ws.end();
}
But I can not solve it or pray, can anyone give a light?