Skip to content

Instantly share code, notes, and snippets.

@zlargon
Created October 30, 2015 10:20
Show Gist options
  • Save zlargon/a469532965874e11a66c to your computer and use it in GitHub Desktop.
Save zlargon/a469532965874e11a66c to your computer and use it in GitHub Desktop.
import fs from 'fs'
var output = fs.readFileSync('input.txt', 'utf8')
.trim() // remove end of line
.split('\n')
.map(line => line.split('\t'))
.reduce((customers, [ user, name, price, quality ]) => {
customers[user] = customers[user] || [];
customers[user].push({ name, price, quality });
return customers;
}, {});
console.log(JSON.stringify(output, null, 2));
mark johansson waffle iron 80 2
mark johansson blender 200 1
mark johansson knife 10 4
Nikita Smith waffle iron 80 1
Nikita Smith knife 10 2
Nikita Smith pot 20 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment