Skip to content

Instantly share code, notes, and snippets.

@grundmanise
Last active June 1, 2017 16:27
Show Gist options
  • Save grundmanise/2bbf89ff848fc3a94864eee843185d3b to your computer and use it in GitHub Desktop.
Save grundmanise/2bbf89ff848fc3a94864eee843185d3b to your computer and use it in GitHub Desktop.
function getLinkedListLength(A = [1,4,-1,3,2]) {
let count = 0;
let current = 0;
while(current !== -1) {
if (A.length < current)
throw Error(`No link found for value: ${current}. Count: ${count}`);
current = A[current];
count++;
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment