Upside Down

Here’s a little script to turn a string upside-down:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var mirror = { 
a: '\u0250',
b: 'q',
c: '\u0254',
d: 'p',
e: '\u01DD',
f: '\u025F',
g: '\u0183',
h: '\u0265',
i: '\u0131',
j: '\u027E',
k: '\u029E',
l: '\u0283',
m: '\u026F',
n: 'u',
r: '\u0279',
t: '\u0287',
v: '\u028C',
w: '\u028D',
y: '\u028E',
'.': '\u02D9',
'[': ']',
'(': ')',
'{': '}',
'?': '\u00BF',
'!': '\u00A1',
"\'": ',',
'<': '>',
'_': '\u203E',
';': '\u061B'
};

Object.keys(mirror).forEach(function(key) { mirror[mirror[key]] = key; });

function upsideDown(text) {
text = text || '';
var result = '', i=text.length;
while (i--) {
ch = text[i];
if (ch in mirror) {
ch = mirror[ch];
}
result += ch || '';
}
return result
}

upsideDown("Upside down");
// returns "uʍop ǝpıspU

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2018 BinaryMiner All Rights Reserved.

Copyright Djordje Ungar