6 kyu
Fun with lists: countIf
744 of 1,581janitormeir
Description:
Implement the method countIf (count_if
in PHP and Python), which accepts a linked list (head) and a predicate function, and returns the number of elements which apply to the given predicate.
For example:
Given the list: 1 -> 2 -> 3
, and the predicate x => x >= 2
, countIf / count_if
should return 2, since x >= 2
applies to both 2 and 3.
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
Functional Programming
Fundamentals
Similar Kata:
Stats:
Created | Nov 1, 2016 |
Published | Nov 1, 2016 |
Warriors Trained | 2822 |
Total Skips | 313 |
Total Code Submissions | 3799 |
Total Times Completed | 1581 |
JavaScript Completions | 744 |
Java Completions | 437 |
PHP Completions | 103 |
C Completions | 102 |
Python Completions | 294 |
Total Stars | 46 |
% of votes with a positive feedback rating | 95% of 359 |
Total "Very Satisfied" Votes | 327 |
Total "Somewhat Satisfied" Votes | 27 |
Total "Not Satisfied" Votes | 5 |
Total Rank Assessments | 10 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |