Skip to content

Instantly share code, notes, and snippets.

@jochri3
Created September 3, 2017 16:24
Show Gist options
  • Save jochri3/f7f95c402db26feac1d47c7b9c56253c to your computer and use it in GitHub Desktop.
Save jochri3/f7f95c402db26feac1d47c7b9c56253c to your computer and use it in GitHub Desktop.
null created by anonymous - https://repl.it/HaJU/46
// 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