Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 27 | 28 | 29 |
30 | 31 |
Tags
- 한큐
- Event
- 전자정부프레임워크
- java
- 유뷰브 올리버쌤
- position
- Youtube 올리버쌤
- javascript
- 이벤트핸들러
- 취업반
- 삼항연산자
- hanq
- 이벤트
- 자바
- 한큐에자바
- continue문
- 올리버쌤
- for문
- es6
- 자바스크립트
- web
- break문
- array
- egov
- 이클립스
- Step2
- JDK
- 유튜브 올리버쌤
- spread operator
- math
Archives
- Today
- Total
호다닥
문자 개수 세기 본문
나의 풀이
또 다른 풀이
// 주어진 단어(word)에 특정 알파벳(ch)이 몇 번 들어가는지 세어주는 함수 function countCharacter(word, ch) { var count = 0; for (var i = 0; i < word.length; i++) { if (word[i].toUpperCase() === ch.toUpperCase()) { count++; } } return count; }
// 주어진 단어(word)에 특정 알파벳(ch)이 몇 번 들어가는지 세어주는 함수 function countCharacter(word, ch) { var count = 0; for (var i = 0; i < word.length; i++) { if (word[i].toUpperCase() === ch.toUpperCase()) { count++; } } return count; } // 단어 word에 알파벳 'A'가 몇 번 나오는지 세어주는 함수 function countA(word) { return countCharacter(word, 'A'); } // 테스트 코드 console.log(countCharacter('AbaCedEA', 'E')); console.log(countCharacter('AbaCedEA', 'X')); console.log(countA('AbaCedEA'));
'알고리즘 문제' 카테고리의 다른 글
데이터 분석하기 (0) | 2018.10.04 |
---|---|
아이디 비밀번호 체크 ( 로그인 버튼 활성화,비활성화) (0) | 2018.10.04 |
배열 만들기2 ( 2중배열 하나로 통합하기+내부배열 순서바꾸기 ) (0) | 2018.10.02 |
배열만들기 (0) | 2018.10.02 |
팩토리얼 (0) | 2018.10.01 |
Comments