Overview
Implement fromPairs(pairs) where each element is a [key, value] array.
Examples
fromPairs([['a',1],['b',2]]); // {a:1,b:2}Solution
Reveal solution
function fromPairs(pairs) {
const r = {};
for (const [k,v] of pairs) r[k] = v;
return r;
}from-pairs.js
From Pairs
easycodingJavaScriptArrays
Overview
Implement fromPairs(pairs) where each element is a [key, value] array.
Examples
fromPairs([['a',1],['b',2]]); // {a:1,b:2}Solution
Reveal solution
function fromPairs(pairs) {
const r = {};
for (const [k,v] of pairs) r[k] = v;
return r;
}NameTopicDifficulty
103 of 103 problems