Skip to content

Commit

Permalink
Another solution for this exercise using Object
Browse files Browse the repository at this point in the history
  • Loading branch information
Ada-11 authored Oct 30, 2020
1 parent bbc47c3 commit 599ee5d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions JavaScript/chapter01/p01_is_unique/fvntr.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ describe(module.filename, () => {
assert.deepEqual(isUnique([1,1,1,2,2,2,2,3,3,3,3]), [1,2,3]);
});
});

//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]

0 comments on commit 599ee5d

Please sign in to comment.