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

Commit f3aef1a

Browse files
latiifabdiKent C. Dodds
authored andcommitted
This function will return the first element of the array (#218)
closes #216
1 parent e876550 commit f3aef1a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/first.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default first
2+
3+
/**
4+
* This method will return the first element of the array.
5+
*
6+
* @param {Array} array - the array
7+
* @return {*} - first item in the array
8+
*/
9+
function first(array) {
10+
return array[0]
11+
}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import reduceCount from './reduceCount'
8181
import BitwiseAnd from './BitwiseAnd'
8282
import copyArrayByValue from './copyArrayByValue'
8383
import timeSince from './timeSince'
84+
import first from './first'
8485

8586
export {
8687
reverseArrayInPlace,
@@ -166,4 +167,5 @@ export {
166167
BitwiseAnd,
167168
copyArrayByValue,
168169
timeSince,
170+
first,
169171
}

test/first.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import test from 'ava'
2+
import {first} from '../src'
3+
4+
test('gets the first item from an array', t => {
5+
const array = [1, 2, 3]
6+
const lastItem = first(array)
7+
t.deepEqual(lastItem, 1)
8+
})

0 commit comments

Comments
 (0)