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?
JavaScript

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
SOLUTION
Leonidas Dosas

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23