function unit(options){ function getMaxNum(arr){ var max = arr[0]; for(var i = 0; i < arr.length;i++){ if(max < arr[i]){ max = arr[i]; } } return max; } function getMinNum(arr){ var min = arr[0]; for(var i = 0;i < arr.length;i++){ if(min > arr[i]){ min = arr[i]; } return min; } if("max" === options){ return getMaxNum; } if("min" === options){ return getMinNum; } } console.log(unit("max")([21,32,21,89,35,3,4]));