Merge pull request #712 from Bruce-Feldman/Simplify-nth_Element

[ENHANCEMENT] Simplified nth Element, added better support for negative numbers thanks to @Bruce-Feldman
This commit is contained in:
Robert Mennell
2018-08-16 13:30:23 -07:00
committed by GitHub
2 changed files with 3 additions and 3 deletions

View File

@ -1,2 +1,2 @@
const nthElement = (arr, n = 0) => (n > 0 ? arr.slice(n, n + 1) : arr.slice(n))[0];
const nthElement = (arr, n = 0) => (n === -1 ? arr.slice(n) : arr.slice(n, n + 1))[0];
module.exports = nthElement;