Created
March 27, 2016 18:12
-
-
Save SamSamskies/ba384b11692b4e2b528f 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
function remDups(arr) { | |
return arr.reduce((memo, num) => { | |
if (memo.numMap[num]) return memo; | |
memo.numMap[num] = true; | |
memo.noDupArr.push(num); | |
return memo; | |
}, { noDupArr: [], numMap: {} }).noDupArr; | |
} | |
/****************************************/ | |
import { expect } from 'chai'; | |
const testCases = [ | |
{ | |
given: [1, 5, 1, 1, 2, 3], | |
expected: [1, 5, 2, 3] | |
} | |
]; | |
describe('remDups', () => { | |
it('should remove duplicates from an array', () => { | |
testCases.forEach(test => { | |
expect(test.expected).to.deep.equal(remDups(test.given)); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment