Find String

Problem

Write a program that receives a single string, receives a specific character, and finds out how many of that specific character exists in the inputted string. The length of the string does not exceed 100.

input

A string is given on the first line, and a character is given on the second line.

COMPUTERPROGRAMMING
R

output

Prints the number of characters in the first line.

3

Solution

using for ... of

function solution(s, t) {
	let answer = 0;
	for (let x of s) {
		if (x === t) answer++;
	}
	return answer;
}

using split()

function solution(s, t) {
	let answer = s.split(t).length - 1;
	return answer;
}