Encrypt and Decrypt Strings LeetCode solution in JavaScript

1
var Encrypter = function (keys, values, dictionary) {
2
this.encryptMap = new Map();
3
for (let i = 0; i < keys.length; i++) {
4
this.encryptMap.set(keys[i], values[i]);
5
}
6
this.dict = new Set(dictionary);
7
// Encypt the values in dict for easy comparison later
8
this.encryptedVals = [];
9
for (let word of this.dict) {
10
this.encryptedVals.push(this.encrypt(word));
11
}
12
};
13
Encrypter.prototype.encrypt = function (word1) {
14
let encrypted = "";
15
for (let char of word1) {
16
encrypted += this.encryptMap.get(char);
17
}
18
return encrypted;
19
};
20
Encrypter.prototype.decrypt = function (word2) {
21
return this.encryptedVals.filter((x) => x === word2).length;
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0