We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a45e6b0 commit f831fdfCopy full SHA for f831fdf
2325-decode-the-message.js
@@ -0,0 +1,31 @@
1
+/**
2
+ * @param {string} key
3
+ * @param {string} message
4
+ * @return {string}
5
+ */
6
+var decodeMessage = function(key, message) {
7
+ const set = new Set()
8
+ for(const ch of key) {
9
+ if(ch !== ' ') set.add(ch)
10
+ if(set.size === 26) break
11
+ }
12
+ const arr = Array.from(set).map((e, i) => [e, i])
13
+ const hash = {}
14
+ for(const [e, i] of arr) {
15
+ hash[e] = i
16
17
+ // console.log(arr)
18
+ const a = 'a'.charCodeAt(0)
19
+ let res = ''
20
+ for(const ch of message) {
21
+ if(ch === ' ') {
22
+ res += ' '
23
+ continue
24
25
+ const idx = hash[ch]
26
+ const tmp = String.fromCharCode(a + idx)
27
+ res += tmp
28
29
+
30
+ return res
31
+};
0 commit comments