Cleanup lodash.js.

Former-commit-id: 7a2443719a96b36ae53b2f7d0fe2a1867d650f02
This commit is contained in:
John-David Dalton
2012-10-04 00:25:32 -07:00
parent 21217dfda3
commit a0cb8ec124

View File

@@ -2548,13 +2548,11 @@
var index = -1, var index = -1,
length = array ? array.length : 0; length = array ? array.length : 0;
if (fromIndex) { if (typeof fromIndex == 'number') {
if (typeof fromIndex == 'number') { index = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex || 0) - 1;
index = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex) - 1; } else if (fromIndex) {
} else { index = sortedIndex(array, value);
index = sortedIndex(array, value); return array[index] === value ? index : -1;
return array[index] === value ? index : -1;
}
} }
while (++index < length) { while (++index < length) {
if (array[index] === value) { if (array[index] === value) {
@@ -2669,7 +2667,7 @@
*/ */
function lastIndexOf(array, value, fromIndex) { function lastIndexOf(array, value, fromIndex) {
var index = array ? array.length : 0; var index = array ? array.length : 0;
if (fromIndex && typeof fromIndex == 'number') { if (typeof fromIndex == 'number') {
index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1; index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1;
} }
while (index--) { while (index--) {
@@ -2879,13 +2877,12 @@
* // => [4, 1, 6, 3, 5, 2] * // => [4, 1, 6, 3, 5, 2]
*/ */
function shuffle(array) { function shuffle(array) {
var rand, var index = -1,
index = -1,
length = array ? array.length : 0, length = array ? array.length : 0,
result = Array(length); result = Array(length);
while (++index < length) { while (++index < length) {
rand = nativeFloor(nativeRandom() * (index + 1)); var rand = nativeFloor(nativeRandom() * (index + 1));
result[index] = result[rand]; result[index] = result[rand];
result[rand] = array[index]; result[rand] = array[index];
} }
@@ -2933,14 +2930,13 @@
* // => 2 * // => 2
*/ */
function sortedIndex(array, value, callback, thisArg) { function sortedIndex(array, value, callback, thisArg) {
var mid, var low = 0,
low = 0,
high = array ? array.length : low; high = array ? array.length : low;
callback = createCallback(callback, thisArg); callback = createCallback(callback, thisArg);
value = callback(value); value = callback(value);
while (low < high) { while (low < high) {
mid = (low + high) >>> 1; var mid = (low + high) >>> 1;
callback(array[mid]) < value ? low = mid + 1 : high = mid; callback(array[mid]) < value ? low = mid + 1 : high = mid;
} }
return low; return low;
@@ -3006,8 +3002,7 @@
* // => [1, 2, 3] * // => [1, 2, 3]
*/ */
function uniq(array, isSorted, callback, thisArg) { function uniq(array, isSorted, callback, thisArg) {
var computed, var index = -1,
index = -1,
length = array ? array.length : 0, length = array ? array.length : 0,
result = [], result = [],
seen = []; seen = [];
@@ -3020,7 +3015,7 @@
} }
callback = createCallback(callback, thisArg); callback = createCallback(callback, thisArg);
while (++index < length) { while (++index < length) {
computed = callback(array[index], index, array); var computed = callback(array[index], index, array);
if (isSorted if (isSorted
? !index || seen[seen.length - 1] !== computed ? !index || seen[seen.length - 1] !== computed
: indexOf(seen, computed) < 0 : indexOf(seen, computed) < 0