arrays

Run Settings
LanguageJavascript
Language Version
Run Command
function reverse_v2(str) { //Check input if(!str || str.length < 2 || typeof str !== 'string') { return "This does not look right"; } const backwards = []; const totalItems = str.length - 1; for(let i = totalItems; i >= 0; i--) { backwards.push(str[i]); } return backwards.toString(); } function reverse(str) { //Check input if(!str || str.length < 2 || typeof str !== 'string') { return "This does not look right"; } let reverse_string = ""; for(let i = str.length -1; i >= 0; i--) { reverse_string += str[i]; } return reverse_string; } function reverse2(str) { return str.split('').reverse().join(''); } //cleaner way of writing reverse string const reverse3 = str => str.split('').reverse().join(''); //cleaner way or writing reverse string spread operator const reverse4 = str => [...str].reverse().join(''); const result = "ierdnA si eman yM iH"; console.log(reverse(result));
class MyArray { constructor() { this.length = 0; this.data = {}; } get(index) { return this.data[index]; } push(item) { this.data[this.length] = item; this.length++; return this.length; } pop() { const lastItem = this.data[this.length-1]; delete this.data[this.length - 1]; this.length--; return lastItem; } delete(index) { const item = this.data[index]; this.shiftItems(index); } shiftItems(index) { for(let i = index; i < this.length - 1; i++) { this.data[i] = this.data[i+1]; } delete this.data[this.length-1]; this.length--; } }
Editor Settings
Theme
Key bindings
Full width
Lines