Evaluate the Bracket Pairs of a String LeetCode solution in JavaScript

1
var evaluate = function (s, knowledge) {
2
// key => value hash map can be directly constructed using the Map constructor
3
const map = new Map(knowledge);
4

5
// since bracket pairs can't be nested we can use a RegExp to capture keys and replace using a map constructed in the line above
6
return s.replace(/\(([a-z]+)\)/g, (_, p1) => map.get(p1) ?? "?");
7
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0