fromKeys - nodef/extra-map GitHub Wiki

Create a map from keys.

Similar: from, fromLists, fromKeys, fromValues.

function fromKeys(x, fm)
// x:  keys
// fm: map function for values (v, i, x)
const {fromKeys} = require('extra-map');

var ks = ['a', 'b', 'c'];
map.fromKeys(ks);
// → Map(3) { 'a' => 'a', 'b' => 'b', 'c' => 'c' }

map.fromKeys(ks, k => k.charCodeAt(0) - 97 + 1);
// → Map(3) { 'a' => 1, 'b' => 2, 'c' => 3 }