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

Commit 67538b0

Browse files
author
Kent C. Dodds
authored
feat(last): add last function (#207)
👍
1 parent a444bab commit 67538b0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import curry from './curry'
7575
import textJustification from './textJustification'
7676
import removeProperty from './removeProperty'
7777
import temperatureConverter from './temperatureConverter'
78+
import last from './last'
7879

7980
export {
8081
reverseArrayInPlace,
@@ -154,4 +155,5 @@ export {
154155
removeProperty,
155156
dec2hex,
156157
temperatureConverter,
158+
last,
157159
}

src/last.js

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

test/last.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 {last} from '../src'
3+
4+
test('gets the last item from an array', t => {
5+
const array = [1, 2, 3]
6+
const lastItem = last(array)
7+
t.deepEqual(lastItem, 3)
8+
})

0 commit comments

Comments
 (0)