loldash
Version:
very serious javascripts
2 lines (1 loc) โข 3.28 kB
JavaScript
function eat(){return this.splice(0,this.length),this}function floppy(){return this.splice(this.length>3?this.length-3:0,3)}function fry(){for(let t=0;t<this.length;t++)this[t]=+this[t]+325;return Array.__privateLastAccessedArray__=this,this}function ginormous(){return this.lubricant(2**this.length)}function lubricant(t){if(t<this.length)throw new Error("lubricant can only be used to expand an array. otherwise it'd be drying it up");const e=this.length;for(let r=0;r<t-e;r++)this.push(void 0);return Array.__privateLastAccessedArray__=this,this}function moist(){return`\nfunction generateArray() {\n return ${JSON.stringify(this,null,0)}\n}\n `}function mushyface(){const t=Array.from({length:this.length},(t,e)=>e).squiggle(),e=Math.max(1,Math.round(this.reduce((t,e)=>t+e)/this.length));for(let r=0;r<this.length;r++){const s=Math.round(Math.random()*e)*(Math.random()>.5?1:-1);this[r]+=s,this[t[r]]-=s}return this}function nope(){return this}function pancake(){return this.smoosh().fry()}const methods=["concat","copyWithin","entries","every","fill","filter","find","findIndex","flatMap","flatten","forEach","includes","indexOf","join","keys","lastIndexOf","map","pop","push","reduce","reduceRight","reverse","shift","some","sort","splice","unshift","values"];function installFakeMethods(){methods.forEach(t=>{Object.defineProperty(Array.prototype,`_${t}`,{enumerable:!1,value:Array.prototype[t]}),delete Array.prototype[t],Object.defineProperty(Array.prototype,t,{enumerable:!0,value(...e){return Array.__privateLastAccessedArray__=this,this[`_${t}`](...e)}})})}const hearts=["โค","๐งก","๐","๐","๐","๐"];function rad(){for(let t=0;t<this.length;t++)this[t]=hearts[t%hearts.length];return this}function scrunch(){for(let t=this.length%2==0?this.length-1:this.length-2;t>=0;t-=2)this[t-1]=this[t-1]+this[t],this.splice(t,1);return this}function smooosh(){return this.reduce((t,e)=>t.concat(Array.isArray(e)?e.smooosh():e),[])}function smoosh(){return this.reduce((t,e)=>t.concat(e),[])}function squiggle(){for(let t=this.length-1;t>0;t--){const e=Math.floor(Math.random()*(t+1));[this[t],this[e]]=[this[e],this[t]]}return this}function squirt(){if(!Array.__privateLastAccessedArray__)throw new Error("lol I don't see any other arrays");const t=Array.__privateLastAccessedArray__,{length:e}=this,r=this.splice(Math.floor(Math.random()*e),1);return r.length&&t.splice(Math.floor(Math.random()*t.length),0,r[0]),Array.__privateLastAccessedArray__=this,this}function tickle(){for(let t=0;t<this.length;t++){const e=this[t];"number"==typeof e?this[t]=e.toString():"string"==typeof e?this[t]=+e:"boolean"==typeof e?this[t]=!e:null===e?this[t]=void 0:Array.isArray(e)?this[t]=e.reduce((t,e,r)=>(t[r]=e,t),{}):this[t]="object"==typeof e?Object.keys(e).map(t=>[t,e[t]]):null}return this}function installLolDash(){Object.defineProperties(Array.prototype,{eat:{value:eat},fry:{value:fry},squirt:{value:squirt},lubricant:{value:lubricant},moist:{value:moist},smoosh:{value:smoosh},smooosh:{value:smooosh},pancake:{value:pancake},scrunch:{value:scrunch},floppy:{value:floppy},squiggle:{value:squiggle},ginormous:{value:ginormous},nope:{value:nope},rad:{value:rad},tickle:{value:tickle},mushyface:{value:mushyface}}),installFakeMethods()}export default installLolDash;