Last active
August 13, 2017 18:12
-
-
Save electerious/ec6f21da54f1afc0e7b8f7ddb67ad5e5 to your computer and use it in GitHub Desktop.
Array with a max number of items
This file contains hidden or 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
const fifo = (length) => { | |
const arr = [] | |
return (value) => { | |
if (value===undefined) return arr | |
if (arr.length>=length) arr.shift() | |
arr.push(value) | |
return arr | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: