honestbleeps/Reddit-Enhancement-Suite — pull request #184 by nm3210 (2012-08-08 01:37:23+00:00)
Title: Update lib/reddit_enhancement_suite.user.js

This changes the RESGalleryLabel to be 'smart' about the number of zeros it appends to the front of the numbers. It uses the log_base10 (magnitude) of the number to determine this.

I will concede that this small code snippet runs around 10 times SLOWER than the previous two lines (seen here: http://jsperf.com/nm3210), but the number of operations on a page are low enough that it shouldn't matter.

The rounding and 1e9 are to fix the small errors from doing log(n)/log(10), so the first actual error occurs when the album size is exactly 999,999,999 (and the next error after that at 9,999,999,999).