Reverse a String using Array

Run Settings
LanguageJavaScript
Language Version
Run Command
// Create a function that reverses a string : function reverse(str){ // General function //check whether input is a string or not if( !str || str.length<2 || typeof str!== 'string'){ return 'Ayoo, that aint a string innit'; } const backwards = []; const totalItems = str.length - 1; for (let i = totalItems; i >= 0; i--){ backwards.push(str[i]); } console.log(backwards); console.log(backwards.join('')); return backwards.join(''); } reverse("That's my name right there"); function reverse2(str){ // language-specific newstr = str.split('').reverse().join(''); console.log(newstr); return newstr; } reverse2("Hell yeah, holy father"); const reverse3 = str => console.log(str.split('').reverse().join('')); // language-specific reverse3("Bring me the sheesh kebab");
Editor Settings
Theme
Key bindings
Full width
Lines