I've developed a function that counts the number of "7" in the given array. But the problem is that it counts an element only once if it has multiple 7's. I want to calculate overall number of 7 in the array. Note: Please describe the logic in a simple and easy to understand way as I'm a newbie in Javascript.
function sevenBoom(arr){
debugger;
let singleElement, string, includeSeven;
let flag = false;
let counter = 0;
for (let i=0; i<arr.length; i++){
singleElement = arr[i];
string = singleElement.toString();
includeSeven = string.includes("7");
if (includeSeven == true){
flag = true;
counter += 1;
}
}
if (counter == 0){
return "There is no 7 in the array";
}else{
return `Boom! There are ${counter} 7s in the array...`;
}
}
arr = [6,7,87, 777, 107777];
sevenBoom(arr);