diff --git a/challenge-1.js b/challenge-1.js new file mode 100644 index 0000000..023c451 --- /dev/null +++ b/challenge-1.js @@ -0,0 +1,14 @@ + +let exampleArray = ['not','funny','but','not','correct','but','correct'] + +let uniqueArray = [...new Set(exampleArray)] + +module.exports = uniqueArray + + + + +/* + Explanation: + I chose this method ("Set" + Spread Operator) as it's the simplest and cleanest I've found: using the "Set" object appears to be the most concise way to return unique values in the new array "uniqueArray". In this situation using "Set" + "Array.from" would be my next choice, which yields similar performace to using "Set" + Spread Operator. +*/ \ No newline at end of file diff --git a/challenge-1.test.js b/challenge-1.test.js new file mode 100644 index 0000000..b24f27e --- /dev/null +++ b/challenge-1.test.js @@ -0,0 +1,5 @@ +const uniqueArray = require('./challenge1') + +test('remove all duplicates from array', () => { + expect(uniqueArray).toStrictEqual(['not','funny','but','correct']) +}) \ No newline at end of file