Refer to Array.reduce Usage
1. Write the Getmissingelement function to return the missing element in the given array (the element in the array is 0~9, only one is missing).
Example:
Getmissingelement ([0, 5, 1, 3, 2, 9, 7, 6, 4]) //returns 8
Getmissingelement ([9, 2, 4, 5, 7, 0, 8, 6, 1]) //returns 3
Soluction:
function Getmissingelement (superimportantarray) { return superimportantarray.reduce (function (sum,i) {return SUM-I;},45)}
2.Write a function that flattens an array of the array objects into a flat array. Your function must only does one level of flattening.
Exmaple:
Flatten ([123])//= [+/-]
Flatten ([[1,2,3],["A", "B", "C"],[1,2,3]])//=>[1,2,3, "A", "B", "C", [+])
Flatten ([[[[[I]]])//= [[[+]]
Soluction:
var flatten = function (array) { return array.reduce (function (b) { return a.concat (b); },[])}
JavaScript algorithm problem (i) && array reduce use