Skip to content

Commit

Permalink
Create (多维)数组的最大值最小值.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain120 authored Aug 9, 2018
1 parent f204843 commit 58f2215
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions (多维)数组的最大值最小值.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* question:一维数组,多维数组找出某列的最大值、最小值
* answer:我的思路是扁平化,在通过一维数组查找结果
*/

var flattenArr = (arr, index) => {
let fa = [];
arr.map(item => fa.push(item[index]));
return fa;
}
var min = Math.min.apply(null, flattenArr([[5, 6, 4], [1, 2, 6], [3, 4, 8]], 2));
var max = Math.max.apply(null, flattenArr([[5, 6, 4], [1, 2, 6], [3, 4, 8]], 2));
console.log(max, min);

0 comments on commit 58f2215

Please sign in to comment.