My problem relates to files I’m trying to group and merge based on combined size (media files). In general, I have a program that will combine multiple files into groups of merged files.
The user may select any amount of files for the program to combine.
The program will combine the files, and output the merged files.
The merged files must be within a certain size range. In my case, 2.2gb to 4.2gb.
So let’s say the user selects 10 files. I need the program to then combine the files in the most optimal way possible. If the last file is 800mb, and won’t fit in the merge with the previous three, but the array of files COULD have been reorganized to incorporate the 800mb file, I need the program to do so.
Here’s an abstract program that illustrates:
console.log(output(2.2, 4.2, [1, .5, .4, 1.2, 2.2, 1.1, 1.7, 1.8, .2, .8]));
function output(lowerRange, upperRange, values) {
let groups = [];
// This works, but would output with a hanging .8 at the end.
groups = [ [1, .5, .4, 1.2], [2.2, 1.1], [1.7, 1.8, .2], [.8] ];
// This reorganizes to incorporate .8 in a more optimal way by shifting things around.
groups = [ [1, .5, .4, 1.2], [2.2, 1.1, .8], [1.7, 1.8, .2] ];
return groups;
}
Any help much appreciated.