Searching
import std.algorithm.searching;
all (array, func)-> bool | Check a predicate on all the element of an array
- Parameters:
- array, an array
- func, a function fn (x)-> bool, where x has the same type as an element of array
- Example:
assert (([1, 2, 3]).all (fn (x) => x < 4)); assert (!([3, 2, 8]).all (fn (x) => x % 2 == 0));
- Parameters:
any (array, func)-> bool | Check if it exists an element in array that satisfy the predicate
- Parameters :
- array, an array
- func, a function fn (x)-> bool, where x has the same type as an element of array
- Example:
assert (([1, 2, 3]).any (fn (x) => x < 3)); assert (!([2, 4, 8]).any (fn (x) => x % 2 == 1));
- Parameters :
countUntil (a, b)-> int | Count until b is found in a
- Parameters :
- a, an array
- b, an array, where b elements have the operator
!=
with the type of the elements of a
- Example:
let a = "Hello World !!"; assert (a.countUntil ("World") == 6);
- Parameters :
count (a, b)-> int | Count the number of occurence of b element in a
- Parameters :
- a, an array
- b, an element that possesses the operator
==
with a elements
- Example :
let a = [1, 2, 2, 4, 2]; assert (a.count (2) == 3);
- Parameters :
countPred (a, func)-> int | Same as count but using a predicate
- Parameters :
- a, an array
- b, a function fn (x)-> bool, where x has the same type as an element of a
- Example :
let a = [1, 3, 6, 9]; assert (a.countPred (fn (x)=> x % 2 == 1) == 3);
- Parameters :
canFind (a, b)-> bool | Returns :
true
if countUntil (a, b) != a.lencommonPrefix (a, b)-> any | Returns: the common prefix of a and b
- Parameters :
- a, an array
- b, an array
- Example :
assert (commonPrefix ("Hello World", "Hello Bob") == "Hello ");
- Parameters :
endsWith (a, b)-> bool | Returns:
true
if a end with b- Parameters :
- a, an array
- b, an array
- Example :
let a = "file.txt"; assert (a.endsWith (".txt"));
- Parameters :
find (a, b)-> int | Returns : the index of the element b in a or
-1
, if b is not in a- Parameters :
- a, an array
- b, an element
- Example :
assert (([1, 2, 3]).find (2) == 1); assert (([1, 2, 3]).find (7) == -1);
- Parameters :
findPred (a, func)-> int | Returns : The index of the first element that satisfy the predicate
- Parameters :
- a, an array
- func, a function fn (x)-> bool, where x has the same type as an element of a
- Example :
let a = [1, 2, 3]; assert (a.findPred (fn (x)=> x % 2 == 0) == 1);
- Parameters :
minElement (a)-> any | Returns : the minimal element of the array a
- Example :
assert (([5, 2, 7, 9]).minElement () == 2);
- Example :
minIndex (a)-> any | Returns : the index of the minimal element of the array a
- Example :
assert (([5, 2, 7, 9]).minElement () == 1);
- Example :
maxElement (a)-> any | Returns : the maximal element of the array a
- Example :
assert (([5, 2, 7, 9]).minElement () == 9);
- Example :
minIndex (a)-> any | Returns : the index of the maximal element of the array a
- Example :
assert (([5, 2, 7, 9]).minElement () == 3);
- Example :