-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreverseStringArray.js
26 lines (17 loc) · 1.45 KB
/
reverseStringArray.js
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
/*
* Reverse an array which contains much more chars.
*/
const a = [":","W","\"","7"," ",".","s"," ","6","S","v","X",";","P","!","i"," ","1","`","0",".","\"","8","f",".","Y","W","7"," ","5","u","f","m","Q","V","E","X","!","E","D","e","Z","`","p","0","!","l","8","9","'","!","'","x","V","o","?","N","P","S","j","'","Q","?","s","?","'","2","T","0","R","N","p","n","v","7","u","u","?","v","?","!",";","a","!"," ","v"," ","\"","S","3","7","2","Y","`","B","j","5","l","3","2","H",";","f","u",":","`","8","X","!","Q","B","M","0","'","`","7","'","\""," ","\"",",","5",".","0","Q"," "," "," "," ","Q","0",".","5",",","\""," ","\"","3","7","`","3","0","M","B","Q","!","X","8","`",":","u","f",";","H","2","3","l","5","j","B","`","Y","2","7","3","S","\""," ","v"," ","!","a",";","!","?","v","?","u","u","7","v","n","p","N","R","0","T","2","'","?","s","?","Q","'","j","S","P","N","?","o","V","x","'","!","'","9","8","l","!","0","p","`","Z","e","D","E","!","X","E","V","Q","m","f","u","5"," ","7","W","Y",".","f","8","\"",".","0","`","1"," ","i","!","P",";","X","v","S","6"," ","s","."," ","7","\"","W",":"]
const reverseString = function(s) {
const size = s.length
const lastIndex = size - 1;
const halfSize = size / 2;
const absHalfSize = parseInt(halfSize)
const middleIndex = halfSize === absHalfSize ? absHalfSize - 1 : absHalfSize
for (let i=0; i <= middleIndex; i++) {
var j = s[i]
s[i] = s[lastIndex - i]
s[lastIndex - i] = j
}
};
reverseString(a)