Created
March 9, 2018 05:42
-
-
Save Pritoj/1c6cd79b9eeb647866920c27ca187f33 to your computer and use it in GitHub Desktop.
Array extensions inspired by this tweet https://twitter.com/AntJanus/status/971634313136451584
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array hug, one array hugs the other | |
// If the hugger is odd numbered, more in the front | |
Array.prototype.hug = function(arr){ | |
let hugged = this.slice(0,Math.ceil(this.length/2)); | |
hugged.push(...arr); | |
hugged.push(...this.slice(Math.ceil(this.length/2), this.length)); | |
return hugged; | |
} | |
// Array spoon, one array spoons the other | |
// If the spooner is odd numbered, more in the back | |
Array.prototype.spoon = function(arr){ | |
let hugged = this.slice(0,Math.floor(this.length/2)); | |
hugged.push(...arr); | |
hugged.push(...this.slice(Math.floor(this.length/2), this.length)); | |
return hugged; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment