알고리즘 62 - All Star Code Challenge #18

tamagoyakii·2021년 10월 19일
0

알고리즘

목록 보기
62/89

Q.

Create a function that accepts 2 string arguments 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
Notes:

The first argument can be an empty string
The second string argument will always be of length 1

A)

function strCount(str, letter) {  
  return str.split('').filter(el =>  el === letter).length
}

0개의 댓글