Created
September 3, 2017 16:24
-
-
Save jochri3/f7f95c402db26feac1d47c7b9c56253c to your computer and use it in GitHub Desktop.
null created by anonymous - https://repl.it/HaJU/46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a function that will take a string as input, and return a new | |
// string with the same letters in reverse order. | |
// | |
// | |
// Difficulty: easy. | |
function reverse(string) { | |
var reversed="" | |
for(var i=string.length-1;i>=0;i--) | |
{ | |
reversed +=string[i] | |
} | |
return reversed | |
} | |
// These are tests to check that your code is working. After writing | |
// your solution, they should all print true. | |
console.log("\nTests for reverse") | |
console.log("===============================================") | |
console.log( | |
'reverse("abc") == "cba": ' + (reverse("abc") == "cba") | |
) | |
console.log( | |
'reverse("a") == "a": ' + (reverse("a") == "a") | |
) | |
console.log( | |
'reverse("") == "": ' + (reverse("") == "") | |
) | |
console.log("===============================================") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment