Skip to content
/ zipmap Public

Returns a map with the keys mapped to the corresponding vals.

License

Notifications You must be signed in to change notification settings

landau/zipmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

zipmap

Returns a map with the keys mapped to the corresponding vals. zipmap also accepts a single value of objects or pairs.

Note: If you use objects, you must use the props key and value

/**
 * Returns a map with the keys mapped to the corresponding vals.
 *
 * @param {array} keys
 * @param {array} [vals]
 *
 * @return {object}
 */
function zipmap(keys, vals) { }

Install

npm i -S zipmap

Usage

var assert = require('assert');
var zipmap = require('zipmap');

var keys = ['a', 'b', 'c'];
var vals = [1, 2, 3];

var map = zipmap(keys, vals);
assert.deepEqual(map, { a: 1, b: 2, c: 3 });

Or use an array of objects

var objs = [
  { key: 'foo', value: 'bar' },
  { key: 'hi', value: 'bye' },
];

var out = {
  foo: 'bar',
  hi: 'bye'
};

var map = zipmap(objs);
assert.deepEqual(map, out);

or use an array of pairs

var pairs = [
  ['foo', 'bar'],
  ['hi', 'bye']
];

var out = {
  foo: 'bar',
  hi: 'bye'
};

var map = zipmap(pairs);
assert.deepEqual(map, out);

Changelog

1.1.1

  • Return empty obj when given an array of len 0

1.1.0

  • Add single argument handling which allows objects or pairs

About

Returns a map with the keys mapped to the corresponding vals.

Resources

License

Stars

Watchers

Forks

Packages

No packages published