Simplified nth Element

This commit is contained in:
Bruce Feldman
2018-08-12 21:01:48 -04:00
parent 4b7defc330
commit 59183e03b3
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;