Solution to the Challenge #6 of AdventJS 2023
Solution to the previous challenge
Solution to the next challenge
Challenge Description
Analys...
For further actions, you may consider blocking this person and/or reporting abuse
function maxDistance(movements) {
let distance = 0, asterisks = 0;
for (let character of movements) {
if (character == ">")
distance++;
else if (character == "<")
distance--;
else
asterisks++;
}
if (distance < 0)
distance *= -1;
return distance + asterisks;
}
Hi Alejandro! Great solution! This line
if (distance < 0) distance *= -1;is the key, clever. Thanks for sharing!Hi, Thanks, at the beginning I used Math.Abs but I finally changed by distance *= -1 because the solution was scored better without Math library, I dont know why :)
Sometimes it's because performance increased or cognitive complexity decreased with the change. π
Or sometimes the server performs better and gives you a better score. π²
yes, youΒ΄re right