Yesterday I got my extraction from a csv working but now ran into another wall. Basically I now have an array of objects with the properties Name, Score and Kills.
I now want to take out 5 objects that have the highest amount of points and sort them from the highest to the lowest of these 5. For now I only have 4 entries as only 4 individuals connected to the server but I want to already get it to work for the future.
heres my current code :
const csv = require('csv-parser');
const fs = require('fs');
fs.createReadStream('./FFA/csv/rankme.csv')
.pipe(csv({ delimiter: ',', from_line: 2 }))
.on('data', (row) =>
{
const keyLookup = ['name', 'score', 'kills'];
const newData = Object.keys(row)
.filter(key => keyLookup.includes(key))
.reduce((obj, key) => {
obj[key] = row[key];
return obj;
}, {});
console.log(newData);
});
and this is the output on the console :
{ name: 'liHi-', score: '998', kills: '1' }
{ name: 'xyCe', score: '1004', kills: '3' }
{ name: 'Лови Аптечка Брат', score: '1000', kills: '0' }
{ name: 'buronhajredini108', score: '1000', kills: '0' }