-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathada11.js
More file actions
30 lines (25 loc) · 765 Bytes
/
ada11.js
File metadata and controls
30 lines (25 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
});
it("should return false on an input string with non-unique characters", () => {
assert.equal(isUnique1("techqueria"), false);
assert.equal(isUnique2("techqueria"), false);
});
});