Skip to content

Instantly share code, notes, and snippets.

@mh-mobile
Created August 18, 2022 12:14
Show Gist options
  • Save mh-mobile/fd28d6ba02e606256610211a06ed0eb0 to your computer and use it in GitHub Desktop.
Save mh-mobile/fd28d6ba02e606256610211a06ed0eb0 to your computer and use it in GitHub Desktop.
js_problem
const array1 = [1, 2, 3, 4, 5, 6]
const array2 = array1.flatMap((x) => new Array(x % 2 == 0 ? 2 : 3).fill(null).map(() => x))
console.log(array2)
const array1 = [1, 2, 3, 4, 5, 6]
const array2 = array1.map((x) => x % 2 == 0 ? [x, x] : [x, x, x])
console.log(array2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment