{"id":23501423,"url":"https://github.com/tbjgolden/array-prototype-pack","last_synced_at":"2025-12-30T22:34:49.678Z","repository":{"id":57184112,"uuid":"137256654","full_name":"tbjgolden/array-prototype-pack","owner":"tbjgolden","description":"(non-standard) - Array.prototype.pack - Bin packing algorithm - https://en.wikipedia.org/wiki/Bin_packing_problem","archived":false,"fork":false,"pushed_at":"2018-06-13T22:36:04.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T09:05:53.024Z","etag":null,"topics":["algorithm","array","bin","javascript","node","nodejs","npm","packing","prototype"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tbjgolden.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-13T18:41:08.000Z","updated_at":"2018-06-13T22:36:05.000Z","dependencies_parsed_at":"2022-08-23T01:20:50.730Z","dependency_job_id":null,"html_url":"https://github.com/tbjgolden/array-prototype-pack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tbjgolden/array-prototype-pack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbjgolden%2Farray-prototype-pack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbjgolden%2Farray-prototype-pack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbjgolden%2Farray-prototype-pack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbjgolden%2Farray-prototype-pack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbjgolden","download_url":"https://codeload.github.com/tbjgolden/array-prototype-pack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbjgolden%2Farray-prototype-pack/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259790456,"owners_count":22911547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","array","bin","javascript","node","nodejs","npm","packing","prototype"],"created_at":"2024-12-25T07:17:56.888Z","updated_at":"2025-12-30T22:34:49.606Z","avatar_url":"https://github.com/tbjgolden.png","language":"JavaScript","readme":"# Array.prototype.pack (non-standard)\n\nBin packing algorithm (https://en.wikipedia.org/wiki/Bin_packing_problem)\n\n\n## Usage\n\n### Install\n\n```\nnpm install array-prototype-pack\n```\n\n### Example\n\n```javascript\nrequire('array-prototype-pack');\n\nvar blocks = [\n  { text: 'Rolly', height: 50 },\n  { text: 'Golly', height: 40 },\n  { text: 'Folly', height: 30 },\n  { text: 'Jolly', height: 20 },\n  { text: 'Holly', height: 30 },\n  { text: 'Bolly', height: 30 }\n];\n\nconst columns = blocks.pack(100, block =\u003e block.height, 'FFD');\nconsole.log(columns);\n```\n\n```javascript\n// example output:\n[\n  [\n    { text: 'Rolly', height: 50 },\n    { text: 'Golly', height: 40 }\n  ],\n  [\n    { text: 'Folly', height: 30 },\n    { text: 'Holly', height: 30 },\n    { text: 'Bolly', height: 30 }\n  ],\n  [\n    { text: 'Jolly', height: 20 }\n  ]\n]\n```\n\n## Parameters\n\n### Bin Max Size (optional)\n\nMax size of any bin. If negative or falsy, it will use the default.\n\nDefault: Will use the largest size in the array.\n\n### Size Function\n\nFunction that gets the size from an object.\n\nDefault: (identity function, returns itself).\n\n### Method\n\nBin packing algorithm to use.\n\nAvailable:\n- `FFD`: first fit decreasing (https://en.wikipedia.org/wiki/Bin_packing_problem#First-fit_algorithm)\n\nTo be added:\n- `MFFD`: modified first fit decreasing (https://en.wikipedia.org/wiki/Bin_packing_problem?oldformat=true#cite_ref-7)\n\nDefault: `FFD` (will be `MFFD` in later versions).\n\n## Return value\n\nA new array of arrays containing the original array's elements.\n\nThe original array, or the elements inside will not be modified.\n\nAll references to non-primitive elements of the original array will be\nused in the return value.\n\nThis means:\n- you can wrap a primitive in an object or array to identify the primitive.\n- mutating non-primitive elements in either the original array or the returned\n  array of arrays would mutate the other.\n\nExample:\n\n```javascript\nconst original = [{ weight: 10 }, { weight: 5 }];\nconst result = original.pack(null, obj =\u003e obj.weight);\nconsole.log(result); // [[{ weight: 10 }], [{ weight: 5 }]]\nconsole.log(original); // [{ weight: 10 }, { weight: 5 }]\n\noriginal[0].weight = 11;\nconsole.log(original); // [{ weight: 11 }, { weight: 5 }]\nconsole.log(result); // [[{ weight: 11 }], [{ weight: 5 }]]\n```\n\n## Notes\n\nFor items with a size larger than the specified 'Bin Max Size',\nthey will be placed in their own bin.\n\nAs 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)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbjgolden%2Farray-prototype-pack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbjgolden%2Farray-prototype-pack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbjgolden%2Farray-prototype-pack/lists"}