Exercise - Arrays Reverse

by Charlie Winfrey

JavaScript

/**
 * Reversing an array
 (without Array.reverse())
 *
 * 1)
 * Create a function, reverseArray(arr), that expects a single array as an argument
 * It will return a new array, with all the values in reverse order
 */
function reverseArray(arr) {
    var newArray =[]
    var j = 0;
}


var myArray = [1,2,3];


function reverseArray(myArray) {
        
    throw {
        name: "ExceptionThrowerException",
        message: "Bad things afoot"
    };
    
    //throw new Error("Bad things afoot");
}

var myArrayLiteral = [1,2,3];
var myArrayConstructed = new Array(1,2,3);

console.log(myArrayLiteral);
console.log(myArrayConstructed);


console.log(reverseArray(["A", "B", "C"]));
// → ["C", "B", "A"];

/* 
 * 2)
 * Upgrade the reverseArray function so that when you pass a value 
 * that is not an array it will throw an exception
 */


/*
 * 3) Bonus
 * Create a new function, reverseArrayInPlace(arr)
 * which does the same but does NOT use two arrays during the reversal process. 
*/