Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
array-prototype-pack
Advanced tools
Array.prototype.pack (non-standard bin packing algorithm)
Bin packing algorithm (https://en.wikipedia.org/wiki/Bin_packing_problem)
npm install array-prototype-pack
require('array-prototype-pack');
var blocks = [
{ text: 'Rolly', height: 50 },
{ text: 'Golly', height: 40 },
{ text: 'Folly', height: 30 },
{ text: 'Jolly', height: 20 },
{ text: 'Holly', height: 30 },
{ text: 'Bolly', height: 30 }
];
const columns = blocks.pack(100, block => block.height, 'FFD');
console.log(columns);
// example output:
[
[
{ text: 'Rolly', height: 50 },
{ text: 'Golly', height: 40 }
],
[
{ text: 'Folly', height: 30 },
{ text: 'Holly', height: 30 },
{ text: 'Bolly', height: 30 }
],
[
{ text: 'Jolly', height: 20 }
]
]
Max size of any bin. If negative or falsy, it will use the default.
Default: Will use the largest size in the array.
Function that gets the size from an object.
Default: (identity function, returns itself).
Bin packing algorithm to use.
Available:
FFD
: first fit decreasing (https://en.wikipedia.org/wiki/Bin_packing_problem#First-fit_algorithm)To be added:
MFFD
: modified first fit decreasing (https://en.wikipedia.org/wiki/Bin_packing_problem?oldformat=true#cite_ref-7)Default: FFD
(will be MFFD
in later versions).
A new array of arrays containing the original array's elements.
The original array, or the elements inside will not be modified.
All references to non-primitive elements of the original array will be used in the return value.
This means:
Example:
const original = [{ weight: 10 }, { weight: 5 }];
const result = original.pack(null, obj => obj.weight);
console.log(result); // [[{ weight: 10 }], [{ weight: 5 }]]
console.log(original); // [{ weight: 10 }, { weight: 5 }]
original[0].weight = 11;
console.log(original); // [{ weight: 11 }, { weight: 5 }]
console.log(result); // [[{ weight: 11 }], [{ weight: 5 }]]
For items with a size larger than the specified 'Bin Max Size', they will be placed in their own bin.
As FFD uses Array.sort, the result is not necessarily stable when sizes are not unique. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
FAQs
Array.prototype.pack (non-standard bin packing algorithm)
The npm package array-prototype-pack receives a total of 0 weekly downloads. As such, array-prototype-pack popularity was classified as not popular.
We found that array-prototype-pack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.