2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
17
Task/Reverse-a-string/JavaScript/reverse-a-string-1.js
Normal file
17
Task/Reverse-a-string/JavaScript/reverse-a-string-1.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
//using chained methods
|
||||
function reverseStr(s) {
|
||||
return s.split('').reverse().join('');
|
||||
}
|
||||
|
||||
//fast method using for loop
|
||||
function reverseStr(s) {
|
||||
for (var i = s.length - 1, o = ''; i >= 0; o += s[i--]) { }
|
||||
return o;
|
||||
}
|
||||
|
||||
//fast method using while loop (faster with long strings in some browsers when compared with for loop)
|
||||
function reverseStr(s) {
|
||||
var i = s.length, o = '';
|
||||
while (i--) o += s[i];
|
||||
return o;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue