Created
June 18, 2019 13:48
-
-
Save abbathaw/c5c0774b28ec3e2215d3a98a46f9d1cd to your computer and use it in GitHub Desktop.
separating duplicates in array
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
// D, C, S, H | |
const deck = [{number: 1, pattern: "D"}, {number: 1, pattern: "H"}, {number: 2, pattern: "A"}, | |
{number: 1, pattern: "C"}, {number: 4, pattern: "C"}, {number: 4, pattern: "S"}] | |
const results = deck.reduce((acc, item) => { | |
if (!acc[item.number]) { | |
acc[item.number] = []; | |
} | |
acc[item.number].push(item); | |
return acc; | |
}, {}) | |
console.log(results) | |
console.log(Object.keys(results).length) | |
for (let [card, pattern] of Object.entries(results)) { | |
console.log(`Card is ${card}`, pattern) | |
// DO STUFF HERE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment