Skip to content

Instantly share code, notes, and snippets.

@passandscore
Created April 26, 2021 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passandscore/dd4544fd993c80d5a769a66edb5aaddf to your computer and use it in GitHub Desktop.
Save passandscore/dd4544fd993c80d5a769a66edb5aaddf to your computer and use it in GitHub Desktop.
Convert an Array to a Linked List
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