【发布时间】:2020-07-16 05:59:24
【问题描述】:
我有一个数组,我必须将它拆分为给定的数字,如果(剩余数组大小
例如
var arr = [1,2,3,4,5,6,7,8,9,10,11]
if given_no 2 = Math.round(arr.length/2)= chunk_size 6 = [[1,2,3,4,5,6],[6,7,8,9,10]]
if given_no 3 = Math.round(arr.length/3)= chunk_size 4 = [[1,2,3,4],[5,6,7,8],[9,10,11]]
if given_no 4 = Math.round(arr.length/4)= chunk_size 3 = [[1,2,3],[4,5,6],[7,8,9],[10,11]]
【问题讨论】:
-
give_number 只到 4 还是动态的?
-
Math.round(11/2) == 6,而不是5。你的意思是Math.floor(11/2)? - 如果是这样,Math.floor(11/3) == 3和Math.floor(11/4) == 2... 另外,我不清楚“如果(剩余数组大小 -
@SijuSamson..它的动态(given_no)
标签: javascript arrays multidimensional-array array-splice