Last active
August 14, 2019 21:09
-
-
Save djD-REK/fc2066eaff6c446a510d0120469f1348 to your computer and use it in GitHub Desktop.
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 suits = ["♠️", "♣️", "♥️", "♦️", "🃏"]; | |
const ranks = ["A", "K", "Q", "J", "🃏"]; | |
console.log(suits.map((suit, index) => [ranks[index], suit])); | |
// result: [["A", "♠️"], ["K", "♣️"], ["Q", "♥️"], ["J", "♦️"], ["🃏", "🃏"]] | |
console.log(suits.flatMap((suit, index) => [ranks[index], suit])); | |
// result: ["A", "♠️", "K", "♣️", "Q", "♥️", "J", "♦️", "🃏", "🃏"] | |
// If for some reason you needed to use a depth > 1 for flat, you can't use flatMap | |
console.log(suits.map((suit, index) => [ranks[index], suit]).flat(Infinity)); | |
// result: ["A", "♠️", "K", "♣️", "Q", "♥️", "J", "♦️", "🃏", "🃏"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment