Skip to content

Conversation

@Ada-11
Copy link

@Ada-11 Ada-11 commented Oct 30, 2020

No description provided.

Comment on lines +17 to +28

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

return Object.keys(obj)
}
//isUnique2([1,1,1,2,2,2,2,3,3,3,3]) //returns[1,2,3]
Copy link
Contributor

Choose a reason for hiding this comment

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

can you create a new file (called Ada-11.js)? that way there's no way that multiple solutions conflict with each other.

also, it is considered a best practice (and thus strongly encouraged) to use unit tests to validate solutions: that way you can clearly see that a particular solution is passing (or failing) the tests quickly by executing it. We also have set up CI to automatically run that every time!

you can see how to do that in L10-16 in this file or

describe(module.filename, () => {
it("should return true on an input string with unique characters", () => {
assert.equal(isUnique1("tech"), true);
assert.equal(isUnique2("tech"), true);
});
it("should return false on an input string with non-unique characters", () => {
assert.equal(isUnique1("techqueria"), false);
assert.equal(isUnique2("techqueria"), false);
});
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants