diff --git a/src/index.js b/src/index.js index a0c4c920..47ee130c 100644 --- a/src/index.js +++ b/src/index.js @@ -91,6 +91,7 @@ import validateEmail from './validateEmail' import removeElementByIndex from './removeElementByIndex' import clone from './clone' import arrMultiply from './array-multiplier' +import second from './second' export { reverseArrayInPlace, @@ -186,4 +187,5 @@ export { removeElementByIndex, clone, arrMultiply, + second, } diff --git a/src/second.js b/src/second.js new file mode 100644 index 00000000..18da3f83 --- /dev/null +++ b/src/second.js @@ -0,0 +1,11 @@ +export default second +/* +*source :https://stackoverflow.com/questions/44531677 +* function return second element of the array. +* @param {Number} array - any +* return boolean value +*/ + +function second(array) { + return array[1] +} diff --git a/test/second.test.js b/test/second.test.js new file mode 100644 index 00000000..295f4d9e --- /dev/null +++ b/test/second.test.js @@ -0,0 +1,9 @@ +import test from 'ava' +import {second} from '../src' + +test('Return second elements of the array', t => { + const array = [1, 2, 3, -1] + const expected = array[1] + const actual = second(array) + t.deepEqual(actual, expected) +})