Before and After
// before:
for (var i == 0; i < bigArray.length; i++) {
if (bigArray[i].isSelected) {
bigArray[i].onDeselect = (function(i) {
return function() {
doSomething(i);
}
})(i);
}
if (!bigArray[i].isSelectable) {
break;
}
}
// after:
Ox.forEach(bigArray, function(v, i) {
if (v.isSelected) {
v.onDeselect = function() {
doSomething(i);
};
}
return v.isSelectable;
});
// before:
var exists = array.indexOf(value) > -1;
// after:
var exists = Ox.in(array, value);
// before:
var key;
for (var k in obj) {
if (obj[k] === value) {
key = k;
break;
}
}
// after:
var key = Ox.keyOf(object, value);
// before:
var last = arrayWithLongName[arrayWithLongName.length - 1];
// after:
var last = Ox.last(arrayWithLongName);
// before:
arrayWithLongName[arrayWithLongName.length - 1] = 0;
// after:
Ox.last(arrayWithLongName, 0);
// before:
myString = myString.substr(2, myString.length - 4);
// or:
myString = myString.substring(2, myString.length - 2);
// after:
myString = Ox.sub(myString, 2, -2);
// before:
myArray = myArray.filter(function(v, i) {
return i > 1 && i < myArray.length - 2;
});
// after:
myArray = Ox.sub(myArray, 2, -2);
// before:
myNumber = Math.min(Math.max(myNumber, min), max);
// after:
myNumber = Ox.limit(myNumber, min, max);
// before:
var random = min + Math.floor(Math.random() * (max - min));
// after:
var random = Ox.random(min, max);
// before:
var mod = -1 % 10 // -1;
// after:
var mod = Ox.mod(-1, 10) // 9