Skip to content

Commit 2be8862

Browse files
committed
Alphabet symmetry
1 parent d5bcef2 commit 2be8862

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.js
22
index.html
3-
Solutions JS
3+
Solutions JS
4+
reverseNumberBase.md

7_kyu/alphabetSymmetry.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## [Alphabet symmetry](https://www.codewars.com/kata/59d9ff9f7905dfeed50000b0)
2+
3+
#### Task
4+
5+
- Consider the word "abode". We can see that the letter a is in position 1 and b is in position 2. In the alphabet, a and b are also in positions 1 and 2. Notice also that d and e in abode occupy the positions they would occupy in the alphabet, which are positions 4 and 5.
6+
7+
- Given an array of words, return an array of the number of letters that occupy their positions in the alphabet for each word. For example,
8+
9+
```js
10+
solve(["abode","ABc","xyzD"]) = [4, 3, 1]
11+
```
12+
13+
- See test cases for more examples.
14+
15+
- Input will consist of alphabet characters, both uppercase and lowercase. No spaces.
16+
17+
- Good luck!
18+
19+
#### Solution:
20+
21+
```js
22+
function solve(arr) {
23+
const refer = "abcdefghijklmnopqrstuvwxyz";
24+
const res = [];
25+
26+
for (const key in arr) {
27+
let counter = 0;
28+
for (let i = 0; i < arr[key].length; i++) {
29+
if (arr[key][i].toLowerCase() === refer[i]) counter++;
30+
}
31+
res.push(counter);
32+
}
33+
34+
return res;
35+
}
36+
37+
console.log(solve(["abode", "ABc", "xyzD"])); // [4,3,1]
38+
console.log(solve(["abide", "ABc", "xyz"])); // [4,3,0]
39+
console.log(solve(["encode", "abc", "xyzD", "ABmD"])); // [1, 3, 1, 3]
40+
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Solutions to CodeWars programming tasks. I try to update every day
408408
</tr>
409409
<tr>
410410
<td><a href=" " > </a></td>
411-
<td><a href="7 kyu" > </a></td>
411+
<td><a href="https://github.com/esadakman/javaScript-coding-challenges/blob/master/7_kyu/alphabetSymmetry.md" >alphabetSymmetry</a></td>
412412
<td><a href="https://github.com/esadakman/javaScript-coding-challenges/blob/master/6_kyu/deepCount.md" >deepCount</a></td>
413413
<td><a href="5 kyu" > </a></td>
414414
<td><a href="others " ></a></td>

0 commit comments

Comments
 (0)