mathdotfloor

What I learned:

Math.floor(number)

This will shave off anything after a decimal point.

Math.floor(number/10)

Put this in a loop and it will cycle through digits starting in the ones place, then shift the decimal point over so the previous tens place is now the ones place, etc.

Why I needed it

The coding challenge was to add the last digit of a number, if the sum is greater than 10, drop the carried one and move on to the next digit. For example, instead of:

990 + 47 = 1037

The answer would drop all carried ones. So the answer would be:

990 + 47 = 937

So I had this long, convoluted code cycling through everything and setting digits to variables and looping through them. I got super close to the correct answer before giving up. I got to the point that I was assigning sums of digits to an array before .joining them together but it wasn’t working for the final digit if the 2 parameters (the numbers to sum) were of different lengths. I figured there had to be a better way and the solution I found used Math.floor(number/10) in a loop to cycle through it all.