Merge pull request #1432 from alexgy1/master

Add  JS correct reverse method
This commit is contained in:
程序员Carl
2022-07-08 08:27:14 +08:00
committed by GitHub

View File

@ -190,13 +190,13 @@ javaScript:
* @return {void} Do not return anything, modify s in-place instead.
*/
var reverseString = function(s) {
return s.reverse();
//Do not return anything, modify s in-place instead.
reverse(s)
};
var reverseString = function(s) {
var reverse = function(s) {
let l = -1, r = s.length;
while(++l < --r) [s[l], s[r]] = [s[r], s[l]];
return s;
};
```