Login

JavaScript implementation of Python xrange() builtin

Author:
fish2000
Posted:
December 15, 2010
Language:
JavaScript
Version:
Not specified
Score:
0 (after 4 ratings)

I don't like not having the range()/xrange() in JavaScript — particularly when working with Underscore.js and other such libraries — so I wrote it.

It's not rocket science, but it might help make the world a slightly less annoying place for a couple of people.

1
2
3
4
5
6
7
8
9
function xrange(b0, b1, quantum) {
	if (!quantum) { quantum = 1; }
	if (!b1) { b1 = b0; b0 = 0; }
	out = [];
	for (var i = b0, idx = 0; i < b1; i += quantum, idx++) {
		out[idx] = i;
	}
	return out;
}

More like this

  1. Django Collapsed Stacked Inlines by mkarajohn 10 months, 4 weeks ago
  2. Dynamically adding forms to a formset. OOP version. by halfnibble 6 years, 6 months ago
  3. Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 8 years, 7 months ago
  4. Django admin inline ordering - javascript only implementation by ojhilt 9 years ago
  5. Google v3 geocoding for Geodjango admin site by samhag 9 years, 1 month ago

Comments

Please login first before commenting.