Hey everyone, wanted to go a little light today on a friday and show you a solution to an easy problem. This solution will focus on using MATH! Hope you enjoy it.
Пікірлер: 26
@sarasalvatierra71982 жыл бұрын
i’ve searched so many videos to find the explanation of the math and you are the only one whose has explained it so well.
@angeloloria65442 жыл бұрын
great video, thank you for this breaking down the math for my own sake reversing a number, ex. 123: 1) use the modulo operator to divide by 10 and return the last decimal space, which will be 3 in this case (123/10 == 12.3) 2) use Math.floor, which will round down and return the nearest whole number, which will be 12 3) use the modulo operator in the same manner as step 1, which will return a 2 (12/10 == 1.2) 4) multiply the first number we extracted (3) times 10, to put it ahead of the second number we extracted (2) 5) add our multiplication result (30) to our second extracted number (2) to get 32. we've now reversed the last two digits of our original number (123) 6) use Math.floor on our last number, which gives us 1 7) use the modulo on that number again, which gives us 1 8) multiply our current reversed number (32) times 10 to put it ahead of our last extracted number (1) 9) add our multiplication result (320) to our last extracted number (1) to get 321, our reversed number
@athirahasri97035 ай бұрын
I love this one. Thank you so much!
@pinkhairblackman81412 жыл бұрын
since the number will be a palindrome return reverse===x; will confirm if the number is the same since its a palindrome when reversed. math.floor(i/10) decrements until i>=1 is false in loop
@UlianaSarkisova11 ай бұрын
Thank you for such an easy to understand explanation!
@Valer0n07 Жыл бұрын
What if an input = 10 or 1000 or 200? This solution will not generate a correct reversed output. But technically it will return a corect answer - false. This input (1234567899) also breaks this algorithm.
@iharisyousaf10 ай бұрын
What do you suggest for these cases
@josey700 Жыл бұрын
Good day! Great content though the font size is just perfect for coding not so much for presenting
@sayeesreeram Жыл бұрын
Great Video :)
@pweezy0012 жыл бұрын
Awesome video, thanks for sharing!
@zherebetskyi40972 жыл бұрын
Great and very helpfull video! Thank's man!
@sarasalvatierra71982 жыл бұрын
you are my savior
@felipegarcialopez37012 жыл бұрын
Great video!
@rawstrife97623 жыл бұрын
GOAT!
@dshl21 Жыл бұрын
thankyou
@jianqiuwang87982 жыл бұрын
why i >= 1 ? can someone explain it ?
@dannycho2287 Жыл бұрын
on line 8, we have the following: for(let i = x; i >= 1; i = Math.floor(i/10)) {...} Now, take an input of 121 as an example. The first iteration of the for loop takes us to i = 121; i is still greater than or equal to 1; i becomes Math.floor(121/10), which is 12. The second iteration of the for loop takes us to i = 12; i is still greater than or equal to 1; i becomes Math.floor(12/10), which is 1. The third iteration of the for loop takes us to i = 1; i is still greater than or equal to 1; i becomes Math.floor(1/10), which is now 0. Since i is now NOT greater than or equal to 1, we come to an end of the for loop. By this time, we already have a reverse version of the number 121.
@jianqiuwang8798 Жыл бұрын
@@dannycho2287 hello Danny, thank you so much for the explanation, I really appreciate it!
@parthgoswami3221 Жыл бұрын
@@dannycho2287 great explanation! thank you
@rajbannasa7662 Жыл бұрын
thank you so much sir
@iharisyousaf10 ай бұрын
It fails in case of 10
@Mikeishere12342 жыл бұрын
make more of these please
@athraafaraj83872 жыл бұрын
Very help
@RichardYoung114 жыл бұрын
bring back the lofi!
@ThinkFWD4 жыл бұрын
I just brought it back ! :), release a new vid with it. let me know if you have any question you want solved/explained