Skip to content

Instantly share code, notes, and snippets.

@piecyk
Created May 13, 2014 10:41
Show Gist options
  • Select an option

  • Save piecyk/6f228bf2f8af25cda3b9 to your computer and use it in GitHub Desktop.

Select an option

Save piecyk/6f228bf2f8af25cda3b9 to your computer and use it in GitHub Desktop.
// task1
function solution(A) {
var pos = 0;
var len = 0;
while(A[pos] !== -1){
len++;
pos = A[pos];
}
return len;
}
console.log(solution([1, -1, -1, 3, 2]));//-1
console.log(solution([1, 4, -1, 3, 2])); // 3
console.log(solution([1, 4, 3, -1, 2])); // 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment