For some reason i end up getting \r
appended to the end of my array elements. This happens after reading data from a file and been splitted with with \r
.The file reading is been achieved with node's file system (fs) module.
data.txt
Samuel 20 male
Benjamin 10 male
Fortune 20 female
The code is shown below :
const fs = require('fs');
let data = fs.readFileSync('data.txt', 'utf8' );
let rawData = data => { return data.split( '\n' ) };
let objData = data => { return data.map( data => { return data.split( '\t' ) } ) }
console.log( objData( rawData( data ) ) );
Code output :
$ node reduce_example.js
[ [ 'Samuel', '20', 'male\r' ],
[ 'Benjamin', '10', 'male\r' ],
[ 'Fortune', '20', 'female' ] ]
I ran the code on node v9.5.0, v9.0.0 and v8.0.0