408aac6b7d425d07387edbece6015ee103c3b114
[yaffs-website] / node_modules / uncss / node_modules / lodash / takeRight.js
1 var baseSlice = require('./internal/baseSlice'),
2     toInteger = require('./toInteger');
3
4 /**
5  * Creates a slice of `array` with `n` elements taken from the end.
6  *
7  * @static
8  * @memberOf _
9  * @category Array
10  * @param {Array} array The array to query.
11  * @param {number} [n=1] The number of elements to take.
12  * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
13  * @returns {Array} Returns the slice of `array`.
14  * @example
15  *
16  * _.takeRight([1, 2, 3]);
17  * // => [3]
18  *
19  * _.takeRight([1, 2, 3], 2);
20  * // => [2, 3]
21  *
22  * _.takeRight([1, 2, 3], 5);
23  * // => [1, 2, 3]
24  *
25  * _.takeRight([1, 2, 3], 0);
26  * // => []
27  */
28 function takeRight(array, n, guard) {
29   var length = array ? array.length : 0;
30   if (!length) {
31     return [];
32   }
33   n = (guard || n === undefined) ? 1 : toInteger(n);
34   n = length - n;
35   return baseSlice(array, n < 0 ? 0 : n, length);
36 }
37
38 module.exports = takeRight;