Skip to content

Commit b5984d0

Browse files
committed
97차 2번 문제풀이
1 parent 186a9b3 commit b5984d0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

live9/test97/문제2/조진우.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function solution(name) {
2+
let nameArr = name.split("");
3+
let currentValue = "A";
4+
let totalCount = 0;
5+
6+
for (let i = 0; i < nameArr.length; i++) {
7+
let upDownCount = 0;
8+
let leftRightCount = 0;
9+
10+
upDownCount = Number(
11+
Math.min(
12+
Math.abs(nameArr[i].charCodeAt(0) - currentValue.charCodeAt(0)),
13+
26 - Math.abs(nameArr[i].charCodeAt(0) - currentValue.charCodeAt(0))
14+
)
15+
);
16+
17+
leftRightCount = i;
18+
19+
totalCount += Math.max(upDownCount, leftRightCount);
20+
currentValue = nameArr[i];
21+
}
22+
23+
return totalCount;
24+
}
25+
26+
console.log(solution("JEROEN"));

0 commit comments

Comments
 (0)