Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

feat(second): add second function #242

Merged
merged 3 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -184,4 +185,5 @@ export {
hex2hsl,
removeElementByIndex,
clone,
second,
}
18 changes: 18 additions & 0 deletions src/second.js
Original file line number Diff line number Diff line change
@@ -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]
}
9 changes: 9 additions & 0 deletions test/second.test.js
Original file line number Diff line number Diff line change
@@ -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)
})