Sha256: 06894f42bf1fac7993058ed32d5761501c69129eafec3f7946dc15caad25a38f

Contents?: true

Size: 959 Bytes

Versions: 167

Compression:

Stored size: 959 Bytes

Contents

var baseSlice = require('../internal/baseSlice'),
    isIterateeCall = require('../internal/isIterateeCall');

/**
 * Creates a slice of `array` with `n` elements taken from the end.
 *
 * @static
 * @memberOf _
 * @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]);
 * // => [3]
 *
 * _.takeRight([1, 2, 3], 2);
 * // => [2, 3]
 *
 * _.takeRight([1, 2, 3], 5);
 * // => [1, 2, 3]
 *
 * _.takeRight([1, 2, 3], 0);
 * // => []
 */
function takeRight(array, n, guard) {
  var length = array ? array.length : 0;
  if (!length) {
    return [];
  }
  if (guard ? isIterateeCall(array, n, guard) : n == null) {
    n = 1;
  }
  n = length - (+n || 0);
  return baseSlice(array, n < 0 ? 0 : n);
}

module.exports = takeRight;

Version data entries

167 entries across 87 versions & 9 rubygems

Version Path
ilog-0.4.1 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/array/takeRight.js
ilog-0.4.1 node_modules/contents/node_modules/lodash/array/takeRight.js
ilog-0.4.1 node_modules/babel/node_modules/lodash/array/takeRight.js
ilog-0.4.0 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/array/takeRight.js
ilog-0.4.0 node_modules/contents/node_modules/lodash/array/takeRight.js
ilog-0.4.0 node_modules/babel/node_modules/lodash/array/takeRight.js
ilog-0.3.3 node_modules/babel/node_modules/lodash/array/takeRight.js
ilog-0.3.3 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/array/takeRight.js
ilog-0.3.3 node_modules/contents/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/takeRight.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/array/takeRight.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/inquirer/node_modules/lodash/array/takeRight.js