Skip to content
This repository was archived by the owner on Nov 7, 2020. It is now read-only.
This repository was archived by the owner on Nov 7, 2020. It is now read-only.

Answer for Array duplicates doesn't pass test #41

@ryanhamley

Description

@ryanhamley

The current answer for the duplicates question is this:

var seen = {};
var dupes = [];

for (var i = 0, len = arr.length; i < len; i++) {
  seen[arr[i]] = seen[arr[i]] ? seen[arr[i]] + 1 : 1;
}

for (var item in seen) {
  if (seen.hasOwnProperty(item) && seen[item] > 1) {
    dupes.push(item);
  }
}

return dupes;

The test rejects it saying:

AssertionError: expected [ '1', '3', '4' ] to deeply equal [ 1, 3, 4 ]
    at Context.<anonymous> (tests/app/arrays.js:96:30)

I changed the following line in my code to make it pass:

dupes.push(item)

//changes to

dupes.push(parseInt(item, 10));

It seems like either the test should expect strings or the answer should be updated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions