Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

countSetBits implemented #204

Merged
merged 6 commits into from
Oct 21, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add new function
dna113p committed Oct 20, 2017
commit 58a82ede155a05aab1e5955b52d68e3a0ad3a86a
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ module.exports = {
sum: require("./sum"),
swapCase: require("./swapCase"),
take: require("./take"),
unique: require("./unique"),
uppercase: require("./uppercase"),
vowelCount: require("./vowelCount"),
without: require("./without"),
8 changes: 8 additions & 0 deletions lib/unique.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//Return the number of unique elements in the array
Copy link
Collaborator

@ktilcu ktilcu Oct 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should we do about complex items in arrays? like objects or other arrays? maybe just use strict equality checking (===)? A test for this situation would be very explanatory. Something like

const omg = {omg:1};
expect(unique([omg, {omg:1}, omg])).toBe(2); // or 1 if you have something else in mind.

would help whoever implements this in the future.


function unique(arr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it uniqueCount?

//your code here
return;
}

module.exports = unique;
17 changes: 17 additions & 0 deletions test/unique.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { unique } = require("../lib");

describe("unique", () => {
test("should find 1 unique number in [1]", () => {
expect(unique([1])).toEqual();
});

test("should find 1 unique number in [5,5,5]", () => {
expect(unique([5,5,5])).toEqual(1);
});

test("should find 3 unique numbers in [1,2,3]", () => {
expect(unique([1,2,3])).toEqual(3);
});
});