Created
January 15, 2019 17:18
-
-
Save jasonseminara/fc37556e09ca502477512656a17b88c1 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* one-line solution with sets! | |
*/ | |
const oneliner = [...new Set(colors.split(' '))].join(' '); | |
console.log(oneliner); | |
/** | |
* WHOAH! let's break that down! | |
*/ | |
// break up the string on spaces | |
const colorArray = colors.split(' '); | |
// use the Set constructor to convert the array into a non-repeating set | |
// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#Description | |
const colorSet = new Set(colorArray); | |
// we want to destructure the set into an array then join into a string | |
const solution3 = [...colorSet].join(' '); | |
console.log(solution3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment