Evaluate the Bracket Pairs of a String LeetCode solution in JavaScript
1var evaluate = function (s, knowledge) {2// key => value hash map can be directly constructed using the Map constructor3const map = new Map(knowledge);45// since bracket pairs can't be nested we can use a RegExp to capture keys and replace using a map constructed in the line above6return s.replace(/\(([a-z]+)\)/g, (_, p1) => map.get(p1) ?? "?");7};