Skip to content

Instantly share code, notes, and snippets.

@SamSamskies
Created March 27, 2016 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSamskies/ba384b11692b4e2b528f to your computer and use it in GitHub Desktop.
Save SamSamskies/ba384b11692b4e2b528f to your computer and use it in GitHub Desktop.
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