Skip to content

Instantly share code, notes, and snippets.

@marr
Last active March 9, 2016 20:49
Show Gist options
  • Save marr/8d2b0d86de532bda5c61 to your computer and use it in GitHub Desktop.
Save marr/8d2b0d86de532bda5c61 to your computer and use it in GitHub Desktop.
flatten a collection of objects
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