Given is an array which contains sub-arrays. The elements in this sub-arrays are numbers.The task is to implement a JavaScript-function which returns an array with the smallest / largest numbers in the single arrays.I have figured out this solution: // Returns the smallest / largest//   numbers contained in a //   set of arrays.// Parameter ---------------------// 1.: Array - Containing other arrays.// 2.: Function - Either Math.max or//  Math.min// Return -------------------------// Array - Containing numbers in case//  of success. //  Containing 'undefined' in case //  of elements which aren't arrays.//  Containing NaN in case of elements //  which aren't numbers.function getExtrema(structure, funct) {  var ret = structure.map(function(value) {    if (Array.isArray(value)) {      return funct.apply(null, value);    }  });  return ret;}Complete code (with examples) on CodePen: http://codepen.io/mizech/pen/bEBMaW?editors=101Are there better ways to solve the described task?
Function which returns the smallest / largest numbers in a nested array structure
javascript
Edge casesYour function works slightly different than you say it does:Math.max and Math.min work on anything that can be converted to a number. The array [1,2,3,4] will just work fine. NaN is returned for a case whenever there is an element in that subarray that cannot be converted to a number.Math.max and Math.min return -Infinity and Infinity if the array is empty. This case is undocumented.DocumentationYour function is documented well. You might want to consider changing the documentation to the format that JSDoc uses, so you can automatically generate documentation for your javascript codebase.