Skip to content

Instantly share code, notes, and snippets.

@gabidavila
Last active December 4, 2017 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabidavila/b3f1e11532a111bbe8db63cd2c539d44 to your computer and use it in GitHub Desktop.
Save gabidavila/b3f1e11532a111bbe8db63cd2c539d44 to your computer and use it in GitHub Desktop.
def reverse_string(word)
new_word = []
array_chars = word.split("")
last_index = array_chars.length - 1
0..(array_chars.length/2.00).ceil.times do |i|
new_word[last_index - i] = array_chars[i]
new_word[i] = array_chars[last_index - i]
end
new_word.join("")
end
function reverseString(word) {
const new_word = [];
const array_chars = word.split("");
const last_index = array_chars.length - 1;
for (let i = 0; i <= Math.ceil(array_chars.length/2); i++) {
new_word[last_index - i] = array_chars[i];
new_word[i] = array_chars[last_index - i]
}
return new_word.join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment