Last active
November 30, 2022 04:43
-
-
Save joshuakfarrar/cdc43da25ee65ace176bb769e02e5385 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
// source: https://stackoverflow.com/questions/71608818/purely-functional-immutable-doubly-linked-list-in-javascript | |
var head = (function CircularList(previous, item, ...items) { | |
if (!items.length) return { item, next: () => head, previous }; | |
var rest = CircularList(() => current, ...items); // Recursion | |
var current = { ...rest, previous }; | |
return { ...rest, item, next: () => current }; | |
})(() => head, 1, 2, 3, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment