Created
August 18, 2022 12:14
-
-
Save mh-mobile/fd28d6ba02e606256610211a06ed0eb0 to your computer and use it in GitHub Desktop.
js_problem
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 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) |
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 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