Skip to content

Instantly share code, notes, and snippets.

@kraftdorian
Created April 3, 2021 19:08
Show Gist options
  • Save kraftdorian/fea66059d6e3b1932ff7b84936ddd29d to your computer and use it in GitHub Desktop.
Save kraftdorian/fea66059d6e3b1932ff7b84936ddd29d to your computer and use it in GitHub Desktop.
Prolog style list in JavaScript
const usePrologStyleList = (array) => {
const [head, ...tail] = array;
return [head, tail];
};
@kraftdorian
Copy link
Author

Use case:

const [head, tail] = usePrologStyleList([1, 2, 3]);
console.log(head, tail);

Result:

1 [ 2, 3 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment