Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
Add manual solution to reverse()
Browse files Browse the repository at this point in the history
  • Loading branch information
sicktastic committed Nov 20, 2017
1 parent cb5c71e commit 48c00c9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions algorithms/reversestring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@
// reverse('hello') === 'olleh'
// reverse('Greetings!') === '!sgniteerG'

// function reverse(str) {
// return str
// .split('')
// .reverse()
// .join('')
// }

function reverse(str) {
return str
.split('')
.reverse()
.join('')
let reversed = '';

for (let character of str) {
reversed = character + reversed;
}

return reversed;
}

module.exports = reverse;

0 comments on commit 48c00c9

Please sign in to comment.