Skip to content

Instantly share code, notes, and snippets.

@atomize
Created September 17, 2018 06:28
Show Gist options
  • Save atomize/a756f096292ca9ab5f90e85c1f9b3ba0 to your computer and use it in GitHub Desktop.
Save atomize/a756f096292ca9ab5f90e85c1f9b3ba0 to your computer and use it in GitHub Desktop.
Dirty flattener.
async function dirtyFlatten(res) {
let vals = Object.values(res)
vals = vals.map((x) => {
return Object.values(x).reduce((a, c) => {
if (typeof c === 'object' || typeof c === 'array') {
c.map(entry => a.push(entry))
} else {
a.push(c)
}
return a;
}, [])
}, []).reduce((y, c) => {
c.map(entry => y.push(entry))
return y
}, [])
console.log("vals reduce: ", vals)
return vals
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment