10-Day-Rotation

Problem

From June 1st, the Seoul Metropolitan Government will implement the 10 car system to prevent traffic congestion. The 10 car system prohibits the operation of the car if the first digit of the car number matches the first digit of the date For example, if the day digit of the car number is 7, the service cannot be operated on the 7th, 17th, and 27th. Also, if the first digit of the car number is 0, the vehicle cannot be operated on the 10th, 20th, or 30th.
You become a daily police officer and try to do a volunteer activity counting the number of cars that violate the 10 sub-system. Write a program to print the number of vehicles in violation given the day digit of a date and the last two digits of the 7 car numbers.

input

The first line gives the day digit of the date and the second line gives the last two digits of the number of the seven cars.

3
25 23 11 47 53 17 33

0
12 20 54 30 87 91 30

output

It looks at the given date and the car’s day digit and prints the number of vehicles that violate the 10 sub-system

3

3

Solution

divide by 10

function solution(day, arr) {
	let answer = 0;
	for (let x of arr) {
		if (x % 10 == day) answer++;
	}

	return answer;
}

using slice

function solution(day, arr) {
	let answer = 0;
	for (let x of arr) {
		if (x.toString().slice(-1) == day) answer++;
	}

	return answer;
}