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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo