Created
April 26, 2021 19:38
-
-
Save passandscore/dd4544fd993c80d5a769a66edb5aaddf to your computer and use it in GitHub Desktop.
Convert an Array to a Linked List
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 linkedList(arr) { | |
return arr.reduceRight((next, value) => ({ value, next }), null); | |
} | |
let l = [3, 1, 2, 3, 4, 5]; | |
console.log(linkedList(l)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment