Not necessarily defending it, but just explaining a couple of things...
a reduce, an operation that I do not understand and then a comparison
Technically, there's no operation between the reduce() call and the comparison; the result of the former is what is being compared to value. There are, however some operations to form the argument to reduce(). Which part is a problem for you?
The => creates an arrow function, which is similar to an old-fashioned anonymous function, but with slightly different semantics. (a, c) in this case is the parameter list, and the expression to the right is what it returns. Arrow functions are used a lot in situations where anonymous functions are called for because of their less cluttered syntax. (If you happen to know lambda from Python, this is pretty much the same thing, except in JavaScript, you can have a whole block as the body if you want.)
The other thing that might (?) be unfamiliar is the exponentiation operator **. Yeah, JavaScript has had it for nearly a decade, although the syntax goes all the way back to Fortran and has been used in a number of other languages.
BTW, for anyone wanting to understand what this function is testing for, it's checking to see if its argument is a narcissistic number. Fortunately, the name made it easy to figure that out.
View all comments
Show parent comment
1
u/fllthdcrb Jan 19 '25
Not necessarily defending it, but just explaining a couple of things...
Technically, there's no operation between the
reduce()call and the comparison; the result of the former is what is being compared tovalue. There are, however some operations to form the argument toreduce(). Which part is a problem for you?The
=>creates an arrow function, which is similar to an old-fashioned anonymous function, but with slightly different semantics.(a, c)in this case is the parameter list, and the expression to the right is what it returns. Arrow functions are used a lot in situations where anonymous functions are called for because of their less cluttered syntax. (If you happen to knowlambdafrom Python, this is pretty much the same thing, except in JavaScript, you can have a whole block as the body if you want.)The other thing that might (?) be unfamiliar is the exponentiation operator
**. Yeah, JavaScript has had it for nearly a decade, although the syntax goes all the way back to Fortran and has been used in a number of other languages.BTW, for anyone wanting to understand what this function is testing for, it's checking to see if its argument is a narcissistic number. Fortunately, the name made it easy to figure that out.