7 kyu
Fun with lists: indexOf
1,016 of 2,008janitormeir
Description:
Implement the method indexOf (index_of
in PHP), which accepts a linked list (head) and a value, and returns the index (zero based) of the first occurrence of that value if exists, or -1 otherwise.
For example:
Given the list: 1 -> 2 -> 3 -> 3
, and the value 3, indexOf / index_of
should return 2.
The linked list is defined as follows:
function Node(data, next = null) {
this.data = data;
this.next = next;
}
Note: the list may be null and can hold any type of value.
Good luck!
This kata is part of fun with lists series:
Lists
Fundamentals
Similar Kata:
Stats:
Created | Nov 4, 2016 |
Published | Nov 4, 2016 |
Warriors Trained | 3895 |
Total Skips | 186 |
Total Code Submissions | 7745 |
Total Times Completed | 2008 |
JavaScript Completions | 1016 |
Java Completions | 628 |
PHP Completions | 136 |
C Completions | 106 |
Python Completions | 234 |
Total Stars | 41 |
% of votes with a positive feedback rating | 93% of 410 |
Total "Very Satisfied" Votes | 365 |
Total "Somewhat Satisfied" Votes | 36 |
Total "Not Satisfied" Votes | 9 |
Total Rank Assessments | 8 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |