-
-
Save soyuka/61402fb9b20368a9a5ea138f8e01ee1d to your computer and use it in GitHub Desktop.
bimbamboum
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
| const assert = require('assert') | |
| var e = { | |
| itag: ['a', 'b'], | |
| s: ['a', 'b'], | |
| url: ['a', 'b'] | |
| } | |
| var f = { | |
| itag: ['c', 'd'], | |
| s: 's', | |
| url: ['c', 'd'] | |
| } | |
| var g = [ | |
| { | |
| itag: 'a', | |
| s: 'a', | |
| url: 'a' | |
| }, | |
| { | |
| itag: 'b', | |
| s: 'b', | |
| url: 'b' | |
| }, | |
| { | |
| itag: 'c', | |
| s: 's', | |
| url: 'c' | |
| }, | |
| { | |
| itag: 'd', | |
| s: 's', | |
| url: 'd' | |
| } | |
| ] | |
| function parseItem(x) { | |
| let l = x.itag.length | |
| const foo = [] | |
| for (let i = 0; i < l; i++) { | |
| const o = {} | |
| for (let key in x) { | |
| o[key] = Array.isArray(x[key]) ? x[key][i] : x[key] | |
| } | |
| foo.push(o) | |
| } | |
| return foo | |
| } | |
| const foobar = [...parseItem(e), ...parseItem(f)] | |
| assert.deepEqual(foobar, g, 'Whooops not equal') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment