code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function createBindWrapper(func, thisArg) {
var Ctor = createCtorWrapper(func);
function wrapper() {
return (this instanceof wrapper ? Ctor : func).apply(thisArg, arguments);
}
return wrapper;
}
|
Creates a function that wraps `func` and invokes it with the `this`
binding of `thisArg`.
@private
@param {Function} func The function to bind.
@param {*} [thisArg] The `this` binding of `func`.
@returns {Function} Returns the new bound function.
|
createBindWrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function wrapper() {
return (this instanceof wrapper ? Ctor : func).apply(thisArg, arguments);
}
|
Creates a function that wraps `func` and invokes it with the `this`
binding of `thisArg`.
@private
@param {Function} func The function to bind.
@param {*} [thisArg] The `this` binding of `func`.
@returns {Function} Returns the new bound function.
|
wrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function createCompounder(callback) {
return function(string) {
var index = -1,
array = words(deburr(string)),
length = array.length,
result = '';
while (++index < length) {
result = callback(result, array[index], index);
}
return result;
};
}
|
Creates a function that produces compound words out of the words in a
given string.
@private
@param {Function} callback The function invoked to combine each word.
@returns {Function} Returns the new compounder function.
|
createCompounder
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function createCtorWrapper(Ctor) {
return function() {
var thisBinding = baseCreate(Ctor.prototype),
result = Ctor.apply(thisBinding, arguments);
// mimic the constructor's `return` behavior
// http://es5.github.io/#x13.2.2
return isObject(result) ? result : thisBinding;
};
}
|
Creates a function that produces an instance of `Ctor` regardless of
whether it was invoked as part of a `new` expression or by `call` or `apply`.
@private
@param {Function} Ctor The constructor to wrap.
@returns {Function} Returns the new wrapped function.
|
createCtorWrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, arity) {
var isBind = bitmask & BIND_FLAG,
isBindKey = bitmask & BIND_KEY_FLAG,
isCurry = bitmask & CURRY_FLAG,
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
isCurryBound = bitmask & CURRY_BOUND_FLAG;
var Ctor = !isBindKey && createCtorWrapper(func),
key = func;
function wrapper() {
var length = arguments.length,
index = length,
args = Array(length);
while (index--) {
args[index] = arguments[index];
}
if (argPos) {
args = arrayReduceRight(argPos, reorder, args);
}
if (partials) {
args = composeArgs(args, partials, holders);
}
if (partialsRight) {
args = composeArgsRight(args, partialsRight, holdersRight);
}
if (isCurry || isCurryRight) {
var placeholder = wrapper.placeholder,
argsHolders = replaceHolders(args, placeholder);
length -= argsHolders.length;
if (length < arity) {
var newArgPos = argPos ? baseSlice(argPos) : null,
newArity = nativeMax(arity - length, 0),
newsHolders = isCurry ? argsHolders : null,
newHoldersRight = isCurry ? null : argsHolders,
newPartials = isCurry ? args : null,
newPartialsRight = isCurry ? null : args;
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
if (!isCurryBound) {
bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
}
var result = createHybridWrapper(func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, newArity);
result.placeholder = placeholder;
return result;
}
}
var thisBinding = isBind ? thisArg : this;
if (isBindKey) {
func = thisBinding[key];
}
return (this instanceof wrapper ? (Ctor || createCtorWrapper(func)) : func).apply(thisBinding, args);
}
return wrapper;
}
|
Creates a function that wraps `func` and invokes it with optional `this`
binding of, partial application, and currying.
@private
@param {Function|string} func The function or method name to reference.
@param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
@param {*} [thisArg] The `this` binding of `func`.
@param {Array} [partials] The arguments to prepend to those provided to the new function.
@param {Array} [holders] The `partials` placeholder indexes.
@param {Array} [partialsRight] The arguments to append to those provided to the new function.
@param {Array} [holdersRight] The `partialsRight` placeholder indexes.
@param {Array} [argPos] The argument positions of the new function.
@param {number} arity The arity of `func`.
@returns {Function} Returns the new wrapped function.
|
createHybridWrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function wrapper() {
var length = arguments.length,
index = length,
args = Array(length);
while (index--) {
args[index] = arguments[index];
}
if (argPos) {
args = arrayReduceRight(argPos, reorder, args);
}
if (partials) {
args = composeArgs(args, partials, holders);
}
if (partialsRight) {
args = composeArgsRight(args, partialsRight, holdersRight);
}
if (isCurry || isCurryRight) {
var placeholder = wrapper.placeholder,
argsHolders = replaceHolders(args, placeholder);
length -= argsHolders.length;
if (length < arity) {
var newArgPos = argPos ? baseSlice(argPos) : null,
newArity = nativeMax(arity - length, 0),
newsHolders = isCurry ? argsHolders : null,
newHoldersRight = isCurry ? null : argsHolders,
newPartials = isCurry ? args : null,
newPartialsRight = isCurry ? null : args;
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
if (!isCurryBound) {
bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
}
var result = createHybridWrapper(func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, newArity);
result.placeholder = placeholder;
return result;
}
}
var thisBinding = isBind ? thisArg : this;
if (isBindKey) {
func = thisBinding[key];
}
return (this instanceof wrapper ? (Ctor || createCtorWrapper(func)) : func).apply(thisBinding, args);
}
|
Creates a function that wraps `func` and invokes it with optional `this`
binding of, partial application, and currying.
@private
@param {Function|string} func The function or method name to reference.
@param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
@param {*} [thisArg] The `this` binding of `func`.
@param {Array} [partials] The arguments to prepend to those provided to the new function.
@param {Array} [holders] The `partials` placeholder indexes.
@param {Array} [partialsRight] The arguments to append to those provided to the new function.
@param {Array} [holdersRight] The `partialsRight` placeholder indexes.
@param {Array} [argPos] The argument positions of the new function.
@param {number} arity The arity of `func`.
@returns {Function} Returns the new wrapped function.
|
wrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function createPad(string, length, chars) {
var strLength = string.length;
length = +length;
if (strLength >= length || !nativeIsFinite(length)) {
return '';
}
var padLength = length - strLength;
chars = chars == null ? ' ' : String(chars);
return repeat(chars, ceil(padLength / chars.length)).slice(0, padLength);
}
|
Creates the pad required for `string` based on the given padding length.
The `chars` string may be truncated if the number of padding characters
exceeds the padding length.
@private
@param {string} string The string to create padding for.
@param {number} [length=0] The padding length.
@param {string} [chars=' '] The string used as padding.
@returns {string} Returns the pad for `string`.
|
createPad
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function createPartialWrapper(func, bitmask, partials, thisArg) {
var isBind = bitmask & BIND_FLAG,
Ctor = createCtorWrapper(func);
function wrapper() {
// avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it to `composeArgs`
var argsIndex = -1,
argsLength = arguments.length,
leftIndex = -1,
leftLength = partials.length,
args = Array(argsLength + leftLength);
while (++leftIndex < leftLength) {
args[leftIndex] = partials[leftIndex];
}
while (argsLength--) {
args[leftIndex++] = arguments[++argsIndex];
}
return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args);
}
return wrapper;
}
|
Creates a function that wraps `func` and invokes it with the optional `this`
binding of `thisArg` and the `partialArgs` prepended to those provided to
the wrapper.
@private
@param {Function} func The function to partially apply arguments to.
@param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
@param {Array} partials The arguments to prepend to those provided to the new function.
@param {*} [thisArg] The `this` binding of `func`.
@returns {Function} Returns the new bound function.
|
createPartialWrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function wrapper() {
// avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it to `composeArgs`
var argsIndex = -1,
argsLength = arguments.length,
leftIndex = -1,
leftLength = partials.length,
args = Array(argsLength + leftLength);
while (++leftIndex < leftLength) {
args[leftIndex] = partials[leftIndex];
}
while (argsLength--) {
args[leftIndex++] = arguments[++argsIndex];
}
return (this instanceof wrapper ? Ctor : func).apply(isBind ? thisArg : this, args);
}
|
Creates a function that wraps `func` and invokes it with the optional `this`
binding of `thisArg` and the `partialArgs` prepended to those provided to
the wrapper.
@private
@param {Function} func The function to partially apply arguments to.
@param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
@param {Array} partials The arguments to prepend to those provided to the new function.
@param {*} [thisArg] The `this` binding of `func`.
@returns {Function} Returns the new bound function.
|
wrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, arity) {
var isBindKey = bitmask & BIND_KEY_FLAG;
if (!isBindKey && !isFunction(func)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var length = partials ? partials.length : 0;
if (!length) {
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
partials = holders = null;
}
if (partials && !holders) {
holders = [];
}
var oldPartials = partials,
oldHolders = holders,
isPartial = bitmask & PARTIAL_FLAG,
isPartialRight = bitmask & PARTIAL_RIGHT_FLAG;
if (!isPartial) {
var partialsRight = partials,
holdersRight = holders;
partials = holders = null;
}
var data = (data = !isBindKey && getData(func)) && data !== true && data;
if (data) {
var funcBitmask = data[1],
funcIsBind = funcBitmask & BIND_FLAG,
isBind = bitmask & BIND_FLAG;
// use metadata `func` and merge bitmasks
func = data[0];
bitmask |= funcBitmask;
// use metadata `thisArg` if available
if (funcIsBind) {
thisArg = data[2];
}
// set if currying a bound function
if (!isBind && funcIsBind) {
bitmask |= CURRY_BOUND_FLAG;
}
// compose partial arguments
var value = data[3];
if (value) {
var funcHolders = data[4];
partials = isPartial ? composeArgs(partials, value, funcHolders) : baseSlice(value);
holders = isPartial ? replaceHolders(partials, PLACEHOLDER) : baseSlice(funcHolders);
}
// compose partial right arguments
value = data[5];
if (value) {
funcHolders = data[6];
partialsRight = isPartialRight ? composeArgsRight(partialsRight, value, funcHolders) : baseSlice(value);
holdersRight = isPartialRight ? replaceHolders(partialsRight, PLACEHOLDER) : baseSlice(funcHolders);
}
// append argument positions
value = data[7];
if (value) {
value = baseSlice(value);
if (argPos) {
push.apply(value, argPos);
}
argPos = value;
}
// use metadata `arity` if not provided
if (arity == null) {
arity = data[8];
}
}
if (arity == null) {
arity = isBindKey ? 0 : func.length;
} else {
arity = nativeMax(+arity || 0, 0);
}
if (oldPartials) {
arity = nativeMax(arity - (oldPartials.length - oldHolders.length), 0);
}
if (bitmask == BIND_FLAG) {
var result = createBindWrapper(func, thisArg);
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
result = createPartialWrapper(func, bitmask, partials, thisArg);
} else {
result = createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, arity);
}
var setter = data ? baseSetData : setData;
return setter(result, [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, arity]);
}
|
Creates a function that either curries or invokes `func` with optional
`this` binding and partially applied arguments.
@private
@param {Function|string} func The function or method name to reference.
@param {number} bitmask The bitmask of flags.
The bitmask may be composed of the following flags:
1 - `_.bind`
2 - `_.bindKey`
4 - `_.curry`
8 - `_.curryRight`
16 - `_.curry` or `_.curryRight` of a bound function
32 - `_.partial`
64 - `_.partialRight`
128 - `_.rearg`
@param {*} [thisArg] The `this` binding of `func`.
@param {Array} [partials] The arguments to be partially applied.
@param {Array} [holders] The `partialArgs` placeholder indexes.
@param {Array} [argPos] The argument positions of the new function.
@param {number} [arity] The arity of `func`.
@returns {Function} Returns the new wrapped function.
|
createWrapper
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function getCallback(func, thisArg, argCount) {
var result = lodash.callback || callback;
result = result === callback ? baseCallback : result;
return argCount ? result(func, thisArg, argCount) : result;
}
|
Gets the appropriate "callback" function. If the `_.callback` method is
customized this function returns the custom method, otherwise it returns
the `baseCallback` function. If arguments are provided the chosen function
is invoked with them and its result is returned.
@private
@returns {Function} Returns the chosen function or its result.
|
getCallback
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function getIndexOf(collection, target, fromIndex) {
var result = lodash.indexOf || indexOf;
result = result === indexOf ? baseIndexOf : result;
return collection ? result(collection, target, fromIndex) : result;
}
|
Gets the appropriate "indexOf" function. If the `_.indexOf` method is
customized this function returns the custom method, otherwise it returns
the `baseIndexOf` function. If arguments are provided the chosen function
is invoked with them and its result is returned.
@private
@returns {Function|number} Returns the chosen function or its result.
|
getIndexOf
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function getView(start, end, transforms) {
var index = -1,
length = transforms ? transforms.length : 0;
while (++index < length) {
var data = transforms[index],
size = data.size;
switch (data.type) {
case 'drop': start += size; break;
case 'dropRight': end -= size; break;
case 'take': end = nativeMin(end, start + size); break;
case 'takeRight': start = nativeMax(start, end - size); break;
}
}
return { 'start': start, 'end': end };
}
|
Gets the view, applying any `transforms` to the `start` and `end` positions.
@private
@param {number} start The start of the view.
@param {number} end The end of the view.
@param {Array} [transforms] The transformations to apply to the view.
@returns {Object} Returns an object containing the `start` and `end`
positions of the view.
|
getView
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function initArrayClone(array, isDeep) {
var index = -1,
length = array.length,
result = new array.constructor(length);
if (!isDeep) {
while (++index < length) {
result[index] = array[index];
}
}
// add array properties assigned by `RegExp#exec`
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
result.index = array.index;
result.input = array.input;
}
return result;
}
|
Initializes an array clone.
@private
@param {Array} array The array to clone.
@param {boolean} [isDeep=false] Specify a deep clone.
@returns {Array} Returns the initialized array clone.
|
initArrayClone
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function initObjectClone(object, isDeep) {
if (!isCloneable(object)) {
return null;
}
var Ctor = object.constructor,
className = toString.call(object),
isArgs = className == argsClass || (!lodash.support.argsClass && isArguments(object)),
isObj = className == objectClass;
if (isObj && !(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
Ctor = Object;
}
if (isArgs || isObj) {
var result = isDeep ? new Ctor : baseAssign(new Ctor, object);
if (isArgs) {
result.length = object.length;
}
return result;
}
switch (className) {
case arrayBufferClass:
return bufferClone(object);
case boolClass:
case dateClass:
return new Ctor(+object);
case float32Class: case float64Class:
case int8Class: case int16Class: case int32Class:
case uint8Class: case uint8ClampedClass: case uint16Class: case uint32Class:
// Safari 5 mobile incorrectly has `Object` as the constructor
if (Ctor instanceof Ctor) {
Ctor = ctorByClass[className];
}
var buffer = object.buffer;
return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
case numberClass:
case stringClass:
return new Ctor(object);
case regexpClass:
result = new Ctor(object.source, reFlags.exec(object));
result.lastIndex = object.lastIndex;
}
return result;
}
|
Initializes an object clone.
@private
@param {Object} object The object to clone.
@param {boolean} [isDeep=false] Specify a deep clone.
@returns {null|Object} Returns the initialized object clone.
|
initObjectClone
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function isArrayLike(value) {
return (value && typeof value == 'object' && isLength(value.length) &&
(arrayLikeClasses[toString.call(value)] || (!lodash.support.argsClass && isArguments(value)))) || false;
}
|
Checks if `value` is an array-like object.
@private
@param {*} value The value to check.
@returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
|
isArrayLike
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function isCloneable(value) {
return (value && cloneableClasses[toString.call(value)] && !isHostObject(value)) || false;
}
|
Checks if `value` is cloneable.
@private
@param {*} value The value to check.
@returns {boolean} Returns `true` if `value` is cloneable, else `false`.
|
isCloneable
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function isIterateeCall(value, index, object) {
if (!isObject(object)) {
return false;
}
var type = typeof index;
if (type == 'number') {
var length = object.length,
prereq = isLength(length) && isIndex(index, length);
} else {
prereq = type == 'string';
}
return prereq && object[index] === value;
}
|
Checks if the provided arguments are from an iteratee call.
@private
@param {*} value The potential iteratee value argument.
@param {*} index The potential iteratee index or key argument.
@param {*} object The potential iteratee object argument.
@returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
|
isIterateeCall
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function isLength(value) {
return typeof value == 'number' && value > -1 && value <= MAX_SAFE_INTEGER;
}
|
Checks if `value` is valid array-like length.
@private
@param {*} value The value to check.
@returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
isLength
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function isStrictComparable(value) {
return value === value && (value === 0 ? ((1 / value) > 0) : !isObject(value));
}
|
Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
@private
@param {*} value The value to check.
@returns {boolean} Returns `true` if `value` if suitable for strict
equality comparisons, else `false`.
|
isStrictComparable
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function pickByArray(object, props) {
object = toObject(object);
var index = -1,
length = props.length,
result = {};
while (++index < length) {
var key = props[index];
if (key in object) {
result[key] = object[key];
}
}
return result;
}
|
A specialized version of `_.pick` that picks `object` properties
specified by the `props` array.
@private
@param {Object} object The source object.
@param {string[]} props The property names to pick.
@returns {Object} Returns the new object.
|
pickByArray
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function pickByCallback(object, predicate) {
var result = {};
baseForIn(object, function(value, key, object) {
if (predicate(value, key, object)) {
result[key] = value;
}
});
return result;
}
|
A specialized version of `_.pick` that picks `object` properties `predicate`
returns truthy for.
@private
@param {Object} object The source object.
@param {Function} predicate The function invoked per iteration.
@returns {Object} Returns the new object.
|
pickByCallback
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function reorder(array, indexes) {
var arrLength = array.length,
length = nativeMin(indexes.length, arrLength),
oldArray = baseSlice(array);
while (length--) {
var index = indexes[length];
array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
}
return array;
}
|
Reorder `array` according to the specified indexes where the element at
the first index is assigned as the first element, the element at
the second index is assigned as the second element, and so on.
@private
@param {Array} array The array to reorder.
@param {Array} indexes The arranged array indexes.
@returns {Array} Returns `array`.
|
reorder
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function shimIsPlainObject(value) {
var Ctor,
support = lodash.support;
// exit early for non `Object` objects
if (!(value && typeof value == 'object' &&
toString.call(value) == objectClass && !isHostObject(value)) ||
(!hasOwnProperty.call(value, 'constructor') &&
(Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor))) ||
(!support.argsClass && isArguments(value))) {
return false;
}
// IE < 9 iterates inherited properties before own properties. If the first
// iterated property is an object's own property then there are no inherited
// enumerable properties.
var result;
if (support.ownLast) {
baseForIn(value, function(subValue, key, object) {
result = hasOwnProperty.call(object, key);
return false;
});
return result !== false;
}
// In most environments an object's own properties are iterated before
// its inherited properties. If the last iterated property is an object's
// own property then there are no inherited enumerable properties.
baseForIn(value, function(subValue, key) {
result = key;
});
return typeof result == 'undefined' || hasOwnProperty.call(value, result);
}
|
A fallback implementation of `_.isPlainObject` which checks if `value`
is an object created by the `Object` constructor or has a `[[Prototype]]`
of `null`.
@private
@param {*} value The value to check.
@returns {boolean} Returns `true` if `value` is a plain object, else `false`.
|
shimIsPlainObject
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function shimKeys(object) {
var props = keysIn(object),
propsLength = props.length,
length = propsLength && object.length,
support = lodash.support;
var allowIndexes = typeof length == 'number' && length > 0 &&
(isArray(object) || (support.nonEnumStrings && isString(object)) ||
(support.nonEnumArgs && isArguments(object)));
var index = -1,
result = [];
while (++index < propsLength) {
var key = props[index];
if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
result.push(key);
}
}
return result;
}
|
A fallback implementation of `Object.keys` which creates an array of the
own enumerable property names of `object`.
@private
@param {Object} object The object to inspect.
@returns {Array} Returns the array of property names.
|
shimKeys
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function toIterable(value) {
if (value == null) {
return [];
}
if (!isLength(value.length)) {
return values(value);
}
if (lodash.support.unindexedChars && isString(value)) {
return value.split('');
}
return isObject(value) ? value : Object(value);
}
|
Converts `value` to an array-like object if it is not one.
@private
@param {*} value The value to process.
@returns {Array|Object} Returns the array-like object.
|
toIterable
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function toObject(value) {
if (lodash.support.unindexedChars && isString(value)) {
var index = -1,
length = value.length,
result = Object(value);
while (++index < length) {
result[index] = value.charAt(index);
}
return result;
}
return isObject(value) ? value : Object(value);
}
|
Converts `value` to an object if it is not one.
@private
@param {*} value The value to process.
@returns {Object} Returns the object.
|
toObject
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function chunk(array, size, guard) {
size = (guard || size == null) ? 1 : nativeMax(+size || 1, 1);
var index = 0,
length = array ? array.length : 0,
resIndex = -1,
result = Array(ceil(length / size));
while (index < length) {
result[++resIndex] = slice(array, index, (index += size));
}
return result;
}
|
Creates an array of elements split into groups the length of `size`.
If `collection` can't be split evenly, the final chunk will be the remaining
elements.
@static
@memberOf _
@category Array
@param {Array} array The array to process.
@param {numer} [size=1] The length of each chunk.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {Array} Returns the new array containing chunks.
@example
_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]
|
chunk
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function compact(array) {
var index = -1,
length = array ? array.length : 0,
resIndex = -1,
result = [];
while (++index < length) {
var value = array[index];
if (value) {
result[++resIndex] = value;
}
}
return result;
}
|
Creates an array with all falsey values removed. The values `false`, `null`,
`0`, `""`, `undefined`, and `NaN` are all falsey.
@static
@memberOf _
@category Array
@param {Array} array The array to compact.
@returns {Array} Returns the new array of filtered values.
@example
_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]
|
compact
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function drop(array, n, guard) {
n = (guard || n == null) ? 1 : n;
return slice(array, n < 0 ? 0 : n);
}
|
Creates a slice of `array` with `n` elements dropped from the beginning.
@static
@memberOf _
@type Function
@category Array
@param {Array} array The array to query.
@param {number} [n=1] The number of elements to drop.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {Array} Returns the slice of `array`.
@example
_.drop([1, 2, 3], 1);
// => [2, 3]
_.drop([1, 2, 3], 2);
// => [3]
_.drop([1, 2, 3], 5);
// => []
_.drop([1, 2, 3], 0);
// => [1, 2, 3]
|
drop
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function dropRight(array, n, guard) {
var length = array ? array.length : 0;
n = (guard || n == null) ? 1 : n;
n = length - (n || 0);
return slice(array, 0, n < 0 ? 0 : n);
}
|
Creates a slice of `array` with `n` elements dropped from the end.
@static
@memberOf _
@type Function
@category Array
@param {Array} array The array to query.
@param {number} [n=1] The number of elements to drop.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {Array} Returns the slice of `array`.
@example
_.dropRight([1, 2, 3], 1);
// => [1, 2]
_.dropRight([1, 2, 3], 2);
// => [1]
_.dropRight([1, 2, 3], 5);
// => []
_.dropRight([1, 2, 3], 0);
// => [1, 2, 3]
|
dropRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function dropRightWhile(array, predicate, thisArg) {
var length = array ? array.length : 0;
predicate = getCallback(predicate, thisArg, 3);
while (length-- && predicate(array[length], length, array)) {}
return slice(array, 0, length + 1);
}
|
Creates a slice of `array` excluding elements dropped from the end.
Elements are dropped until `predicate` returns falsey. The predicate is
bound to `thisArg` and invoked with three arguments; (value, index, array).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@type Function
@category Array
@param {Array} array The array to query.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per element.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {Array} Returns the slice of `array`.
@example
_.dropRightWhile([1, 2, 3], function(n) { return n > 1; });
// => [1]
var users = [
{ 'user': 'barney', 'status': 'busy', 'active': false },
{ 'user': 'fred', 'status': 'busy', 'active': true },
{ 'user': 'pebbles', 'status': 'away', 'active': true }
];
// using "_.pluck" callback shorthand
_.pluck(_.dropRightWhile(users, 'active'), 'user');
// => ['barney']
// using "_.where" callback shorthand
_.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user');
// => ['barney', 'fred']
|
dropRightWhile
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function dropWhile(array, predicate, thisArg) {
var index = -1,
length = array ? array.length : 0;
predicate = getCallback(predicate, thisArg, 3);
while (++index < length && predicate(array[index], index, array)) {}
return slice(array, index);
}
|
Creates a slice of `array` excluding elements dropped from the beginning.
Elements are dropped until `predicate` returns falsey. The predicate is
bound to `thisArg` and invoked with three arguments; (value, index, array).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@type Function
@category Array
@param {Array} array The array to query.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per element.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {Array} Returns the slice of `array`.
@example
_.dropWhile([1, 2, 3], function(n) { return n < 3; });
// => [3]
var users = [
{ 'user': 'barney', 'status': 'busy', 'active': true },
{ 'user': 'fred', 'status': 'busy', 'active': false },
{ 'user': 'pebbles', 'status': 'away', 'active': true }
];
// using "_.pluck" callback shorthand
_.pluck(_.dropWhile(users, 'active'), 'user');
// => ['fred', 'pebbles']
// using "_.where" callback shorthand
_.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user');
// => ['pebbles']
|
dropWhile
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function findIndex(array, predicate, thisArg) {
var index = -1,
length = array ? array.length : 0;
predicate = getCallback(predicate, thisArg, 3);
while (++index < length) {
if (predicate(array[index], index, array)) {
return index;
}
}
return -1;
}
|
This method is like `_.find` except that it returns the index of the first
element `predicate` returns truthy for, instead of the element itself.
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@category Array
@param {Array} array The array to search.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {number} Returns the index of the found element, else `-1`.
@example
var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': true },
{ 'user': 'pebbles', 'age': 1, 'active': false }
];
_.findIndex(users, function(chr) { return chr.age < 40; });
// => 0
// using "_.where" callback shorthand
_.findIndex(users, { 'age': 1 });
// => 2
// using "_.pluck" callback shorthand
_.findIndex(users, 'active');
// => 1
|
findIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function findLastIndex(array, predicate, thisArg) {
var length = array ? array.length : 0;
predicate = getCallback(predicate, thisArg, 3);
while (length--) {
if (predicate(array[length], length, array)) {
return length;
}
}
return -1;
}
|
This method is like `_.findIndex` except that it iterates over elements
of `collection` from right to left.
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@category Array
@param {Array} array The array to search.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {number} Returns the index of the found element, else `-1`.
@example
var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false },
{ 'user': 'pebbles', 'age': 1, 'active': false }
];
_.findLastIndex(users, function(chr) { return chr.age < 40; });
// => 2
// using "_.where" callback shorthand
_.findLastIndex(users, { 'age': 40});
// => 1
// using "_.pluck" callback shorthand
_.findLastIndex(users, 'active');
// => 0
|
findLastIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function first(array) {
return array ? array[0] : undefined;
}
|
Gets the first element of `array`.
@static
@memberOf _
@alias head
@category Array
@param {Array} array The array to query.
@returns {*} Returns the first element of `array`.
@example
_.first([1, 2, 3]);
// => 1
_.first([]);
// => undefined
|
first
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function flatten(array, isDeep, guard) {
var length = array ? array.length : 0;
return length ? baseFlatten(array, guard ? false : isDeep) : [];
}
|
Flattens a nested array. If `isDeep` is `true` the array is recursively
flattened, otherwise it is only flattened a single level.
@static
@memberOf _
@category Array
@param {Array} array The array to flatten.
@param {boolean} [isDeep=false] Specify a deep flatten.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {Array} Returns the new flattened array.
@example
_.flatten([1, [2], [3, [[4]]]]);
// => [1, 2, 3, [[4]]];
// using `isDeep`
_.flatten([1, [2], [3, [[4]]]], true);
// => [1, 2, 3, 4];
|
flatten
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function flattenDeep(array) {
var length = array ? array.length : 0;
return length ? baseFlatten(array, true) : [];
}
|
Recursively flattens a nested array.
@static
@memberOf _
@category Array
@param {Array} array The array to recursively flatten.
@returns {Array} Returns the new flattened array.
@example
_.flattenDeep([1, [2], [3, [[4]]]]);
// => [1, 2, 3, 4];
|
flattenDeep
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function initial(array) {
return dropRight(array, 1);
}
|
Gets all but the last element of `array`.
@static
@memberOf _
@category Array
@param {Array} array The array to query.
@returns {Array} Returns the slice of `array`.
@example
_.initial([1, 2, 3]);
// => [1, 2]
|
initial
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function last(array) {
var length = array ? array.length : 0;
return length ? array[length - 1] : undefined;
}
|
Gets the last element of `array`.
@static
@memberOf _
@category Array
@param {Array} array The array to query.
@returns {*} Returns the last element of `array`.
@example
_.last([1, 2, 3]);
// => 3
|
last
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function lastIndexOf(array, value, fromIndex) {
var length = array ? array.length : 0;
if (!length) {
return -1;
}
var index = length;
if (typeof fromIndex == 'number') {
index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
} else if (fromIndex) {
index = sortedLastIndex(array, value) - 1;
var other = array[index];
return (value === value ? value === other : other !== other) ? index : -1;
}
if (value !== value) {
return indexOfNaN(array, index, true);
}
while (index--) {
if (array[index] === value) {
return index;
}
}
return -1;
}
|
This method is like `_.indexOf` except that it iterates over elements of
`array` from right to left.
@static
@memberOf _
@category Array
@param {Array} array The array to search.
@param {*} value The value to search for.
@param {boolean|number} [fromIndex=array.length-1] The index to search from
or `true` to perform a binary search on a sorted array.
@returns {number} Returns the index of the matched value, else `-1`.
@example
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
// => 4
// using `fromIndex`
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
// => 1
// performing a binary search
_.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true);
// => 3
|
lastIndexOf
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function pullAt(array) {
return basePullAt(array || [], baseFlatten(arguments, false, false, 1));
}
|
Removes elements from `array` corresponding to the specified indexes and
returns an array of the removed elements. Indexes may be specified as an
array of indexes or as individual arguments.
**Note:** Unlike `_.at`, this method mutates `array`.
@static
@memberOf _
@category Array
@param {Array} array The array to modify.
@param {...(number|number[])} [indexes] The indexes of elements to remove,
specified as individual indexes or arrays of indexes.
@returns {Array} Returns the new array of removed elements.
@example
var array = [5, 10, 15, 20];
var evens = _.pullAt(array, [1, 3]);
console.log(array);
// => [5, 15]
console.log(evens);
// => [10, 20]
|
pullAt
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function remove(array, predicate, thisArg) {
var index = -1,
length = array ? array.length : 0,
result = [];
predicate = getCallback(predicate, thisArg, 3);
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result.push(value);
splice.call(array, index--, 1);
length--;
}
}
return result;
}
|
Removes all elements from `array` that `predicate` returns truthy for
and returns an array of the removed elements. The predicate is bound to
`thisArg` and invoked with three arguments; (value, index, array).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
**Note:** Unlike `_.filter`, this method mutates `array`.
@static
@memberOf _
@category Array
@param {Array} array The array to modify.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {Array} Returns the new array of removed elements.
@example
var array = [1, 2, 3, 4];
var evens = _.remove(array, function(n) { return n % 2 == 0; });
console.log(array);
// => [1, 3]
console.log(evens);
// => [2, 4]
|
remove
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function rest(array) {
return drop(array, 1);
}
|
Gets all but the first element of `array`.
@static
@memberOf _
@alias tail
@category Array
@param {Array} array The array to query.
@returns {Array} Returns the slice of `array`.
@example
_.rest([1, 2, 3]);
// => [2, 3]
|
rest
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function slice(array, start, end) {
var index = -1,
length = array ? array.length : 0,
endType = typeof end;
if (end && endType != 'number' && isIterateeCall(array, start, end)) {
start = 0;
end = length;
}
start = start == null ? 0 : (+start || 0);
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = (endType == 'undefined' || end > length) ? length : (+end || 0);
if (end < 0) {
end += length;
}
if (end && end == length && !start) {
return baseSlice(array);
}
length = start > end ? 0 : (end - start);
var result = Array(length);
while (++index < length) {
result[index] = array[index + start];
}
return result;
}
|
Creates a slice of `array` from `start` up to, but not including, `end`.
**Note:** This function is used instead of `Array#slice` to support node
lists in IE < 9 and to ensure dense arrays are returned.
@static
@memberOf _
@category Array
@param {Array} array The array to slice.
@param {number} [start=0] The start position.
@param {number} [end=array.length] The end position.
@returns {Array} Returns the slice of `array`.
|
slice
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function sortedIndex(array, value, iteratee, thisArg) {
iteratee = iteratee == null ? identity : getCallback(iteratee, thisArg, 1);
return baseSortedIndex(array, value, iteratee);
}
|
Uses a binary search to determine the lowest index at which a value should
be inserted into a given sorted array in order to maintain the sort order
of the array. If an iteratee function is provided it is invoked for `value`
and each element of `array` to compute their sort ranking. The iteratee
is bound to `thisArg` and invoked with one argument; (value).
If a property name is provided for `iteratee` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `iteratee` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@category Array
@param {Array} array The array to inspect.
@param {*} value The value to evaluate.
@param {Function|Object|string} [iteratee=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {number} Returns the index at which `value` should be inserted
into `array`.
@example
_.sortedIndex([30, 50], 40);
// => 1
_.sortedIndex([4, 4, 5, 5, 6, 6], 5);
// => 2
var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
// using an iteratee function
_.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
return this.data[word];
}, dict);
// => 1
// using "_.pluck" callback shorthand
_.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
// => 1
|
sortedIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function sortedLastIndex(array, value, iteratee, thisArg) {
iteratee = iteratee == null ? identity : getCallback(iteratee, thisArg, 1);
return baseSortedIndex(array, value, iteratee, true);
}
|
This method is like `_.sortedIndex` except that it returns the highest
index at which a value should be inserted into a given sorted array in
order to maintain the sort order of the array.
@static
@memberOf _
@category Array
@param {Array} array The array to inspect.
@param {*} value The value to evaluate.
@param {Function|Object|string} [iteratee=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {number} Returns the index at which `value` should be inserted
into `array`.
@example
_.sortedLastIndex([4, 4, 5, 5, 6, 6], 5);
// => 4
|
sortedLastIndex
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function take(array, n, guard) {
n = (guard || n == null) ? 1 : n;
return slice(array, 0, n < 0 ? 0 : n);
}
|
Creates a slice of `array` with `n` elements taken from the beginning.
@static
@memberOf _
@type Function
@category Array
@param {Array} array The array to query.
@param {number} [n=1] The number of elements to take.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {Array} Returns the slice of `array`.
@example
_.take([1, 2, 3], 1);
// => [1]
_.take([1, 2, 3], 2);
// => [1, 2]
_.take([1, 2, 3], 5);
// => [1, 2, 3]
_.take([1, 2, 3], 0);
// => []
|
take
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function takeRight(array, n, guard) {
var length = array ? array.length : 0;
n = (guard || n == null) ? 1 : n;
n = length - (n || 0);
return slice(array, n < 0 ? 0 : n);
}
|
Creates a slice of `array` with `n` elements taken from the end.
@static
@memberOf _
@type Function
@category Array
@param {Array} array The array to query.
@param {number} [n=1] The number of elements to take.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {Array} Returns the slice of `array`.
@example
_.takeRight([1, 2, 3], 1);
// => [3]
_.takeRight([1, 2, 3], 2);
// => [2, 3]
_.takeRight([1, 2, 3], 5);
// => [1, 2, 3]
_.takeRight([1, 2, 3], 0);
// => []
|
takeRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function takeRightWhile(array, predicate, thisArg) {
var length = array ? array.length : 0;
predicate = getCallback(predicate, thisArg, 3);
while (length-- && predicate(array[length], length, array)) {}
return slice(array, length + 1);
}
|
Creates a slice of `array` with elements taken from the end. Elements are
taken until `predicate` returns falsey. The predicate is bound to `thisArg`
and invoked with three arguments; (value, index, array).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@type Function
@category Array
@param {Array} array The array to query.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per element.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {Array} Returns the slice of `array`.
@example
_.takeRightWhile([1, 2, 3], function(n) { return n > 1; });
// => [2, 3]
var users = [
{ 'user': 'barney', 'status': 'busy', 'active': false },
{ 'user': 'fred', 'status': 'busy', 'active': true },
{ 'user': 'pebbles', 'status': 'away', 'active': true }
];
// using "_.pluck" callback shorthand
_.pluck(_.takeRightWhile(users, 'active'), 'user');
// => ['fred', 'pebbles']
// using "_.where" callback shorthand
_.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user');
// => ['pebbles']
|
takeRightWhile
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function takeWhile(array, predicate, thisArg) {
var index = -1,
length = array ? array.length : 0;
predicate = getCallback(predicate, thisArg, 3);
while (++index < length && predicate(array[index], index, array)) {}
return slice(array, 0, index);
}
|
Creates a slice of `array` with elements taken from the beginning. Elements
are taken until `predicate` returns falsey. The predicate is bound to
`thisArg` and invoked with three arguments; (value, index, array).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@type Function
@category Array
@param {Array} array The array to query.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per element.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {Array} Returns the slice of `array`.
@example
_.takeWhile([1, 2, 3], function(n) { return n < 3; });
// => [1, 2]
var users = [
{ 'user': 'barney', 'status': 'busy', 'active': true },
{ 'user': 'fred', 'status': 'busy', 'active': false },
{ 'user': 'pebbles', 'status': 'away', 'active': true }
];
// using "_.pluck" callback shorthand
_.pluck(_.takeWhile(users, 'active'), 'user');
// => ['barney']
// using "_.where" callback shorthand
_.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user');
// => ['barney', 'fred']
|
takeWhile
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function unzip(array) {
var index = -1,
length = isObject(length = max(array, 'length')) && length.length || 0,
result = Array(length);
while (++index < length) {
result[index] = pluck(array, index);
}
return result;
}
|
This method is like `_.zip` except that it accepts an array of grouped
elements and creates an array regrouping the elements to their pre `_.zip`
configuration.
@static
@memberOf _
@category Array
@param {Array} array The array of grouped elements to process.
@returns {Array} Returns the new array of regrouped elements.
@example
var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
// => [['fred', 30, true], ['barney', 40, false]]
_.unzip(zipped);
// => [['fred', 'barney'], [30, 40], [true, false]]
|
unzip
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function xor() {
var index = -1,
length = arguments.length;
while (++index < length) {
var array = arguments[index];
if (isArray(array) || isArguments(array)) {
var result = result
? baseDifference(result, array).concat(baseDifference(array, result))
: array;
}
}
return result ? baseUniq(result) : [];
}
|
Creates an array that is the symmetric difference of the provided arrays.
See [Wikipedia](http://en.wikipedia.org/wiki/Symmetric_difference) for
more details.
@static
@memberOf _
@category Array
@param {...Array} [arrays] The arrays to inspect.
@returns {Array} Returns the new array of values.
@example
_.xor([1, 2, 3], [5, 2, 1, 4]);
// => [3, 5, 4]
_.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]);
// => [1, 4, 5]
|
xor
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function zip() {
var length = arguments.length,
array = Array(length);
while (length--) {
array[length] = arguments[length];
}
return unzip(array);
}
|
Creates an array of grouped elements, the first of which contains the first
elements of the given arrays, the second of which contains the second elements
of the given arrays, and so on.
@static
@memberOf _
@category Array
@param {...Array} [arrays] The arrays to process.
@returns {Array} Returns the new array of grouped elements.
@example
_.zip(['fred', 'barney'], [30, 40], [true, false]);
// => [['fred', 30, true], ['barney', 40, false]]
|
zip
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function zipObject(props, values) {
var index = -1,
length = props ? props.length : 0,
result = {};
if (!values && length && !isArray(props[0])) {
values = [];
}
while (++index < length) {
var key = props[index];
if (values) {
result[key] = values[index];
} else if (key) {
result[key[0]] = key[1];
}
}
return result;
}
|
Creates an object composed from arrays of property names and values. Provide
either a single two dimensional array, e.g. `[[key1, value1], [key2, value2]]`
or two arrays, one of property names and one of corresponding values.
@static
@memberOf _
@alias object
@category Array
@param {Array} props The property names.
@param {Array} [values=[]] The property values.
@returns {Object} Returns the new object.
@example
_.zipObject(['fred', 'barney'], [30, 40]);
// => { 'fred': 30, 'barney': 40 }
|
zipObject
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function chain(value) {
var result = lodash(value);
result.__chain__ = true;
return result;
}
|
Creates a `lodash` object that wraps `value` with explicit method
chaining enabled.
@static
@memberOf _
@category Chain
@param {*} value The value to wrap.
@returns {Object} Returns the new `lodash` object.
@example
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'pebbles', 'age': 1 }
];
var youngest = _.chain(users)
.sortBy('age')
.map(function(chr) { return chr.user + ' is ' + chr.age; })
.first()
.value();
// => 'pebbles is 1'
|
chain
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function tap(value, interceptor, thisArg) {
interceptor.call(thisArg, value);
return value;
}
|
This method invokes `interceptor` and returns `value`. The interceptor is
bound to `thisArg` and invoked with one argument; (value). The purpose of
this method is to "tap into" a method chain in order to perform operations
on intermediate results within the chain.
@static
@memberOf _
@category Chain
@param {*} value The value to provide to `interceptor`.
@param {Function} interceptor The function to invoke.
@param {*} [thisArg] The `this` binding of `interceptor`.
@returns {*} Returns `value`.
@example
_([1, 2, 3])
.tap(function(array) { array.pop(); })
.reverse()
.value();
// => [2, 1]
|
tap
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function thru(value, interceptor, thisArg) {
return interceptor.call(thisArg, value);
}
|
This method is like `_.tap` except that it returns the result of `interceptor`.
@static
@memberOf _
@category Chain
@param {*} value The value to provide to `interceptor`.
@param {Function} interceptor The function to invoke.
@param {*} [thisArg] The `this` binding of `interceptor`.
@returns {*} Returns the result of `interceptor`.
@example
_([1, 2, 3])
.last()
.thru(function(value) { return [value]; })
.value();
// => [3]
|
thru
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function wrapperChain() {
return chain(this);
}
|
Enables explicit method chaining on the wrapper object.
@name chain
@memberOf _
@category Chain
@returns {*} Returns the `lodash` object.
@example
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];
// without explicit chaining
_(users).first();
// => { 'user': 'barney', 'age': 36 }
// with explicit chaining
_(users).chain()
.first()
.pick('age')
.value();
// => { 'age': 36 }
|
wrapperChain
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function wrapperReverse() {
return this.thru(function(value) {
return value.reverse();
});
}
|
Reverses the wrapped array so the first element becomes the last, the
second element becomes the second to last, and so on.
**Note:** This method mutates the wrapped array.
@name chain
@memberOf _
@category Chain
@returns {Object} Returns the new reversed `lodash` object.
@example
var array = [1, 2, 3];
_(array).reverse().value()
// => [3, 2, 1]
console.log(array);
// => [3, 2, 1]
|
wrapperReverse
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function wrapperToString() {
return String(this.value());
}
|
Produces the result of coercing the unwrapped value to a string.
@name toString
@memberOf _
@category Chain
@returns {string} Returns the coerced string value.
@example
_([1, 2, 3]).toString();
// => '1,2,3'
|
wrapperToString
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function wrapperValueOf() {
var result = this.__wrapped__;
if (result instanceof LazyWrapper) {
result = result.value();
}
var index = -1,
queue = this.__queue__,
length = queue.length;
while (++index < length) {
var args = [result],
data = queue[index],
object = data.object;
push.apply(args, data.args);
result = object[data.name].apply(object, args);
}
return result;
}
|
Extracts the unwrapped value from its wrapper.
@name valueOf
@memberOf _
@alias toJSON, value
@category Chain
@returns {*} Returns the unwrapped value.
@example
_([1, 2, 3]).valueOf();
// => [1, 2, 3]
|
wrapperValueOf
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function at(collection) {
if (!collection || isLength(collection.length)) {
collection = toIterable(collection);
}
return baseAt(collection, baseFlatten(arguments, false, false, 1));
}
|
Creates an array of elements corresponding to the specified keys, or indexes,
of the collection. Keys may be specified as individual arguments or as arrays
of keys.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {...(number|number[]|string|string[])} [props] The property names
or indexes of elements to pick, specified individually or in arrays.
@returns {Array} Returns the new array of picked elements.
@example
_.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
// => ['a', 'c', 'e']
_.at(['fred', 'barney', 'pebbles'], 0, 2);
// => ['fred', 'pebbles']
|
at
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function every(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayEvery : baseEvery;
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
predicate = getCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
|
Checks if `predicate` returns truthy for **all** elements of `collection`.
The predicate is bound to `thisArg` and invoked with three arguments;
(value, index|key, collection).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@alias all
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {boolean} Returns `true` if all elements pass the predicate check,
else `false`.
@example
_.every([true, 1, null, 'yes']);
// => false
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];
// using "_.pluck" callback shorthand
_.every(users, 'age');
// => true
// using "_.where" callback shorthand
_.every(users, { 'age': 36 });
// => false
|
every
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function filter(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayFilter : baseFilter;
predicate = getCallback(predicate, thisArg, 3);
return func(collection, predicate);
}
|
Iterates over elements of `collection`, returning an array of all elements
`predicate` returns truthy for. The predicate is bound to `thisArg` and
invoked with three arguments; (value, index|key, collection).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@alias select
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {Array} Returns the new filtered array.
@example
var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; });
// => [2, 4]
var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': true }
];
// using "_.pluck" callback shorthand
_.pluck(_.filter(users, 'active'), 'user');
// => ['fred']
// using "_.where" callback shorthand
_.pluck(_.filter(users, { 'age': 36 }), 'user');
// => ['barney']
|
filter
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function find(collection, predicate, thisArg) {
if (isArray(collection)) {
var index = findIndex(collection, predicate, thisArg);
return index > -1 ? collection[index] : undefined;
}
predicate = getCallback(predicate, thisArg, 3);
return baseFind(collection, predicate, baseEach);
}
|
Iterates over elements of `collection`, returning the first element
`predicate` returns truthy for. The predicate is bound to `thisArg` and
invoked with three arguments; (value, index|key, collection).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@alias detect
@category Collection
@param {Array|Object|string} collection The collection to search.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {*} Returns the matched element, else `undefined`.
@example
var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': true },
{ 'user': 'pebbles', 'age': 1, 'active': false }
];
_.result(_.find(users, function(chr) { return chr.age < 40; }), 'user');
// => 'barney'
// using "_.where" callback shorthand
_.result(_.find(users, { 'age': 1 }), 'user');
// => 'pebbles'
// using "_.pluck" callback shorthand
_.result(_.find(users, 'active'), 'user');
// => 'fred'
|
find
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function findLast(collection, predicate, thisArg) {
predicate = getCallback(predicate, thisArg, 3);
return baseFind(collection, predicate, baseEachRight);
}
|
This method is like `_.find` except that it iterates over elements of
`collection` from right to left.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to search.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {*} Returns the matched element, else `undefined`.
@example
_.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; });
// => 3
|
findLast
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function findWhere(collection, source) {
return find(collection, matches(source));
}
|
Performs a deep comparison between each element in `collection` and the
source object, returning the first element that has equivalent property
values.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to search.
@param {Object} source The object of property values to match.
@returns {*} Returns the matched element, else `undefined`.
@example
var users = [
{ 'user': 'barney', 'age': 36, 'status': 'busy' },
{ 'user': 'fred', 'age': 40, 'status': 'busy' }
];
_.findWhere(users, { 'status': 'busy' });
// => { 'user': 'barney', 'age': 36, 'status': 'busy' }
_.findWhere(users, { 'age': 40 });
// => { 'user': 'fred', 'age': 40, 'status': 'busy' }
|
findWhere
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function forEach(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
? arrayEach(collection, iteratee)
: baseEach(collection, baseCallback(iteratee, thisArg, 3));
}
|
Iterates over elements of `collection` invoking `iteratee` for each element.
The `iteratee` is bound to `thisArg` and invoked with three arguments;
(value, index|key, collection). Iterator functions may exit iteration early
by explicitly returning `false`.
**Note:** As with other "Collections" methods, objects with a `length` property
are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
may be used for object iteration.
@static
@memberOf _
@alias each
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} [iteratee=_.identity] The function invoked per iteration.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {Array|Object|string} Returns `collection`.
@example
_([1, 2, 3]).forEach(function(n) { console.log(n); });
// => logs each value from left to right and returns the array
_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, key); });
// => logs each value-key pair and returns the object (iteration order is not guaranteed)
|
forEach
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function forEachRight(collection, iteratee, thisArg) {
return (typeof iteratee == 'function' && typeof thisArg == 'undefined' && isArray(collection))
? arrayEachRight(collection, iteratee)
: baseEachRight(collection, baseCallback(iteratee, thisArg, 3));
}
|
This method is like `_.forEach` except that it iterates over elements of
`collection` from right to left.
@static
@memberOf _
@alias eachRight
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} [iteratee=_.identity] The function invoked per iteration.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {Array|Object|string} Returns `collection`.
@example
_([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(',');
// => logs each value from right to left and returns the array
|
forEachRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function invoke(collection, methodName) {
return baseInvoke(collection, methodName, slice(arguments, 2));
}
|
Invokes the method named by `methodName` on each element in the collection,
returning an array of the results of each invoked method. Any additional
arguments are provided to each invoked method. If `methodName` is a function
it is invoked for, and `this` bound to, each element in the collection.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|string} methodName The name of the method to invoke or
the function invoked per iteration.
@param {...*} [args] The arguments to invoke the method with.
@returns {Array} Returns the array of results.
@example
_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
// => [[1, 5, 7], [1, 2, 3]]
_.invoke([123, 456], String.prototype.split, '');
// => [['1', '2', '3'], ['4', '5', '6']]
|
invoke
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function map(collection, iteratee, thisArg) {
iteratee = getCallback(iteratee, thisArg, 3);
var func = isArray(collection) ? arrayMap : baseMap;
return func(collection, iteratee);
}
|
Creates an array of values by running each element in the collection through
`iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
arguments; (value, index|key, collection).
If a property name is provided for `iteratee` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `iteratee` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@alias collect
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|Object|string} [iteratee=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {Array} Returns the new mapped array.
@example
_.map([1, 2, 3], function(n) { return n * 3; });
// => [3, 6, 9]
_.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; });
// => [3, 6, 9] (iteration order is not guaranteed)
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];
// using "_.pluck" callback shorthand
_.map(users, 'user');
// => ['barney', 'fred']
|
map
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function max(collection, iteratee, thisArg) {
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null;
}
var noIteratee = iteratee == null,
isArr = noIteratee && isArray(collection),
isStr = !isArr && isString(collection);
if (noIteratee && !isStr) {
return arrayMax(isArr ? collection : toIterable(collection));
}
var computed = NEGATIVE_INFINITY,
result = computed;
iteratee = (noIteratee && isStr)
? charAtCallback
: getCallback(iteratee, thisArg, 3);
baseEach(collection, function(value, index, collection) {
var current = iteratee(value, index, collection);
if (current > computed || (current === NEGATIVE_INFINITY && current === result)) {
computed = current;
result = value;
}
});
return result;
}
|
Retrieves the maximum value of `collection`. If the collection is empty
or falsey `-Infinity` is returned. If an iteratee function is provided it
is invoked for each value in the collection to generate the criterion by
which the value is ranked. The `iteratee` is bound to `thisArg` and invoked
with three arguments; (value, index, collection).
If a property name is provided for `iteratee` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `iteratee` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|Object|string} [iteratee] The function invoked per iteration.
If a property name or object is provided it is used to create a "_.pluck"
or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {*} Returns the maximum value.
@example
_.max([4, 2, 8, 6]);
// => 8
_.max([]);
// => -Infinity
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];
_.max(users, function(chr) { return chr.age; });
// => { 'user': 'fred', 'age': 40 };
// using "_.pluck" callback shorthand
_.max(users, 'age');
// => { 'user': 'fred', 'age': 40 };
|
max
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function min(collection, iteratee, thisArg) {
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null;
}
var noIteratee = iteratee == null,
isArr = noIteratee && isArray(collection),
isStr = !isArr && isString(collection);
if (noIteratee && !isStr) {
return arrayMin(isArr ? collection : toIterable(collection));
}
var computed = POSITIVE_INFINITY,
result = computed;
iteratee = (noIteratee && isStr)
? charAtCallback
: getCallback(iteratee, thisArg, 3);
baseEach(collection, function(value, index, collection) {
var current = iteratee(value, index, collection);
if (current < computed || (current === POSITIVE_INFINITY && current === result)) {
computed = current;
result = value;
}
});
return result;
}
|
Retrieves the minimum value of `collection`. If the collection is empty
or falsey `Infinity` is returned. If an iteratee function is provided it
is invoked for each value in the collection to generate the criterion by
which the value is ranked. The `iteratee` is bound to `thisArg` and invoked
with three arguments; (value, index, collection).
If a property name is provided for `iteratee` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `iteratee` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|Object|string} [iteratee] The function invoked per iteration.
If a property name or object is provided it is used to create a "_.pluck"
or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {*} Returns the minimum value.
@example
_.min([4, 2, 8, 6]);
// => 2
_.min([]);
// => Infinity
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];
_.min(users, function(chr) { return chr.age; });
// => { 'user': 'barney', 'age': 36 };
// using "_.pluck" callback shorthand
_.min(users, 'age');
// => { 'user': 'barney', 'age': 36 };
|
min
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function pluck(collection, key) {
return map(collection, property(key));
}
|
Retrieves the value of a specified property from all elements in the collection.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {string} key The name of the property to pluck.
@returns {Array} Returns the property values.
@example
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];
_.pluck(users, 'user');
// => ['barney', 'fred']
var userIndex = _.indexBy(users, 'user');
_.pluck(userIndex, 'age');
// => [36, 40] (iteration order is not guaranteed)
|
pluck
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function reduce(collection, iteratee, accumulator, thisArg) {
var func = isArray(collection) ? arrayReduce : baseReduce;
return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEach);
}
|
Reduces a collection to a value which is the accumulated result of running
each element in the collection through `iteratee`, where each successive
invocation is supplied the return value of the previous. If `accumulator`
is not provided the first element of the collection is used as the initial
value. The `iteratee` is bound to `thisArg`and invoked with four arguments;
(accumulator, value, index|key, collection).
@static
@memberOf _
@alias foldl, inject
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} [iteratee=_.identity] The function invoked per iteration.
@param {*} [accumulator] The initial value.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {*} Returns the accumulated value.
@example
var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; });
// => 6
var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) {
result[key] = n * 3;
return result;
}, {});
// => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed)
|
reduce
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function reduceRight(collection, iteratee, accumulator, thisArg) {
var func = isArray(collection) ? arrayReduceRight : baseReduce;
return func(collection, getCallback(iteratee, thisArg, 4), accumulator, arguments.length < 3, baseEachRight);
}
|
This method is like `_.reduce` except that it iterates over elements of
`collection` from right to left.
@static
@memberOf _
@alias foldr
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function} [iteratee=_.identity] The function invoked per iteration.
@param {*} [accumulator] The initial value.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {*} Returns the accumulated value.
@example
var array = [[0, 1], [2, 3], [4, 5]];
_.reduceRight(array, function(flattened, other) { return flattened.concat(other); }, []);
// => [4, 5, 2, 3, 0, 1]
|
reduceRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function reject(collection, predicate, thisArg) {
var func = isArray(collection) ? arrayFilter : baseFilter;
predicate = getCallback(predicate, thisArg, 3);
return func(collection, function(value, index, collection) {
return !predicate(value, index, collection);
});
}
|
The opposite of `_.filter`; this method returns the elements of `collection`
that `predicate` does **not** return truthy for.
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {Array} Returns the new filtered array.
@example
var odds = _.reject([1, 2, 3, 4], function(n) { return n % 2 == 0; });
// => [1, 3]
var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': true }
];
// using "_.pluck" callback shorthand
_.pluck(_.reject(users, 'active'), 'user');
// => ['barney']
// using "_.where" callback shorthand
_.pluck(_.reject(users, { 'age': 36 }), 'user');
// => ['fred']
|
reject
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function sample(collection, n, guard) {
if (guard || n == null) {
collection = toIterable(collection);
var length = collection.length;
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
}
var result = shuffle(collection);
result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
return result;
}
|
Retrieves a random element or `n` random elements from a collection.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to sample.
@param {number} [n] The number of elements to sample.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {*} Returns the random sample(s).
@example
_.sample([1, 2, 3, 4]);
// => 2
_.sample([1, 2, 3, 4], 2);
// => [3, 1]
|
sample
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function shuffle(collection) {
collection = toIterable(collection);
var index = -1,
length = collection.length,
result = Array(length);
while (++index < length) {
var rand = baseRandom(0, index);
if (index != rand) {
result[index] = result[rand];
}
result[rand] = collection[index];
}
return result;
}
|
Creates an array of shuffled values, using a version of the Fisher-Yates
shuffle. See [Wikipedia](http://en.wikipedia.org/wiki/Fisher-Yates_shuffle)
for more details.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to shuffle.
@returns {Array} Returns the new shuffled array.
@example
_.shuffle([1, 2, 3, 4]);
// => [4, 1, 3, 2]
|
shuffle
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function size(collection) {
var length = collection ? collection.length : 0;
return isLength(length) ? length : keys(collection).length;
}
|
Gets the size of the collection by returning `collection.length` for
array-like values or the number of own enumerable properties for objects.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to inspect.
@returns {number} Returns `collection.length` or number of own enumerable properties.
@example
_.size([1, 2]);
// => 2
_.size({ 'one': 1, 'two': 2, 'three': 3 });
// => 3
_.size('pebbles');
// => 7
|
size
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function some(collection, predicate, thisArg) {
var func = isArray(collection) ? arraySome : baseSome;
if (typeof predicate != 'function' || typeof thisArg != 'undefined') {
predicate = getCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
|
Checks if `predicate` returns truthy for **any** element of `collection`.
The function returns as soon as it finds a passing value and does not iterate
over the entire collection. The predicate is bound to `thisArg` and invoked
with three arguments; (value, index|key, collection).
If a property name is provided for `predicate` the created "_.pluck" style
callback returns the property value of the given element.
If an object is provided for `predicate` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@alias any
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Function|Object|string} [predicate=_.identity] The function invoked
per iteration. If a property name or object is provided it is used to
create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `predicate`.
@returns {boolean} Returns `true` if any element passes the predicate check,
else `false`.
@example
_.some([null, 0, 'yes', false], Boolean);
// => true
var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': true }
];
// using "_.pluck" callback shorthand
_.some(users, 'active');
// => true
// using "_.where" callback shorthand
_.some(users, { 'age': 1 });
// => false
|
some
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function sortBy(collection, iteratee, thisArg) {
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
iteratee = null;
}
var index = -1,
length = collection ? collection.length : 0,
multi = iteratee && isArray(iteratee),
result = [];
if (isLength(length)) {
result.length = length;
}
if (!multi) {
iteratee = getCallback(iteratee, thisArg, 3);
}
baseEach(collection, function(value, key, collection) {
if (multi) {
var length = iteratee.length,
criteria = Array(length);
while (length--) {
criteria[length] = value == null ? undefined : value[iteratee[length]];
}
} else {
criteria = iteratee(value, key, collection);
}
result[++index] = { 'criteria': criteria, 'index': index, 'value': value };
});
length = result.length;
result.sort(multi ? compareMultipleAscending : compareAscending);
while (length--) {
result[length] = result[length].value;
}
return result;
}
|
Creates an array of elements, sorted in ascending order by the results of
running each element in a collection through `iteratee`. This method performs
a stable sort, that is, it preserves the original sort order of equal elements.
The `iteratee` is bound to `thisArg` and invoked with three arguments;
(value, index|key, collection).
If a property name is provided for `iteratee` the created "_.pluck" style
callback returns the property value of the given element.
If an array of property names is provided for `iteratee` the collection
is sorted by each property value.
If an object is provided for `iteratee` the created "_.where" style callback
returns `true` for elements that have the properties of the given object,
else `false`.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to iterate over.
@param {Array|Function|Object|string} [iteratee=_.identity] The function
invoked per iteration. If property name(s) or an object is provided it
is used to create a "_.pluck" or "_.where" style callback respectively.
@param {*} [thisArg] The `this` binding of `iteratee`.
@returns {Array} Returns the new sorted array.
@example
_.sortBy([1, 2, 3], function(n) { return Math.sin(n); });
// => [3, 1, 2]
_.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math);
// => [3, 1, 2]
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 26 },
{ 'user': 'fred', 'age': 30 }
];
// using "_.pluck" callback shorthand
_.map(_.sortBy(users, 'age'), _.values);
// => [['barney', 26], ['fred', 30], ['barney', 36], ['fred', 40]]
// sorting by multiple properties
_.map(_.sortBy(users, ['user', 'age']), _.values);
// = > [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]]
|
sortBy
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function toArray(collection) {
var length = collection ? collection.length : 0;
if (isLength(length)) {
return (lodash.support.unindexedChars && isString(collection))
? collection.split('')
: baseSlice(collection);
}
return values(collection);
}
|
Converts `collection` to an array.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to convert.
@returns {Array} Returns the new converted array.
@example
(function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
// => [2, 3, 4]
|
toArray
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function where(collection, source) {
return filter(collection, matches(source));
}
|
Performs a deep comparison between each element in `collection` and the
source object, returning an array of all elements that have equivalent
property values.
@static
@memberOf _
@category Collection
@param {Array|Object|string} collection The collection to search.
@param {Object} source The object of property values to match.
@returns {Array} Returns the new filtered array.
@example
var users = [
{ 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] },
{ 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] }
];
_.pluck(_.where(users, { 'age': 36 }), 'user');
// => ['barney']
_.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
// => ['fred']
_.pluck(_.where(users, { 'status': 'busy' }), 'user');
// => ['barney', 'fred']
|
where
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function after(n, func) {
if (!isFunction(func)) {
if (isFunction(n)) {
var temp = n;
n = func;
func = temp;
} else {
throw new TypeError(FUNC_ERROR_TEXT);
}
}
n = nativeIsFinite(n = +n) ? n : 0;
return function() {
if (--n < 1) {
return func.apply(this, arguments);
}
};
}
|
The opposite of `_.before`; this method creates a function that invokes
`func` only after it is called `n` times.
@static
@memberOf _
@category Function
@param {number} n The number of calls before `func` is invoked.
@param {Function} func The function to restrict.
@returns {Function} Returns the new restricted function.
@example
var saves = ['profile', 'settings'];
var done = _.after(saves.length, function() {
console.log('done saving!');
});
_.forEach(saves, function(type) {
asyncSave({ 'type': type, 'complete': done });
});
// => logs 'done saving!' after the two async saves have completed
|
after
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function before(n, func) {
var result;
if (!isFunction(func)) {
if (isFunction(n)) {
var temp = n;
n = func;
func = temp;
} else {
throw new TypeError(FUNC_ERROR_TEXT);
}
}
return function() {
if (--n > 0) {
result = func.apply(this, arguments);
} else {
func = null;
}
return result;
};
}
|
Creates a function that invokes `func`, with the `this` binding and arguments
of the created function, while it is called less than `n` times. Subsequent
calls to the created function return the result of the last `func` invocation.
@static
@memberOf _
@category Function
@param {number} n The number of calls at which `func` is no longer invoked.
@param {Function} func The function to restrict.
@returns {Function} Returns the new restricted function.
@example
jQuery('#add').on('click', _.before(5, addContactToList));
// => allows adding up to 4 contacts to the list
|
before
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function bind(func, thisArg) {
var bitmask = BIND_FLAG;
if (arguments.length > 2) {
var partials = slice(arguments, 2),
holders = replaceHolders(partials, bind.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(func, bitmask, thisArg, partials, holders);
}
|
Creates a function that invokes `func` with the `this` binding of `thisArg`
and prepends any additional `bind` arguments to those provided to the bound
function.
**Note:** Unlike native `Function#bind` this method does not set the `length`
property of bound functions.
@static
@memberOf _
@category Function
@param {Function} func The function to bind.
@param {*} [thisArg] The `this` binding of `func`.
@param {...*} [args] The arguments to be partially applied.
@returns {Function} Returns the new bound function.
@example
var func = function(greeting) {
return greeting + ' ' + this.user;
};
func = _.bind(func, { 'user': 'fred' }, 'hi');
func();
// => 'hi fred'
|
bind
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function bindAll(object) {
return baseBindAll(object,
arguments.length > 1
? baseFlatten(arguments, false, false, 1)
: functions(object)
);
}
|
Binds methods of an object to the object itself, overwriting the existing
method. Method names may be specified as individual arguments or as arrays
of method names. If no method names are provided all enumerable function
properties, own and inherited, of `object` are bound.
**Note:** This method does not set the `length` property of bound functions.
@static
@memberOf _
@category Function
@param {Object} object The object to bind and assign the bound methods to.
@param {...(string|string[])} [methodNames] The object method names to bind,
specified as individual method names or arrays of method names.
@returns {Object} Returns `object`.
@example
var view = {
'label': 'docs',
'onClick': function() { console.log('clicked ' + this.label); }
};
_.bindAll(view);
jQuery('#docs').on('click', view.onClick);
// => logs 'clicked docs' when the element is clicked
|
bindAll
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function bindKey(object, key) {
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
if (arguments.length > 2) {
var partials = slice(arguments, 2),
holders = replaceHolders(partials, bindKey.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(key, bitmask, object, partials, holders);
}
|
Creates a function that invokes the method at `object[key]` and prepends
any additional `bindKey` arguments to those provided to the bound function.
This method differs from `_.bind` by allowing bound functions to reference
methods that may be redefined or don't yet exist.
See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definition-pattern)
for more details.
@static
@memberOf _
@category Function
@param {Object} object The object the method belongs to.
@param {string} key The key of the method.
@param {...*} [args] The arguments to be partially applied.
@returns {Function} Returns the new bound function.
@example
var object = {
'user': 'fred',
'greet': function(greeting) {
return greeting + ' ' + this.user;
}
};
var func = _.bindKey(object, 'greet', 'hi');
func();
// => 'hi fred'
object.greet = function(greeting) {
return greeting + 'ya ' + this.user + '!';
};
func();
// => 'hiya fred!'
|
bindKey
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function curry(func, arity, guard) {
var result = createWrapper(func, CURRY_FLAG, null, null, null, null, guard ? null : arity);
result.placeholder = curry.placeholder;
return result;
}
|
Creates a function that accepts one or more arguments of `func` that when
called either invokes `func` returning its result, if all `func` arguments
have been provided, or returns a function that accepts one or more of the
remaining `func` arguments, and so on. The arity of `func` can be specified
if `func.length` is not sufficient.
**Note:** This method does not set the `length` property of curried functions.
@static
@memberOf _
@category Function
@param {Function} func The function to curry.
@param {number} [arity=func.length] The arity of `func`.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {Function} Returns the new curried function.
@example
var curried = _.curry(function(a, b, c) {
return [a, b, c];
});
curried(1)(2)(3);
// => [1, 2, 3]
curried(1, 2)(3);
// => [1, 2, 3]
curried(1, 2, 3);
// => [1, 2, 3]
|
curry
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function curryRight(func, arity, guard) {
var result = createWrapper(func, CURRY_RIGHT_FLAG, null, null, null, null, guard ? null : arity);
result.placeholder = curryRight.placeholder;
return result;
}
|
This method is like `_.curry` except that arguments are applied to `func`
in the manner of `_.partialRight` instead of `_.partial`.
**Note:** This method does not set the `length` property of curried functions.
@static
@memberOf _
@category Function
@param {Function} func The function to curry.
@param {number} [arity=func.length] The arity of `func`.
@param- {Object} [guard] Enables use as a callback for functions like `_.map`.
@returns {Function} Returns the new curried function.
@example
var curried = _.curryRight(function(a, b, c) {
return [a, b, c];
});
curried(3)(2)(1);
// => [1, 2, 3]
curried(2, 3)(1);
// => [1, 2, 3]
curried(1, 2, 3);
// => [1, 2, 3]
|
curryRight
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function debounce(func, wait, options) {
var args,
maxTimeoutId,
result,
stamp,
thisArg,
timeoutId,
trailingCall,
lastCalled = 0,
maxWait = false,
trailing = true;
if (!isFunction(func)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
wait = wait < 0 ? 0 : wait;
if (options === true) {
var leading = true;
trailing = false;
} else if (isObject(options)) {
leading = options.leading;
maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
trailing = 'trailing' in options ? options.trailing : trailing;
}
function cancel() {
if (timeoutId) {
clearTimeout(timeoutId);
}
if (maxTimeoutId) {
clearTimeout(maxTimeoutId);
}
maxTimeoutId = timeoutId = trailingCall = undefined;
}
function delayed() {
var remaining = wait - (now() - stamp);
if (remaining <= 0 || remaining > wait) {
if (maxTimeoutId) {
clearTimeout(maxTimeoutId);
}
var isCalled = trailingCall;
maxTimeoutId = timeoutId = trailingCall = undefined;
if (isCalled) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
}
} else {
timeoutId = setTimeout(delayed, remaining);
}
}
function maxDelayed() {
if (timeoutId) {
clearTimeout(timeoutId);
}
maxTimeoutId = timeoutId = trailingCall = undefined;
if (trailing || (maxWait !== wait)) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
}
}
function debounced() {
args = arguments;
stamp = now();
thisArg = this;
trailingCall = trailing && (timeoutId || !leading);
if (maxWait === false) {
var leadingCall = leading && !timeoutId;
} else {
if (!maxTimeoutId && !leading) {
lastCalled = stamp;
}
var remaining = maxWait - (stamp - lastCalled),
isCalled = remaining <= 0 || remaining > maxWait;
if (isCalled) {
if (maxTimeoutId) {
maxTimeoutId = clearTimeout(maxTimeoutId);
}
lastCalled = stamp;
result = func.apply(thisArg, args);
}
else if (!maxTimeoutId) {
maxTimeoutId = setTimeout(maxDelayed, remaining);
}
}
if (isCalled && timeoutId) {
timeoutId = clearTimeout(timeoutId);
}
else if (!timeoutId && wait !== maxWait) {
timeoutId = setTimeout(delayed, wait);
}
if (leadingCall) {
isCalled = true;
result = func.apply(thisArg, args);
}
if (isCalled && !timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
return result;
}
debounced.cancel = cancel;
return debounced;
}
|
Creates a function that delays invoking `func` until after `wait` milliseconds
have elapsed since the last time it was invoked. The created function comes
with a `cancel` method to cancel delayed invocations. Provide an options
object to indicate that `func` should be invoked on the leading and/or
trailing edge of the `wait` timeout. Subsequent calls to the debounced
function return the result of the last `func` invocation.
**Note:** If `leading` and `trailing` options are `true`, `func` is invoked
on the trailing edge of the timeout only if the the debounced function is
invoked more than once during the `wait` timeout.
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
for details over the differences between `_.debounce` and `_.throttle`.
@static
@memberOf _
@category Function
@param {Function} func The function to debounce.
@param {number} wait The number of milliseconds to delay.
@param {Object} [options] The options object.
@param {boolean} [options.leading=false] Specify invoking on the leading
edge of the timeout.
@param {number} [options.maxWait] The maximum time `func` is allowed to be
delayed before it is invoked.
@param {boolean} [options.trailing=true] Specify invoking on the trailing
edge of the timeout.
@returns {Function} Returns the new debounced function.
@example
// avoid costly calculations while the window size is in flux
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// invoke `sendMail` when the click event is fired, debouncing subsequent calls
jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
'leading': true,
'trailing': false
});
// ensure `batchLog` is invoked once after 1 second of debounced calls
var source = new EventSource('/stream');
jQuery(source).on('message', _.debounce(batchLog, 250, {
'maxWait': 1000
}, false);
// cancel a debounced call
var todoChanges = _.debounce(batchLog, 1000);
Object.observe(models.todo, todoChanges);
Object.observe(models, function(changes) {
if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
todoChanges.cancel();
}
}, ['delete']);
// ...at some point `models.todo` is changed
models.todo.completed = true;
// ...before 1 second has passed `models.todo` is deleted
// which cancels the debounced `todoChanges` call
delete models.todo;
|
debounce
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function cancel() {
if (timeoutId) {
clearTimeout(timeoutId);
}
if (maxTimeoutId) {
clearTimeout(maxTimeoutId);
}
maxTimeoutId = timeoutId = trailingCall = undefined;
}
|
Creates a function that delays invoking `func` until after `wait` milliseconds
have elapsed since the last time it was invoked. The created function comes
with a `cancel` method to cancel delayed invocations. Provide an options
object to indicate that `func` should be invoked on the leading and/or
trailing edge of the `wait` timeout. Subsequent calls to the debounced
function return the result of the last `func` invocation.
**Note:** If `leading` and `trailing` options are `true`, `func` is invoked
on the trailing edge of the timeout only if the the debounced function is
invoked more than once during the `wait` timeout.
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
for details over the differences between `_.debounce` and `_.throttle`.
@static
@memberOf _
@category Function
@param {Function} func The function to debounce.
@param {number} wait The number of milliseconds to delay.
@param {Object} [options] The options object.
@param {boolean} [options.leading=false] Specify invoking on the leading
edge of the timeout.
@param {number} [options.maxWait] The maximum time `func` is allowed to be
delayed before it is invoked.
@param {boolean} [options.trailing=true] Specify invoking on the trailing
edge of the timeout.
@returns {Function} Returns the new debounced function.
@example
// avoid costly calculations while the window size is in flux
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// invoke `sendMail` when the click event is fired, debouncing subsequent calls
jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
'leading': true,
'trailing': false
});
// ensure `batchLog` is invoked once after 1 second of debounced calls
var source = new EventSource('/stream');
jQuery(source).on('message', _.debounce(batchLog, 250, {
'maxWait': 1000
}, false);
// cancel a debounced call
var todoChanges = _.debounce(batchLog, 1000);
Object.observe(models.todo, todoChanges);
Object.observe(models, function(changes) {
if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
todoChanges.cancel();
}
}, ['delete']);
// ...at some point `models.todo` is changed
models.todo.completed = true;
// ...before 1 second has passed `models.todo` is deleted
// which cancels the debounced `todoChanges` call
delete models.todo;
|
cancel
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function delayed() {
var remaining = wait - (now() - stamp);
if (remaining <= 0 || remaining > wait) {
if (maxTimeoutId) {
clearTimeout(maxTimeoutId);
}
var isCalled = trailingCall;
maxTimeoutId = timeoutId = trailingCall = undefined;
if (isCalled) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
}
} else {
timeoutId = setTimeout(delayed, remaining);
}
}
|
Creates a function that delays invoking `func` until after `wait` milliseconds
have elapsed since the last time it was invoked. The created function comes
with a `cancel` method to cancel delayed invocations. Provide an options
object to indicate that `func` should be invoked on the leading and/or
trailing edge of the `wait` timeout. Subsequent calls to the debounced
function return the result of the last `func` invocation.
**Note:** If `leading` and `trailing` options are `true`, `func` is invoked
on the trailing edge of the timeout only if the the debounced function is
invoked more than once during the `wait` timeout.
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
for details over the differences between `_.debounce` and `_.throttle`.
@static
@memberOf _
@category Function
@param {Function} func The function to debounce.
@param {number} wait The number of milliseconds to delay.
@param {Object} [options] The options object.
@param {boolean} [options.leading=false] Specify invoking on the leading
edge of the timeout.
@param {number} [options.maxWait] The maximum time `func` is allowed to be
delayed before it is invoked.
@param {boolean} [options.trailing=true] Specify invoking on the trailing
edge of the timeout.
@returns {Function} Returns the new debounced function.
@example
// avoid costly calculations while the window size is in flux
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// invoke `sendMail` when the click event is fired, debouncing subsequent calls
jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
'leading': true,
'trailing': false
});
// ensure `batchLog` is invoked once after 1 second of debounced calls
var source = new EventSource('/stream');
jQuery(source).on('message', _.debounce(batchLog, 250, {
'maxWait': 1000
}, false);
// cancel a debounced call
var todoChanges = _.debounce(batchLog, 1000);
Object.observe(models.todo, todoChanges);
Object.observe(models, function(changes) {
if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
todoChanges.cancel();
}
}, ['delete']);
// ...at some point `models.todo` is changed
models.todo.completed = true;
// ...before 1 second has passed `models.todo` is deleted
// which cancels the debounced `todoChanges` call
delete models.todo;
|
delayed
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function maxDelayed() {
if (timeoutId) {
clearTimeout(timeoutId);
}
maxTimeoutId = timeoutId = trailingCall = undefined;
if (trailing || (maxWait !== wait)) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
}
}
|
Creates a function that delays invoking `func` until after `wait` milliseconds
have elapsed since the last time it was invoked. The created function comes
with a `cancel` method to cancel delayed invocations. Provide an options
object to indicate that `func` should be invoked on the leading and/or
trailing edge of the `wait` timeout. Subsequent calls to the debounced
function return the result of the last `func` invocation.
**Note:** If `leading` and `trailing` options are `true`, `func` is invoked
on the trailing edge of the timeout only if the the debounced function is
invoked more than once during the `wait` timeout.
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
for details over the differences between `_.debounce` and `_.throttle`.
@static
@memberOf _
@category Function
@param {Function} func The function to debounce.
@param {number} wait The number of milliseconds to delay.
@param {Object} [options] The options object.
@param {boolean} [options.leading=false] Specify invoking on the leading
edge of the timeout.
@param {number} [options.maxWait] The maximum time `func` is allowed to be
delayed before it is invoked.
@param {boolean} [options.trailing=true] Specify invoking on the trailing
edge of the timeout.
@returns {Function} Returns the new debounced function.
@example
// avoid costly calculations while the window size is in flux
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// invoke `sendMail` when the click event is fired, debouncing subsequent calls
jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
'leading': true,
'trailing': false
});
// ensure `batchLog` is invoked once after 1 second of debounced calls
var source = new EventSource('/stream');
jQuery(source).on('message', _.debounce(batchLog, 250, {
'maxWait': 1000
}, false);
// cancel a debounced call
var todoChanges = _.debounce(batchLog, 1000);
Object.observe(models.todo, todoChanges);
Object.observe(models, function(changes) {
if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
todoChanges.cancel();
}
}, ['delete']);
// ...at some point `models.todo` is changed
models.todo.completed = true;
// ...before 1 second has passed `models.todo` is deleted
// which cancels the debounced `todoChanges` call
delete models.todo;
|
maxDelayed
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function debounced() {
args = arguments;
stamp = now();
thisArg = this;
trailingCall = trailing && (timeoutId || !leading);
if (maxWait === false) {
var leadingCall = leading && !timeoutId;
} else {
if (!maxTimeoutId && !leading) {
lastCalled = stamp;
}
var remaining = maxWait - (stamp - lastCalled),
isCalled = remaining <= 0 || remaining > maxWait;
if (isCalled) {
if (maxTimeoutId) {
maxTimeoutId = clearTimeout(maxTimeoutId);
}
lastCalled = stamp;
result = func.apply(thisArg, args);
}
else if (!maxTimeoutId) {
maxTimeoutId = setTimeout(maxDelayed, remaining);
}
}
if (isCalled && timeoutId) {
timeoutId = clearTimeout(timeoutId);
}
else if (!timeoutId && wait !== maxWait) {
timeoutId = setTimeout(delayed, wait);
}
if (leadingCall) {
isCalled = true;
result = func.apply(thisArg, args);
}
if (isCalled && !timeoutId && !maxTimeoutId) {
args = thisArg = null;
}
return result;
}
|
Creates a function that delays invoking `func` until after `wait` milliseconds
have elapsed since the last time it was invoked. The created function comes
with a `cancel` method to cancel delayed invocations. Provide an options
object to indicate that `func` should be invoked on the leading and/or
trailing edge of the `wait` timeout. Subsequent calls to the debounced
function return the result of the last `func` invocation.
**Note:** If `leading` and `trailing` options are `true`, `func` is invoked
on the trailing edge of the timeout only if the the debounced function is
invoked more than once during the `wait` timeout.
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
for details over the differences between `_.debounce` and `_.throttle`.
@static
@memberOf _
@category Function
@param {Function} func The function to debounce.
@param {number} wait The number of milliseconds to delay.
@param {Object} [options] The options object.
@param {boolean} [options.leading=false] Specify invoking on the leading
edge of the timeout.
@param {number} [options.maxWait] The maximum time `func` is allowed to be
delayed before it is invoked.
@param {boolean} [options.trailing=true] Specify invoking on the trailing
edge of the timeout.
@returns {Function} Returns the new debounced function.
@example
// avoid costly calculations while the window size is in flux
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// invoke `sendMail` when the click event is fired, debouncing subsequent calls
jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
'leading': true,
'trailing': false
});
// ensure `batchLog` is invoked once after 1 second of debounced calls
var source = new EventSource('/stream');
jQuery(source).on('message', _.debounce(batchLog, 250, {
'maxWait': 1000
}, false);
// cancel a debounced call
var todoChanges = _.debounce(batchLog, 1000);
Object.observe(models.todo, todoChanges);
Object.observe(models, function(changes) {
if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
todoChanges.cancel();
}
}, ['delete']);
// ...at some point `models.todo` is changed
models.todo.completed = true;
// ...before 1 second has passed `models.todo` is deleted
// which cancels the debounced `todoChanges` call
delete models.todo;
|
debounced
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function defer(func) {
if (!isFunction(func)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var args = arguments;
return setTimeout(function() { func.apply(undefined, slice(args, 1)); }, 1);
}
|
Defers invoking the `func` until the current call stack has cleared. Any
additional arguments are provided to `func` when it is invoked.
@static
@memberOf _
@category Function
@param {Function} func The function to defer.
@param {...*} [args] The arguments to invoke the function with.
@returns {number} Returns the timer id.
@example
_.defer(function(text) { console.log(text); }, 'deferred');
// logs 'deferred' after one or more milliseconds
|
defer
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function delay(func, wait) {
if (!isFunction(func)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var args = arguments;
return setTimeout(function() { func.apply(undefined, slice(args, 2)); }, wait);
}
|
Invokes `func` after `wait` milliseconds. Any additional arguments are
provided to `func` when it is invoked.
@static
@memberOf _
@category Function
@param {Function} func The function to delay.
@param {number} wait The number of milliseconds to delay invocation.
@param {...*} [args] The arguments to invoke the function with.
@returns {number} Returns the timer id.
@example
_.delay(function(text) { console.log(text); }, 1000, 'later');
// => logs 'later' after one second
|
delay
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
function flow() {
var funcs = arguments,
length = funcs.length;
if (!length) {
return function() {};
}
if (!arrayEvery(funcs, isFunction)) {
throw new TypeError(FUNC_ERROR_TEXT);
}
return function() {
var index = 0,
result = funcs[index].apply(this, arguments);
while (++index < length) {
result = funcs[index].call(this, result);
}
return result;
};
}
|
Creates a function that invokes the provided functions with the `this`
binding of the created function, where each successive invocation is
supplied the return value of the previous.
@static
@memberOf _
@category Function
@param {...Function} [funcs] Functions to invoke.
@returns {Function} Returns the new function.
@example
function add(x, y) {
return x + y;
}
function square(n) {
return n * n;
}
var addSquare = _.flow(add, square);
addSquare(1, 2);
// => 9
|
flow
|
javascript
|
codemix/fast.js
|
dist/bench.js
|
https://github.com/codemix/fast.js/blob/master/dist/bench.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.