-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkUnique.js
41 lines (32 loc) · 885 Bytes
/
checkUnique.js
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
31
32
33
34
35
36
37
38
39
40
41
// Given a string, check to see if all characters are unique
// store => true
// sass => false
function checkUnique(string) {
var seen = {};
for(var i = 0; i < string.length; i++) {
if(seen[string[i]]) {
console.log("Not Unique");
return false;
}
else {
seen[string[i]] = true;
}
}
console.log("Unique");
return true;
}
// function checkUnique(string) {
// var seen = Array.apply(null, Array(256)).map(Boolean.prototype.valueOf, false);
// for(var i = 0; i < string.length; i++) {
// if(seen[string[i].charCodeAt(0)]) {
// console.log("Not Unique");
// return false;
// }
// else {
// seen[string[i].charCodeAt(0)] = true;
// }
// }
// console.log("Unique");
// return true;
// }
checkUnique("sass");