Assignment 2 - Atif

Iron Array: You need to create a single array with all the unique numbers from a multi dimensional array. You need to account for varying levels of nesting.testcases: 1 ironArray([[["a"]], [["b"]]]) should return ["a", "b"] 2 ironArray([1, [2], [3, [[4]]]]) should return [1, 2, 3, 4]

by Atif Hassan

JavaScript

//Input Arrays
ironArray = [[["a"]], [["b", "c", "d", ["e", "d", [[2.12]]]]]];
arr = [[[1]], [[2, 3, 4, [5, [[6]]]]]];

//Change the array here
test = ironArray;

//Output Array
var steamRolled = [];

//Function unrolls given array
function steamRoll(test){
    test.reduce(function(res, ob){
        Array.isArray(ob)?steamRoll(ob):steamRolled.push(ob);
    }, [])
};

//Call function to unroll array
steamRoll(test);

//Remove Duplicates
steamRolled = Array.from(new Set(steamRolled));

alert(steamRolled);