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

Commit 0f94be7

Browse files
jedilanceyKent C. Dodds
jedilancey
authored and
Kent C. Dodds
committed
feat(removeProperty): add function removeProperty with test (#197)
1 parent 5af53e3 commit 0f94be7

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Diff for: src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import occurrences from './occurrences'
7171
import getMiddle from './getMiddle'
7272
import debounce from './debounce'
7373
import curry from './curry'
74+
import removeProperty from './removeProperty'
7475

7576
export {
7677
reverseArrayInPlace,
@@ -146,4 +147,5 @@ export {
146147
getMiddle,
147148
debounce,
148149
curry,
150+
removeProperty,
149151
}

Diff for: src/removeProperty.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default removeProperty
2+
3+
/**
4+
* Original Source: https://stackoverflow.com/questions/208105/how-do-i-remove-a-property-from-a-javascript-object
5+
*
6+
* This method will remove named property from given object
7+
*
8+
* @param {Object} obj - the object to remove property from
9+
* @param {String} prop - name of property to remove
10+
*/
11+
12+
function removeProperty(obj, prop) {
13+
delete obj[prop]
14+
}

Diff for: test/removeProperty.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import test from 'ava'
2+
import {removeProperty} from '../src'
3+
4+
test('Remove a property from object', t => {
5+
const obj = {fname: 'foo', lname: 'bar'}
6+
const prop = 'lname'
7+
const expected = {fname: 'foo'}
8+
const actual = obj
9+
removeProperty(obj, prop)
10+
t.deepEqual(actual, expected)
11+
})

0 commit comments

Comments
 (0)