6 kyu
Find within array
2,517 of 3,574kylehill
Description:
We'll create a function that takes in two parameters:
- a sequence (length and types of items are irrelevant)
- a function (value, index) that will be called on members of the sequence and their index. The function will return either true or false.
Your function will iterate through the members of the sequence in order until the provided function returns true; at which point your function will return that item's index.
If the function given returns false for all members of the sequence, your function should return -1.
var trueIfEven = function(value, index) { return (value % 2 === 0) };
findInArray([1,3,5,6,7], trueIfEven) // should === 3
Arrays
Functional Programming
Fundamentals
Similar Kata:
Stats:
Created | Jul 25, 2013 |
Published | Jul 26, 2013 |
Warriors Trained | 6234 |
Total Skips | 591 |
Total Code Submissions | 15104 |
Total Times Completed | 3574 |
JavaScript Completions | 2517 |
Python Completions | 995 |
Groovy Completions | 36 |
Ruby Completions | 50 |
Total Stars | 68 |
% of votes with a positive feedback rating | 84% of 521 |
Total "Very Satisfied" Votes | 388 |
Total "Somewhat Satisfied" Votes | 103 |
Total "Not Satisfied" Votes | 30 |