[go: nahoru, domu]

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

Is unique branch #79

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 30 additions & 0 deletions JavaScript/chapter01/p01_is_unique/ada11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


/* Write a function isUnique that:
Input: takes an array of integers
Output: returns a deduped array of integers
*/

// using an Object
const isUnique = (arr)=>{
let obj = {}
for (let elem of arr){
if(obj.hasOwnProperty(elem)) obj[elem]++
else obj[elem] = 1
}

return Object.keys(obj)
}

//test cases
const assert = require('assert');
describe(module.filename, () => {
it("should return true on an input string with unique characters", () => {
assert.equal(isUnique1("tech"), true);
assert.equal(isUnique2("tech"), true);
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.equal(isUnique1("tech"), true);
assert.equal(isUnique2("tech"), true);
assert.equal(isUnique("tech"), true);

there's only one implementation in this file. same below.

});
it("should return false on an input string with non-unique characters", () => {
assert.equal(isUnique1("techqueria"), false);
assert.equal(isUnique2("techqueria"), false);
});
});
1 change: 1 addition & 0 deletions JavaScript/chapter01/p01_is_unique/avc278.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

this seems like an unintended change in another person's file:

Suggested change

// Is Unique: Implement an algorithm to determine if a string has all unique characters.
// What if you cannot used additional data structures?

Expand Down