The mismatch() function loops through an array’s elements and compares each of its values with that of another array.
It is a built-in method in the D language.
It is part of the std.algorithm
module.
The mismatch()
method carries out a lockstep comparison of two arrays.
This comparison ends when the first mismatch is encountered, and both arrays are returned as members of a tuple.
The returned arrays will have elements only from the point where the first mismatch was found.
For instance, the mismatch()
operation output of arrays A =[1,2,3,4, 5] and B = [1,2,4,6] will be a tuple
P = [[3,4,5],[4,6]].
mismatch(comparison_conditon, value_a, value_b)
comparison_conditon : By default, this parameter is equality. A mismatch is where an element of value_a
and value_b
at the same index position is not equal. This is an optional parameter.
value_a : This is one of the values to compare.
value_b : This is the second value for comparison.
It returns a tuple. The value of this tuple is both the compared arrays. The element of this array will be the elements from the point of mismatch in both arrays to the end/last index.
In the code below, the mismatch value between arr_a
and arr_b
is computed:
import std.algorithm;import std.stdio;void main(){//define variablesint[6] arr_a = [4, 5, 6, 7, 8, 9 ];float[6] arr_b = [ 4, 5, 6, 7.3, 4, 9 ];auto tuple_output = mismatch(arr_a[], arr_b[]);//output the whole tuplewriteln(tuple_output);//output individual member of the tupplewriteln(tuple_output[0]); // arr_a[7 .. $]writeln(tuple_output[1]); // arr_b[7.3.. $]}
std.algorithm
is the module with the mismatch()
function.main
function that encloses the whole program.arr_a
and arr_b
, that will be compared.tuple_output
.