Created
May 13, 2014 10:41
-
-
Save piecyk/6f228bf2f8af25cda3b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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