Implementing sethaurus' suggestion for better temp variable names -- getting rid of the numbers.

This commit is contained in:
Jeremy Ashkenas
2010-02-16 18:00:40 -05:00
parent e4bb6c91e7
commit db6bc0ba02
8 changed files with 256 additions and 256 deletions

View File

@@ -40,22 +40,22 @@
// The cornerstone, an each implementation.
// Handles objects implementing forEach, arrays, and raw objects.
_.each = function each(obj, iterator, context) {
var _1, _2, _3, _4, _5, _6, i, index, key, val;
var _a, _b, _c, _d, _e, _f, i, index, key, val;
index = 0;
try {
if (obj.forEach) {
return obj.forEach(iterator, context);
}
if (_.isNumber(obj.length)) {
_1 = []; _4 = 0; _5 = obj.length;
for (_3=0, i=_4; (_4 <= _5 ? i < _5 : i > _5); (_4 <= _5 ? i += 1 : i -= 1), _3++) {
_1.push(iterator.call(context, obj[i], i, obj));
_a = []; _d = 0; _e = obj.length;
for (_c=0, i=_d; (_d <= _e ? i < _e : i > _e); (_d <= _e ? i += 1 : i -= 1), _c++) {
_a.push(iterator.call(context, obj[i], i, obj));
}
return _1;
return _a;
}
_6 = obj;
for (key in _6) if (__hasProp.call(_6, key)) {
val = _6[key];
_f = obj;
for (key in _f) if (__hasProp.call(_f, key)) {
val = _f[key];
iterator.call(context, val, key, obj);
}
} catch (e) {
@@ -173,13 +173,13 @@
// Determine if a given value is included in the array or object,
// based on '==='.
_.include = function include(obj, target) {
var _1, key, val;
var _a, key, val;
if (obj && _.isFunction(obj.indexOf)) {
return _.indexOf(obj, target) !== -1;
}
_1 = obj;
for (key in _1) if (__hasProp.call(_1, key)) {
val = _1[key];
_a = obj;
for (key in _a) if (__hasProp.call(_a, key)) {
val = _a[key];
if (val === target) {
return true;
}
@@ -188,15 +188,15 @@
};
// Invoke a method with arguments on every item in a collection.
_.invoke = function invoke(obj, method) {
var _1, _2, _3, args, val;
var _a, _b, _c, args, val;
var arguments = Array.prototype.slice.call(arguments, 0);
args = _.rest(arguments, 2);
_1 = []; _2 = obj;
for (_3 = 0; _3 < _2.length; _3++) {
val = _2[_3];
_1.push((method ? val[method] : val).apply(val, args));
_a = []; _b = obj;
for (_c = 0; _c < _b.length; _c++) {
val = _b[_c];
_a.push((method ? val[method] : val).apply(val, args));
}
return _1;
return _a;
};
// Convenience version of a common use case of map: fetching a property.
_.pluck = function pluck(obj, key) {
@@ -315,14 +315,14 @@
};
// Trim out all falsy values from an array.
_.compact = function compact(array) {
var _1, _2, _3, _4, _5, i;
_1 = []; _4 = 0; _5 = array.length;
for (_3=0, i=_4; (_4 <= _5 ? i < _5 : i > _5); (_4 <= _5 ? i += 1 : i -= 1), _3++) {
var _a, _b, _c, _d, _e, i;
_a = []; _d = 0; _e = array.length;
for (_c=0, i=_d; (_d <= _e ? i < _e : i > _e); (_d <= _e ? i += 1 : i -= 1), _c++) {
if (array[i]) {
_1.push(array[i]);
_a.push(array[i]);
}
}
return _1;
return _a;
};
// Return a completely flattened version of an array.
_.flatten = function flatten(array) {
@@ -336,26 +336,26 @@
};
// Return a version of the array that does not contain the specified value(s).
_.without = function without(array) {
var _1, _2, _3, val, values;
var _a, _b, _c, val, values;
var arguments = Array.prototype.slice.call(arguments, 0);
values = _.rest(arguments);
_1 = []; _2 = _.toArray(array);
for (_3 = 0; _3 < _2.length; _3++) {
val = _2[_3];
_a = []; _b = _.toArray(array);
for (_c = 0; _c < _b.length; _c++) {
val = _b[_c];
if (!_.include(values, val)) {
_1.push(val);
_a.push(val);
}
}
return _1;
return _a;
};
// Produce a duplicate-free version of the array. If the array has already
// been sorted, you have the option of using a faster algorithm.
_.uniq = function uniq(array, isSorted) {
var _1, el, i, memo;
var _a, el, i, memo;
memo = [];
_1 = _.toArray(array);
for (i = 0; i < _1.length; i++) {
el = _1[i];
_a = _.toArray(array);
for (i = 0; i < _a.length; i++) {
el = _a[i];
if (i === 0 || (isSorted === true ? _.last(memo) !== el : !_.include(memo, el))) {
memo.push(el);
}
@@ -377,12 +377,12 @@
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function zip() {
var _1, _2, _3, _4, i, length, results;
var _a, _b, _c, _d, i, length, results;
var arguments = Array.prototype.slice.call(arguments, 0);
length = _.max(_.pluck(arguments, 'length'));
results = new Array(length);
_3 = 0; _4 = length;
for (_2=0, i=_3; (_3 <= _4 ? i < _4 : i > _4); (_3 <= _4 ? i += 1 : i -= 1), _2++) {
_c = 0; _d = length;
for (_b=0, i=_c; (_c <= _d ? i < _d : i > _d); (_c <= _d ? i += 1 : i -= 1), _b++) {
results[i] = _.pluck(arguments, String(i));
}
return results;
@@ -427,7 +427,7 @@
// the native Python range() function. See:
// http://docs.python.org/library/functions.html#range
_.range = function range(start, stop, step) {
var _1, a, i, idx, len, range, solo;
var _a, a, i, idx, len, range, solo;
var arguments = Array.prototype.slice.call(arguments, 0);
a = arguments;
solo = a.length <= 1;
@@ -440,7 +440,7 @@
}
range = new Array(len);
idx = 0;
_1 = [];
_a = [];
while (true) {
if ((step > 0 ? i - stop : stop - i) >= 0) {
return range;
@@ -449,7 +449,7 @@
idx++;
i += step;
}
return _1;
return _a;
};
// ----------------------- Function Functions: -----------------------------
// Create a function bound to a given object (assigning 'this', and arguments,
@@ -506,11 +506,11 @@
var arguments = Array.prototype.slice.call(arguments, 0);
funcs = arguments;
return (function() {
var _1, _2, _3, _4, args, i;
var _a, _b, _c, _d, args, i;
var arguments = Array.prototype.slice.call(arguments, 0);
args = arguments;
_3 = (funcs.length - 1); _4 = 0;
for (_2=0, i=_3; (_3 <= _4 ? i <= _4 : i >= _4); (_3 <= _4 ? i += 1 : i -= 1), _2++) {
_c = (funcs.length - 1); _d = 0;
for (_b=0, i=_c; (_c <= _d ? i <= _d : i >= _d); (_c <= _d ? i += 1 : i -= 1), _b++) {
args = [funcs[i].apply(this, args)];
}
return args[0];
@@ -519,16 +519,16 @@
// ------------------------- Object Functions: ----------------------------
// Retrieve the names of an object's properties.
_.keys = function keys(obj) {
var _1, _2, key, val;
var _a, _b, key, val;
if (_.isArray(obj)) {
return _.range(0, obj.length);
}
_1 = []; _2 = obj;
for (key in _2) if (__hasProp.call(_2, key)) {
val = _2[key];
_1.push(key);
_a = []; _b = obj;
for (key in _b) if (__hasProp.call(_b, key)) {
val = _b[key];
_a.push(key);
}
return _1;
return _a;
};
// Retrieve the values of an object's properties.
_.values = function values(obj) {
@@ -542,10 +542,10 @@
};
// Extend a given object with all of the properties in a source object.
_.extend = function extend(destination, source) {
var _1, key, val;
_1 = source;
for (key in _1) if (__hasProp.call(_1, key)) {
val = _1[key];
var _a, key, val;
_a = source;
for (key in _a) if (__hasProp.call(_a, key)) {
val = _a[key];
destination[key] = val;
}
return destination;