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

Commit

Permalink
feat(removeProperty): add function removeProperty with test (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedilancey authored and Kent C. Dodds committed Oct 8, 2018
1 parent 5af53e3 commit 0f94be7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import occurrences from './occurrences'
import getMiddle from './getMiddle'
import debounce from './debounce'
import curry from './curry'
import removeProperty from './removeProperty'

export {
reverseArrayInPlace,
Expand Down Expand Up @@ -146,4 +147,5 @@ export {
getMiddle,
debounce,
curry,
removeProperty,
}
14 changes: 14 additions & 0 deletions src/removeProperty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default removeProperty

/**
* Original Source: https://stackoverflow.com/questions/208105/how-do-i-remove-a-property-from-a-javascript-object
*
* This method will remove named property from given object
*
* @param {Object} obj - the object to remove property from
* @param {String} prop - name of property to remove
*/

function removeProperty(obj, prop) {
delete obj[prop]
}
11 changes: 11 additions & 0 deletions test/removeProperty.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import test from 'ava'
import {removeProperty} from '../src'

test('Remove a property from object', t => {
const obj = {fname: 'foo', lname: 'bar'}
const prop = 'lname'
const expected = {fname: 'foo'}
const actual = obj
removeProperty(obj, prop)
t.deepEqual(actual, expected)
})

0 comments on commit 0f94be7

Please sign in to comment.