-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjewelCounter.js
26 lines (24 loc) · 934 Bytes
/
jewelCounter.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
/*
You're given strings J repesenting the types of stones that are jewels, and S representing the stones
you have. Each character in S is a type of stone that you have . You want to know many stones that
you have that are also stones.
The letters in J are guaranteed distinct, and all characters in J and S are letters. The letters are
case-sensitive , so 'a' is not the same as 'A'
*/
const jewelCounter = ( J, S) => {
if (J.length < 1 || S.length < 1) return null;
let jewelArray = J.split('');
let stoneArray = S.split('');
let counter = 0;
for(let i = 0; i < J.length-1; i++){
for(let j = 0; j < S.length-1; j++){
if(jewelArray[i] === stoneArray[j]){
// console.log(stoneArray[i], stoneArray[j])
counter +=1;
}
}
}
console.log(counter)
return counter;
}
jewelCounter('aAch', 'aaAAcccchfh')