ecmascript 6 - What does => mean in JavaScript? (equals greater than) -
this question has answer here:
tl;dr: => do?
i've finished solving problem on codewars , after looking @ other peoples' common responses problem, keep seeing this: =>
the problem below:
you have quiver of arrows, have been damaged. quiver contains arrows optional range information (different types of targets positioned @ different ranges), each item arrow. you need verify have ones left, in order prepare battle. below example array quiver of arrows.
anyarrows([ {range: 5}, {range: 10, damaged: true}, {damaged: true} ])
if arrow in quiver not have damaged status, means it's new.
this example saw returns true or false, depending on if there undamaged arrow in quiver:
function anyarrows(arrows){ return arrows.some(a => !a.damaged); }
now, way shorter code! mine lot more basic:
function anyarrows(arrows){ ( var = 0 ; < arrows.length ; i++ ){ if ( arrows[i].damaged === false ) { return true; } else if (arrows[i].damaged === true) { return false; } else if (arrows[i].range === 0) { return false } else { return true; } } if (arrows.length === 0) return false; }
again though, question is: =>
in case , in general?
=>
es2015 syntax separates arrow function parameters body, e.g. (params) => { /* body */ }
.
arrowfunction : arrowparameters => concisebody
Comments
Post a Comment