Skip to content

Instantly share code, notes, and snippets.

@kemalkanok
Created March 17, 2017 08:53
Show Gist options
  • Save kemalkanok/e23c0290ad919532ea8d289adbfca7ec to your computer and use it in GitHub Desktop.
Save kemalkanok/e23c0290ad919532ea8d289adbfca7ec to your computer and use it in GitHub Desktop.
general reverse method
<script>
function start() {
// var text = prompt("here a text");
text="adanada";
// text = text.split('').reverse().join('');
// console.log(eval(text));
text = join(reverse(split(text)));
console.log(text);
}
function split(keyword) {
result = [];
for (var i = 0; i < keyword.length; i++) {
result.push(keyword[i]);
}
return result;
}
function reverse(arr) {
result = [];
for (var i = arr.length - 1; i >= 0; i--) {
result.push(arr[i]);
}
return result;
}
function join(arr) {
result = "";
for (var i = 0; i < arr.length; i++) {
result += arr[i];
}
return result;
}
start();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment