https://www.codewars.com/kata/5865918c6b569962950002a1
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
Create a function that accepts a string and a single character, and returns an integer of the count of occurrences the 2nd argument is found in the first one.
If no occurrences can be found, a count of 0 should be returned.
("Hello", "o") ==> 1
("Hello", "l") ==> 2
("", "z") ==> 0
str_count("Hello", 'o'); // returns 1
str_count("Hello", 'l'); // returns 2
str_count("", 'z'); // returns 0
Notes
- The first argument can be an empty string
- In languages with no distinct character data type, the second argument will be a string of length 1
코드
function strCount(str, letter){
return str.split('').filter(el => el === letter).length;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Surface Area and Volume of a Box (8 kyu) / JavaScript (0) | 2023.03.29 |
---|---|
[Codewars] Sort Numbers (7 kyu) / JavaScript (0) | 2023.03.28 |
[Codewars] Enumerable Magic - Does My List Include This? (8 kyu) / JavaScript (0) | 2023.03.26 |
[Codewars] Find the capitals (7 kyu) / JavaScript (0) | 2023.03.25 |
[Codewars] Sum The Strings (8 kyu) / JavaScript (0) | 2023.03.24 |
댓글