-
Notifications
You must be signed in to change notification settings - Fork 0
/
016-gem-stones.js
executable file
·40 lines (36 loc) · 1005 Bytes
/
016-gem-stones.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
// https://www.hackerrank.com/challenges/gem-stones/problem
let arr = ["abcdde", "baccd", "eeabg"];
function gemstones(arr) {
let counter = null;
//acii a = 97; z = 122;
for (let i = 97; i <= 122; i++) {
if (arr.every(element => element.includes(String.fromCharCode(i)))) {
//fromCharCode method returns a string created from the specified sequence of UTF-16 code units.
counter++;
}
}
return counter;
}
let z = gemstones(arr);
console.log(z);
// let arr = ["abcdde", "baccd", "eeabg"];
// function gemstones(arr) {
// let count = 0;
// let hasGem = true;
// for (let i = 0; i < arr[0].length; i++) {
// let char = arr[0].charAt(i);
// if (arr[0].indexOf(char) === i) {
// for (let j = 1; j < arr.length; j++) {
// if (arr[j].indexOf(char) === -1) {
// hasGem = false;
// }
// }
// if (hasGem) {
// count++;
// }
// }
// }
// return count;
// }
// let z = gemstones(arr);
// console.log(z);