Hi guys,
I'm trying to complete a function that does the following:
/* Tests if all balls selected match all balls drawn in the same order
The function takes two arguments:
an array of drawn balls
an array of selected balls.
The function code compares each ball in one array with the ball at the same position in the other array.
The function returns:
true if the arrays contain the same numbers in the same order
false otherwise.
*/
The code I have written is
I have two arrays drawnBalls and selectedBalls, which will both be the same length and need to check if the numbers in the arrays match in the sameorder.
Instead of returning an overall return of true or false if all the balls match, it is looping, giving me a separate result for each element. Can anyone give me some guidance on how to achieve my overall objective of, simply returning true if the values in the array are the same and in the same order, and false otherwise. Thanks in advance for any help.
I'm trying to complete a function that does the following:
/* Tests if all balls selected match all balls drawn in the same order
The function takes two arguments:
an array of drawn balls
an array of selected balls.
The function code compares each ball in one array with the ball at the same position in the other array.
The function returns:
true if the arrays contain the same numbers in the same order
false otherwise.
*/
The code I have written is
Code:
{
for (var index = 0; index < drawnBalls.length; index = index + 1)
{
if(drawnBalls[index] == selectedBalls[index])
{
return true;
}
else
{
return false;
}
}
}
Instead of returning an overall return of true or false if all the balls match, it is looping, giving me a separate result for each element. Can anyone give me some guidance on how to achieve my overall objective of, simply returning true if the values in the array are the same and in the same order, and false otherwise. Thanks in advance for any help.
Comment