Skip to content

Instantly share code, notes, and snippets.

@Akjosch
Last active October 25, 2021 11:39
Show Gist options
  • Save Akjosch/fb6a6897f974649730c9bcf33e6f3ddb to your computer and use it in GitHub Desktop.
Save Akjosch/fb6a6897f974649730c9bcf33e6f3ddb to your computer and use it in GitHub Desktop.
Array extension methods for SugarCube, quick & dirty version
"use strict";Object.defineProperty(Array.prototype,"countWith",{configurable:!0,writable:!0,value:function value(predicate,thisArg){if(null==this)throw new TypeError("Array.prototype.countWith called on null or undefined");if("function"!=typeof predicate)throw new Error("Array.prototype.countWith predicate parameter must be a function");var length=this.length>>>0;if(0==length)return[];for(var count=0,i=0;i<length;++i)count+=!!predicate.call(thisArg,this[i],i,this);return count}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment