Last active
February 26, 2020 20:47
-
-
Save munkacsitomi/50472801c1209de0504131df81cd0f93 to your computer and use it in GitHub Desktop.
Set example in JS
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 ninjas = new Set(['Kuma', 'Hattori', 'Yagyu']); | |
const samurai = new Set(['Hattori', 'Oda', 'Tomoe']); | |
const pureNinjas = new Set([...ninjas].filter(ninja => !samurai.has(ninja))); | |
const everyone = new Set([...ninjas, ...samurai]); | |
console.log(pureNinjas.size === 2, 'There’s only one ninja samurai'); | |
console.log(pureNinjas.has('Kuma'), 'Kuma is a true ninja'); | |
console.log(pureNinjas.has('Yagyu'), 'Yagyu is a true ninja'); | |
console.log(everyone.size === 5, 'Do not count twice Hattori, the ninja samurai'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment