Map object
const map1 = new Map();
map1.set("a", 1);
map1.set("b", 2);
map1.set("c", 3);
console.log(map1.get("a"));
// expected output: 1
map1.set("a", 97);
console.log(map1.get("a"));
// expected output: 97
console.log(map1.size);
// expected output: 3
map1.delete("b");
console.log(map1.size);
// expected output: 2
validParentheses(strArr: string): boolean {
const mapP = new Map([
["(", ")"],
["{", "}"],
["[", "]"],
]);
let arr = [];
for (let i = 0; i < strArr.length; i++) {
arr.push(strArr[i]);
if (
arr.length > 1 &&
mapP.get(arr[arr.length - 2]) === arr[arr.length - 1]
)
arr.splice(arr.length - 2, 2);
}
return arr.length == 0 ? true : false;
}