Skip to content

Instantly share code, notes, and snippets.

@soyuka
Created March 26, 2017 15:24
Show Gist options
  • Save soyuka/61402fb9b20368a9a5ea138f8e01ee1d to your computer and use it in GitHub Desktop.
Save soyuka/61402fb9b20368a9a5ea138f8e01ee1d to your computer and use it in GitHub Desktop.
bimbamboum
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