Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Build and Read a Map

Data Structures, Operators & Stringsmedium

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 124: Maps: Fundamentals

Implement `lookupAll(pairs, keys)` that builds a Map from an array of `[key, value]` pairs, then returns the values for the given `keys` in order.

Sample tests

Input: lookupAll([["a",1],["b",2]], ["a","b"])
Output: [1,2]
Input: lookupAll([["x",9]], ["x"])
Output: [9]

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Map keys use strict equality, so 1 and "1" are different keys.
Visualize this concept: Maps and Sets →
Approach & explanation (try first)

A Map is constructed directly from entry pairs and queried with get.

Loading...
⌘/Ctrl + Enter

Run your code to see results.