I was playing codewars, i came up with this
function nbDig(n, d) {
// your code
var count;
count=0;
while(n>0){
var squared = (n*n).toString();
var regex = new RegExp(d,"gi");
var matches = squared.match(regex);
if(matches){
count = count + matches.length;
}
n--;
}
return count;
}
However one of the best practices submitted was the following below
function nbDig(n, d) {
var res=0;
for (var g=0;g<=n;g++){
var square=(g*g+"").split("");
square.forEach((s)=>s==d?res++:null)
}return res;
}
I do not understand the (s)=>s==d
I believe that this is function(s){ s==d?res++:null}
Is that correct, can someone provide some good documentation or link for the (s)=> paradigm in javascript?