Created
June 7, 2019 08:43
-
-
Save return-none/b631aa5c70b737012967fb60c1591b34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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