take-last
Version:
Returns a new shallow copy of the last n elements taken from the end of the given array. When list.length < n the list returned contain list.length elements.
75 lines (46 loc) • 2.35 kB
Markdown
# take-last
> Returns a new shallow copy of the last n elements taken from the end of the given array. When list.length < n the list returned contain list.length elements.
[](https://travis-ci.org/wilmoore/take-last.js) [](https://codeclimate.com/github/wilmoore/take-last.js) [](https://github.com/feross/standard)
```shell
npm install take-last --save
```
> You can also use Duo, Bower or [download the files manually](https://github.com/wilmoore/take-last.js/releases).
###### npm stats
[](https://www.npmjs.org/package/take-last) [](https://www.npmjs.org/package/take-last) [](https://david-dm.org/wilmoore/take-last.js)
## Overview
Returns `expr1` if it can be converted to true; otherwise, returns `expr2`. Thus, when used with Boolean values, || returns true if either operand is true; if both are false, returns false.
## API Example
###### Pointful
```js
var last = require('take-last')
last(2, ['a', 'b', 'c'])
//=> ['b', 'c']
```
###### Pointfree Style
```js
var last = require('take-last')
var list = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'] ]
list.map(last(1))
//=> [['c'], ['f'], ['i']]
```
## API
### `last(n, list)`
###### arguments
- `n (number)` Number of elements to take from the end of the list.
- `list (array)` Array to extract elements from.
###### returns
- `(array)` Returns copy of the last `n` elements taken from the end of `list`.
## Related
- [array-head]
## Alternatives
- [_.takeRight]
- [R.takeLast]
- [array-last]
## Contributing
> SEE: [contributing.md](contributing.md)
## Licenses
[](https://github.com/wilmoore/take-last.js/blob/master/license)
[array-head]: https://www.npmjs.com/package/array-head
[array-last]: https://www.npmjs.com/package/array-last
[_.takeRight]: https://lodash.com/docs#takeRight
[R.takeLast]: http://ramdajs.com/0.19.0/docs/#takeLast