tl; dr: what does => do?
I just decided to solve the problem on code carriers and, looking at the general answers of other people to the problem, I always see this: =>
The problem is below:
You have a quiver of arrows, but some of them have been damaged. The quiver contains arrows with additional information about the range (different types of targets are placed in different ranges), so each element is an arrow. You need to make sure that you have good ones to prepare for the battle. Below is an example of an array that is a quiver of arrows.
anyArrows([ {range: 5}, {range: 10, damaged: true}, {damaged: true} ])
If the arrow in the quiver does not have a damaged condition, it means that it is new.
This is an example I saw that returns true or false, depending on whether the quiver has an intact arrow:
function anyArrows(arrows){ return arrows.some(a => !a.damaged); }
Now it was much shorter than my code! Mine was much more basic:
function anyArrows(arrows){ for ( var i = 0 ; i < 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, the question arises: what does => in this case and in general?
source share