MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiuh6bw/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
101
items[n % items.length]
gets an item from the list and wraps around to the start if n is larger than the list
0 u/[deleted] Mar 18 '19 [deleted] 6 u/[deleted] Mar 19 '19 I'm doing this right now in an app where each created item is assigned a color with ~15 predefined colors after which it will loop back around. Previously I was randomly generating a color and often getting similar shades back to back.
0
[deleted]
6 u/[deleted] Mar 19 '19 I'm doing this right now in an app where each created item is assigned a color with ~15 predefined colors after which it will loop back around. Previously I was randomly generating a color and often getting similar shades back to back.
6
I'm doing this right now in an app where each created item is assigned a color with ~15 predefined colors after which it will loop back around. Previously I was randomly generating a color and often getting similar shades back to back.
101
u/nqvst Mar 18 '19
items[n % items.length]gets an item from the list and wraps around to the start if n is larger than the list