Link to home
Start Free TrialLog in
Avatar of Brant Snow
Brant Snow

asked on

Explain this javascript function to me

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?
SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial