-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7kyu-isograms.js
More file actions
47 lines (36 loc) · 912 Bytes
/
7kyu-isograms.js
File metadata and controls
47 lines (36 loc) · 912 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//1 2022/04/24 2:25pm -
//2 using forEach
function isIsogram(str){
str = str.toUpperCase()
let obj = {}
let result = true;
[...str].forEach(each => {
obj[each] = obj[each]? obj[each] +1 : 1
})
Object.values(obj).forEach(each => {if(each > 1) return result = false
})
console.log(result)
return result
}
isIsogram("Dermatoglyphics")
// function isIsogram(str){
// str = str.toUpperCase()
// let obj = {}
// let result = true;
// for(let i=0; i< str.length; i++){
// //console.log(str[i])
// if(!obj.hasOwnProperty([str[i]])){
// obj[str[i]] = 1
// } else {
// obj[str[i]]++
// }
// }
// for(let keys in obj){
// if(obj[keys] > 1) {
// return result = false
// }
// }
// console.log(result)
// return result
// }
// isIsogram("Dermatoglyphics")