Skip to content

Instantly share code, notes, and snippets.

@return-none
Created June 7, 2019 08:43
Show Gist options
  • Save return-none/b631aa5c70b737012967fb60c1591b34 to your computer and use it in GitHub Desktop.
Save return-none/b631aa5c70b737012967fb60c1591b34 to your computer and use it in GitHub Desktop.
// simple assert
function assertEqual(a, b) {
return a === b;
}
// input data
var spend = [
{
id: 1,
price: -120,
category: 'leisure',
name: 'food'
},
{
id: 2,
price: -45.1,
category: 'leisure',
name: 'bevarage'
},
{
id: 3,
price: '250',
category: 'income',
name: 'return'
},
{
id: 4,
category: 'income',
name: 'placeholder'
}
];
// pick returns new list of values in field
function pick(list, field) {
}
// sum returns sum of all values by field
function sum(list) {
}
// find filters the input list of objects, based on key and value
function find(list, field, value) {
}
console.log(assertEqual(sum(pick(spend, 'price')), 84.9));
console.log(assertEqual(sum(pick(find(spend, 'category', 'leisure'), 'price')), -165.1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment