Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 936e273

Browse files
시저-암호 add solution 1
1 parent 221fb8c commit 936e273

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

‎level-1/시저-암호.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,26 @@ function solution(s, n) {
1313
}
1414
}).join('')
1515
return answer;
16-
}
16+
}
17+
18+
//정답 2 - jaewon1676
19+
function solution(s, n) {
20+
return s.split("").map((el) => {
21+
if (el == " ") return el;
22+
let tmp = el.charCodeAt()
23+
return el.toLowerCase().charCodeAt()+n > 122
24+
? String.fromCharCode(tmp+n-26)
25+
: String.fromCharCode(tmp+n)
26+
}).join('')
27+
}
28+
/* 문자열 -> 아스키코드 : s.charCodeAt()
29+
아스키코드 -> 문자열 : String.fromCharCode()
30+
풀이과정
31+
1. 배열을 문자열로 쪼개서 map 메서드로 하나씩 순회한다., 문자열이 비어있으면 리턴한다.
32+
2. 알파벳을 통일 하기 위해 소문자 아스키코드로 변환한다.
33+
대문자 아스키코드는 65가 A, 90이 Z이다.
34+
소문자 아스키코드는 97이 a, 122가 z이다.
35+
3. 변환한 아스키코드 + n이 122이상이면 알파벳 단어 길이 25 + 알파벳 앞으로 이동 1만큼 뺴준고
36+
그렇지 않으면 그대로 더한 후 해당 아스키코드의 알파벳으로 변환해준다.
37+
*/
38+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /