Steven
Steven

Reputation: 1596

Subtract largest multiple of 10

I'm trying to set up animating in a list of items in React. I'm using Velocity for the animations, and using react/addons's TransitionGroup. The easy part is using the index of the item in the list to "stagger" them in, but there's a problem when I load additional data from the server, and add them to the list: the index of the new items are from 20 to [x], so they wait (20 * 300ms) before the first one animates in. Given a number, say 23, is there an easy way to boil this down to 3 (remove 20 in this case, if the number were 55, boil it down to 5). This should be really basic, but I can't get my head around an elegant solution. Any help would be greatly appreciated!

Upvotes: 0

Views: 66

Answers (2)

dhuang
dhuang

Reputation: 921

Have you tried:

 var onesDigit = yourarray.length % 10;

Upvotes: 0

Paweł Smołka
Paweł Smołka

Reputation: 638

You need to use modulus: %

23 % 10 = 3

Upvotes: 4

Related Questions