{"id":15608621,"url":"https://github.com/hypercubed/boostarray","last_synced_at":"2025-06-23T05:41:40.317Z","repository":{"id":24023737,"uuid":"27408339","full_name":"Hypercubed/BoostArray","owner":"Hypercubed","description":"Booster shot for Javascript Arrays","archived":false,"fork":false,"pushed_at":"2015-11-23T12:57:47.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-04T15:25:07.677Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hypercubed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-02T01:07:34.000Z","updated_at":"2015-04-12T08:47:52.000Z","dependencies_parsed_at":"2022-08-26T02:52:02.513Z","dependency_job_id":null,"html_url":"https://github.com/Hypercubed/BoostArray","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2FBoostArray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2FBoostArray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2FBoostArray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hypercubed%2FBoostArray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hypercubed","download_url":"https://codeload.github.com/Hypercubed/BoostArray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246194908,"owners_count":20738761,"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":[],"created_at":"2024-10-03T05:21:40.546Z","updated_at":"2025-03-29T14:25:29.538Z","avatar_url":"https://github.com/Hypercubed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"BoostArray\n==========\n\nBooster shot for JavaScript Arrays\n\nAdds \"boosted\" iterator methods to ordinary JavaScript arrays.\n\n\u003e Note: BoostArray is experimental.  Feedback is appreciated.  Please see [techfort/PowerArray](https://github.com/techfort/PowerArray) for an alternative approach.\n\n# Introduction\n\nThe fastest way to iterate over an array in JavaScript is always going to be writing out the explicit `for` or `while` loop like this\u003csup\u003e[*citation needed*]\u003c/sup\u003e:\n\n```\nfor (var i = 0, len = myArray.length; i \u003c len; i++) {\n\tmyFunc(myArray[i]);\n}\n```\n\nHowever, nothing beats the convenience of JavaScript's `forEach` and sibling functions (`map`, `reduce`, `filter`):\n\n```\nmyArray.forEach(myFunc);\n```\n\nHowever convenience comes at a cost.  `forEach`, and siblings, do various type checking and have various extra features not needed 93%\u003csup\u003e[*based on very unscientific analysis of my own code*]\u003c/sup\u003e of the time.  These features, desired in many cases, slow the looping process down significantly (see benchmarks below).\n\nBoostArray is like a Booster shot for JavaScript Arrays in that it adds additional fast versions of forEach and siblings to a ordinary JavaScript arrays or, optionally, all native arrays (see usage below).  Switching between the standard method and the similar boosted method can be as simple as adding a single character:\n\n```\nmyArray.$forEach(myFunc);\n```\n\n# Usage\n\nThere are three ways to use BoostArray:\n\n## As a boost for ordinary JavaScript arrays (recommended method)\n\n```\nvar boostedArray = BoostArray();\n\n/* ...add some elements using push(), etc */\n\nboostedArray.$forEach(myFunc);\n```\n\nboostedArray is initially an empty array that has the boosted methods attached (see methods below).  Note that while `BoostArray` looks (and sort of acts) like a constructor it... it really isn't (see [here](http://www.bennadel.com/blog/2292-extending-javascript-arrays-while-keeping-native-bracket-notation-functionality.htm)).  BoostArray adds methods to existing arrays, but in the example above, since no array is passed to the \"constructor\" so BoostArray assumes you want a new array.  The following method for boosting an existing array is recommended:\n\n```\nBoostArray(myArray);\nmyArray.$forEach(myFunc);\n```\n\n\u003e Note: using this method, any array returned from Array.prototype or BoostArray.prototype methods will be an ordinary JavaScript array.  You will need subsequently to boost any array's returned from these methods (if you want to later use the boosted methods).\n\n```\nBoostArray(myArray);\nvar resultArray = BoostArray(myArray.$map(myFunc));\n```\n\n## As a boost for all arrays (use with caution)\n\n```\nBoostArray(Array.prototype);\n\n/* ... */\n\nmyArray.$forEach(myFunc);\n```\n\nThis will boost all JavaScript arrays.  All JavaScript arrays will now have the fast \"boosted\" methods.\n\n\u003e Note: In general extending JavaScript natives is not recommended (see [Extending JavaScript Natives](http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/)) and may break other libraries.  Use with caution.\n\n## As a boosting toolset\n\n```\nBoostArray.prototype.$forEach.call(myArray, myFunc);\n```\n\nUsing JavaScript's `Function.prototype.call()` method the BoostArray methods can be applied to any array or array like object.\n\n# Methods\n\nA boosted array (by any of first two methods above) is still an ordinary JavaScript Array.  Therefore it contains all the standard [Array.prototype methods](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype).\n\n### BoostArray.isBoostedArray(element)\nReturns true if an element is a boosted array, if not false.\n\n## Accessor methods\nIn addition to `Array.prototype` accessor methods a boosted array contains the following additional fast methods.\n\n\u003e Notice the dollar sign for boosted methods.\n\n### BoostArray.prototype.$indexOf(searchElement)\nReturns the first index of an element within the array that is strictly equal (the same method used by the === operator) to the searchElement, or -1 if none is found.\n\n\u003e Note: Unlike `Array.prototype.indexOf` there is no fromIndex used start the search at, there is no handling of sparse arrays.\n\n## Iteration methods\nIn addition to `Array.prototype` iteration methods a boosted array contains the following additional fast methods.\n\n\u003e Notice the dollar sign for boosted methods.\n\n### BoostArray.prototype.$forEach(callback)\nCalls the callback function for each element in the array in ascending order.\n\n\u003e Note: Unlike `Array.prototype.forEach` there is no thisArg used for callback binding, there is no handling of sparse arrays, and the callback function is invoked with only the element value (i.e. no element index or reference to the original array).\n\n### BoostArray.prototype.$filter(callback)\nCreates a new ordinary array with all of the elements of this array for which the provided filtering function returns true.\n\n\u003e Note: Unlike `Array.prototype.filter` there is no thisArg used for callback binding, there is no handling of sparse arrays, and the callback function is invoked with only the element value (i.e. no element index or reference to the original array).\n\u003e Also note that unless you have boosted the Array.prototype as discussed above the returned value will not have the boosted methods attached.\n\n### BoostArray.prototype.$map(callback)\nCreates a new ordinary array with the results of calling a provided function on every element in this array.\n\n\u003e Note: Unlike `Array.prototype.map` there is no thisArg used for callback binding, there is no handling of sparse arrays, and the callback function is invoked with only the element value (i.e. no element index or reference to the original array).\n\u003e Also note that unless you have boosted the Array.prototype as discussed above the returned value will not have the boosted methods attached.\n\n### BoostArray.prototype.$reduce(callback, initialValue)\nApply a the callback function against each value of the array (in ascending order) reducing it to a single value.\n\n\u003e Note: Unlike `Array.prototype.reduce` the initialValue is not optional, there is no handling of sparse arrays, and the callback function is invoked with only the element value (i.e. no element index or reference to the original array).\n\n# Benchmarks\n\nFor benchmarks see [Hypercubed/ArraySpeedTests](https://github.com/Hypercubed/ArraySpeedTests)\n\n# Contributions\n\nPull requests are appreciated.  However, remember keep it fast by:\n\n1. no callback binding,\n2. no type checking,\n3. no element index or reference to the original array.\n\n# Acknowledgements\n\nBoostArray was inspired by [PowerArray](https://github.com/techfort/PowerArray) by Joe Minichino, [fast.js](https://github.com/codemix/fast.js/tree/master), [ramda](https://github.com/ramda/ramda), and [lodash](https://github.com/lodash/lodash/).  Much of the Array sub-classing code based on *[Extending JavaScript Arrays While Keeping Native Bracket-Notation Functionality](http://www.bennadel.com/blog/2292-extending-javascript-arrays-while-keeping-native-bracket-notation-functionality.htm)* by Ben Nadel.\n\n## License\n2014 Jayson Harshbarger\n\n[MIT License](http://en.wikipedia.org/wiki/MIT_License)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercubed%2Fboostarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhypercubed%2Fboostarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhypercubed%2Fboostarray/lists"}