X Tutup
Skip to content

Commit ba0366f

Browse files
committed
minor cleanup
1 parent 38675a3 commit ba0366f

File tree

1 file changed

+6
-14
lines changed
  • algorithm/cryptography/caesar_cipher/basic

1 file changed

+6
-14
lines changed

algorithm/cryptography/caesar_cipher/basic/code.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
function getPosUp(pos) {
2-
if (pos === alphabet.length - 1) {
3-
return 0;
4-
} else {
5-
return pos + 1;
6-
}
2+
return (pos === alphabet.length - 1) ? 0 : pos + 1;
73
}
84

95
function getPosDown(pos) {
10-
if (pos === 0) {
11-
return alphabet.length - 1;
12-
} else {
13-
return pos - 1;
14-
}
6+
return (pos === 0) ? alphabet.length - 1 : pos - 1;
157
}
168

179
function getNextChar(currChar, direction) {
1810
var pos = alphabetMap[currChar];
1911
var nextPos = direction === 'up' ? getPosUp(pos) : getPosDown(pos);
2012
var nextChar = alphabet.charAt(nextPos);
13+
2114
logger._print(currChar + ' -> ' + nextChar);
2215
return nextChar;
2316
}
@@ -27,6 +20,8 @@ function cipher(str, rotation, direction, cipherTracer) {
2720

2821
for (var i = 0; i < str.length; i++) {
2922

23+
cipherTracer._wait();
24+
3025
var currChar = str.charAt(i);
3126
var r = rotation;
3227

@@ -38,11 +33,8 @@ function cipher(str, rotation, direction, cipherTracer) {
3833
currChar = getNextChar(currChar, direction);
3934
cipherTracer._notify(i, currChar)._wait();
4035
}
41-
42-
logger._print('Rotation result: ' + currChar);
43-
36+
4437
str = str.substring(0, i) + currChar + str.substring(i + 1);
45-
4638
logger._print('Current result: ' + str);
4739
}
4840

0 commit comments

Comments
 (0)
X Tutup