Last active
March 12, 2019 02:10
-
-
Save omginbd/04207eef6c30dbd8a9fa20afd53f72ea to your computer and use it in GitHub Desktop.
This file contains 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
const assert = require('assert') | |
const test = [ | |
{ | |
title: 'hi', | |
values: [ | |
{ | |
count: '1', | |
value: 'fun' | |
}, | |
{ | |
count: '0', | |
value: 'no fun' | |
} | |
] | |
}, | |
{ | |
title: 'hey', | |
values: [] | |
} | |
] | |
const final = [ | |
{ | |
title: 'hi', | |
values: [ | |
{ | |
count: '1', | |
value: 'fun' | |
} | |
] | |
} | |
] | |
const transform = categories => { | |
return categories.reduce((memo, category) => { | |
category.values = category.values.filter(value => +value.count) | |
return category.values.length ? memo.concat([category]) : memo | |
}, []) | |
} | |
const main = () => { | |
const transformed = transform(test) | |
assert(transformed[0].values.length === 1) | |
assert(transformed.length === 1) | |
console.log('it worked') | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment