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 602fd1f

Browse files
chaerin-devprove-ability
authored andcommitted
Add 문자열-내-p와-y의-개수.js
1 parent ec1eea3 commit 602fd1f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

‎level-1/문자열-내-p와-y의-개수.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ function solution(s) {
1717

1818
return p == y ? true : false;
1919
}
20+
21+
//정답 3 - chaerin-dev
22+
function solution(s) {
23+
let pCount = s.split(/p/i).length - 1;
24+
let yCount = s.split(/y/i).length - 1;
25+
return pCount === yCount;
26+
}
27+
// 문자열에서 특정 문자의 개수를 구하려면 split을 사용하면 된다.
28+
// Ex. "ababb".split("a") 의 결과는 ["", "b", "bb"]
29+
// => 즉, "a"의 갯수는 3에서 1을 뺀 2

0 commit comments

Comments
(0)

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