This recreates the massive object at every call of the function.
I don't know much about JS, maybe some interpreters are smart and can remember it, but I wouldn't count on that.
While we all want to write more readable code, just remember that 'readability' sometimes depends on our ability to read! More advanced code may seem unreadable for beginners but may actually be very readable and concise the more one learns...
If you want to make it more readable you can always customise the arguments yourself.
Good point, I didn't think about that in my solution.
However, I argue that it doesn't break if one fighter has damageperAttack = 0.
Math.ceil(Infinity) === Infinity
q < Infinity === true
However, if both players have 0 damage, the function would declare the first attacker as a winner (since both factors would be Infinity, that is they would be equal). Semantically, undefined would be a more fitting result as no fighter could ever win or lose. But this (and also stuff like negative damage points) is rather theoretical and not really in the spirit of the exercise.
It means a fighter doesn't take half a turn to attack... he either attacks or doesn't.
'1234'.split('') = ['1' ,'2' ,'3' ,'4'];
n => n < 5,n is a string and 5 is not,is it possible to compare a string with the number(if not) ,then how the above code worked(without converting n to integer value);
This comment is hidden because it contains spoiler information about the solution
I got it done, but definitely not the most simplest way. I gotta learn to move away from for loops and learn more maps and filters!! love this simple solution, nice to read too!
Please use spoiler flag next time.
wow, this's just absolutely brilliant!