Skip to content

Commit

Permalink
Ignore keys with undefined vals in pick and zipObj
Browse files Browse the repository at this point in the history
  • Loading branch information
flintinatux committed Oct 5, 2019
1 parent 65ba1e1 commit bbef56c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p align="center">
<a href="https://www.npmjs.com/package/tinyfunk"><img src="https://img.shields.io/npm/v/tinyfunk.svg" alt="npm version" style="max-width:100%;"></a>
<a href="https://www.npmjs.com/package/tinyfunk"><img src="https://img.shields.io/npm/dm/tinyfunk.svg" alt="npm downloads" style="max-width:100%;"></a>
<a href="#"><img src="https://img.shields.io/badge/gzip--size-1.55%20kB-blue.svg" alt="gzip-size" style="max-width:100%;"></a>
<a href="#"><img src="https://img.shields.io/badge/gzip--size-1.56%20kB-blue.svg" alt="gzip-size" style="max-width:100%;"></a>
<br />
<a href="https://travis-ci.org/flintinatux/tinyfunk"><img src="https://travis-ci.org/flintinatux/tinyfunk.svg?branch=master" alt="Build Status" style="max-width:100%;"></a>
<a href="https://coveralls.io/github/flintinatux/tinyfunk?branch=master"><img src="https://coveralls.io/repos/github/flintinatux/tinyfunk/badge.svg?branch=master" alt="Coverage Status" style="max-width:100%;"></a>
Expand Down
3 changes: 2 additions & 1 deletion src.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ const when = curry((pred, f, x) =>
// zipObj :: [k] -> [v] -> { k: v }
const zipObj = curry((keys, vals) => {
const res = {}
for (let i = length(keys); i--;) res[keys[i]] = vals[i]
for (let i = length(keys); i--;)
if (vals[i] !== undefined) res[keys[i]] = vals[i]
return res
})

Expand Down
4 changes: 4 additions & 0 deletions test/pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ describe('pick', () => {
it('is curried', () =>
expect(pick([ 'a', 'b' ])(orig)).to.eql({ a: 'a', b: 'b' })
)

it('does not include a picked key if val is undefined', () =>
expect(pick([ 'a', 'd' ], orig)).to.eql({ a: 'a' })
)
})
4 changes: 4 additions & 0 deletions test/zipObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ describe('zipObj', () => {
it('is curried', () =>
expect(zipObj(keys)(vals)).to.eql({ foo: 1, bar: 2 })
)

it('does not include a key when val is undefined', () =>
expect(zipObj(keys, [ 1, undefined ])).to.eql({ foo: 1 })
)
})
2 changes: 1 addition & 1 deletion tinyfunk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbef56c

Please sign in to comment.