javascript - Converting ECMAScript 6's arrow function to a regular function -


i have following arrow function

if( rowcheckstatuses.reduce((a, b) => + b, 0) ){}

rowcheckstatuses array of 1's , 0's, arrow function adds them produce number. number acts boolean determine whether or not there @ least 1 "1" in array.

the issue is, don't understand how arrow functions work, , ide thinks it's bad syntax , refuses check rest of document syntax errors.

how go converting regular function alleviate both issues?

you can refactor as:

if( rowcheckstatuses.reduce(function(a, b){return + b}, 0) 

the initial accumulator isn't necessary (unless expect array empty sometimes), be:

if( rowcheckstatuses.reduce(function(a, b){return + b}) 

this number acts boolean determine whether or not there @ least 1 "1" in array

it might faster (and clearer) use:

if( rowcheckstatuses.some(function(a){return == 1})) 

which return true if there 1s in rowcheckstatuses , return 1 encountered. alternative indexof:

if( rowcheckstatuses.indexof(1) != -1) 

lots of alternatives.