From 7b40ea58769fc6b17e98d526cbd3f0d123fab9f5 Mon Sep 17 00:00:00 2001 From: yeashinr Date: Mon, 11 Feb 2019 19:09:50 -0500 Subject: [PATCH 1/2] feat(second): add second function --- src/index.js | 2 ++ src/second.js | 18 ++++++++++++++++++ test/second.test.js | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/second.js create mode 100644 test/second.test.js diff --git a/src/index.js b/src/index.js index 072f17fe..c13aa0e9 100644 --- a/src/index.js +++ b/src/index.js @@ -90,6 +90,7 @@ import truncate from './truncate' import validateEmail from './validateEmail' import removeElementByIndex from './removeElementByIndex' import clone from './clone' +import second from './second' export { reverseArrayInPlace, @@ -184,4 +185,5 @@ export { hex2hsl, removeElementByIndex, clone, + second, } diff --git a/src/second.js b/src/second.js new file mode 100644 index 00000000..1fd29fce --- /dev/null +++ b/src/second.js @@ -0,0 +1,18 @@ + + +//export default arrayHasNegativeValue +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) { + /* if (array !== undefined || array.length >= 2 || !Array.isArray(array)) { + return array[1] + } */ + + return array[1] +} diff --git a/test/second.test.js b/test/second.test.js new file mode 100644 index 00000000..50731177 --- /dev/null +++ b/test/second.test.js @@ -0,0 +1,9 @@ +import test from 'ava' +import {second} from '../src' + +test('Check Array contains negative value', t => { + const array = [1, 2, 3, -1] + const expected = array[1] + const actual = second(array) + t.deepEqual(actual, expected) +}) From 12580e059a3cff598db4653119685fff4e079ef3 Mon Sep 17 00:00:00 2001 From: yeashinr Date: Tue, 12 Feb 2019 00:32:11 -0500 Subject: [PATCH 2/2] feat(second): resolve the issues --- src/second.js | 7 ------- test/second.test.js | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/second.js b/src/second.js index 1fd29fce..18da3f83 100644 --- a/src/second.js +++ b/src/second.js @@ -1,6 +1,3 @@ - - -//export default arrayHasNegativeValue export default second /* *source :https://stackoverflow.com/questions/44531677 @@ -10,9 +7,5 @@ export default second */ function second(array) { - /* if (array !== undefined || array.length >= 2 || !Array.isArray(array)) { - return array[1] - } */ - return array[1] } diff --git a/test/second.test.js b/test/second.test.js index 50731177..295f4d9e 100644 --- a/test/second.test.js +++ b/test/second.test.js @@ -1,7 +1,7 @@ import test from 'ava' import {second} from '../src' -test('Check Array contains negative value', t => { +test('Return second elements of the array', t => { const array = [1, 2, 3, -1] const expected = array[1] const actual = second(array)