Last active
March 9, 2016 20:49
-
-
Save marr/8d2b0d86de532bda5c61 to your computer and use it in GitHub Desktop.
flatten a collection of objects
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
test('map a collection into a new array', assert => { | |
const expected = [ { a:1 }, { a: 1 } ] | |
const input = [ [ { a: 1 }, { b: 1 } ], [ { a: 1, c: 1 } ] ] | |
const actual = [].concat.apply([], input) | |
.filter(e => e.hasOwnProperty('a')) | |
.map(e => { | |
return { a: e.a } | |
}) | |
assert.deepEqual(actual, expected) | |
assert.end() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment