js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Solve 'Count the Characters' #287

Closed odv closed 5 years ago

odv commented 5 years ago

https://www.codewars.com/kata/count-the-characters/train/javascript

RazvanBugoi commented 5 years ago
function countChar(string, char) {
  const input = string.toLowerCase();
  const secondArg = char.toLowerCase();
  let output = 0;

  for (let i = 0; i < input.length; i += 1) {
    if (input[i] === char) {
      output += 1;
      }
  }
  return output;
}