Skip to content

Instantly share code, notes, and snippets.

@railsstudent
Created December 23, 2016 15:49
Show Gist options
  • Save railsstudent/6227db21298a68e06272b12a2e4e4a2f to your computer and use it in GitHub Desktop.
Save railsstudent/6227db21298a68e06272b12a2e4e4a2f to your computer and use it in GitHub Desktop.
function loop_size(node){
var visitedNodes = [];
var idx = -1;
while (node != null) {
idx = visitedNodes.indexOf(node);
if (idx < 0) {
visitedNodes.push(node);
} else {
break;
}
node = node.getNext();
}
return (visitedNodes.length - idx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment