Last active
March 2, 2020 18:26
-
-
Save EliaECoyote/6e2886be91c31e4cf4d2f3f0fd426fd9 to your computer and use it in GitHub Desktop.
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
function makeStack() { | |
let head = null | |
function push(item) { | |
if (head == null) head = { value: item } | |
else head = { value: item, next: head } | |
} | |
function isEmpty() { | |
return head == null | |
} | |
function peek() { | |
return head ? head.value : null | |
} | |
function pop() { | |
const value = head ? head.value : null | |
if (value) head = head.next | |
return value | |
} | |
return { isEmpty, push, peek, pop } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment