I am trying to break a 1D array into a 2D array where the sub-arrays are of varying lengths. This variance should follow the gaussian curve [or a mound shape]. So, say the 2D array variable we make is named gaussianCurve. The array within gaussianCurve[0] & gaussianCurve[n] would be of length 1, and gaussianCurve[n/2] would be a maximum provided by a parameter "maxArrayLength". This forces the number of gaussianCurve indexes to become variable.
Say I have the following psuedo-code:
function (oneDimentionalArray, maxArrayLength) {
// oneDimentionalArray is ["A","B","C","D","E","F","G","H","I","J","K"]
// maxArrayLength is 5
// Currently working like this (i.e. "batches"):
// return [["A","B","C","D","E"],["F","G","H","I","J"],["K"]]
// would LIKE it to work like this
gaussianCurve = []
gaussianCurve.push(["A"])
gaussianCurve.push(["B", "C"])
gaussianCurve.push(["D", "E", "F", "G", "H"])
gaussianCurve.push(["I", "J"])
gaussianCurve.push(["K"])
return gaussianCurve
}
Why would I want such a thing? Progress bars.
- They don’t show I am making progress immediately
- This is because the first job must complete before the bar can move
- They slow down at 95%+ and sometimes even stick at 100%
- Just annoying
Any suggestions are welcome. I am just not seeing the answer in my minds eye.
EDIT: I feel it was worded poorly, so I am rewording it.
...gaussianCurve[0].length & gaussianCurve[gaussianCurve.length - 1].length would be 1, and gaussianCurve[gaussianCurve.length/2].length would be up to "maxArrayLength".
REQUESTED INFO: For the record, I am aware of how rough this is, and how it has a bug in it. I am also aware it is not gaussian (because that is what I need help with). It is instead a triangle.
https://jsfiddle.net/brightmatter_og/xzfwjeaq/
from 1D -> 2D Array W/Normal Curve Sub-Array Lengths
No comments:
Post a Comment