The government announced plans to adopt a 10-day rotation system of driving to relieve traffic congestion. From now on, private vehicles may not be driven on dates that end in the same number as the last digit of the vehicle's license plate. For example, if your license plate number ends in 0, you may not drive your car on 10th, 20th and 30th of the month. If it ends in 7, you may not drive on 7th, 17th and 27th.
Write a program which counts the number of vehicles who didn't follow the rule. You will be given the last two digits of few vehicles' plate number and the last digit of the day.
Solution
/*
1. Declare variable named count and initialize its value with 0.
2. Iterate the array with for...of loop to find the vehicles which didn't follow the rule.
We have to compare the day and the last digit of each elements.
How to get last digit of certain number? Divide the number into 10 and take the mod.
So if the day and the remainder of (x / 10) equals, increment the count.
*/
function solution(day, arr){
let count = 0;
for (let x of arr){
if (x % 10 === day) count++;
}
return count;
}
Result