Answers for "Check if two arrays are equal or not"

4

check if numpy arrays are equal

(A==B).all()
Posted by: Guest on July-23-2020
0

check if 2 arrays are equal javascript

var arraysMatch = function (arr1, arr2) {

	// Check if the arrays are the same length
	if (arr1.length !== arr2.length) return false;

	// Check if all items exist and are in the same order
	for (var i = 0; i < arr1.length; i++) {
		if (arr1[i] !== arr2[i]) return false;
	}

	// Otherwise, return true
	return true;

};
Posted by: Guest on December-07-2020
0

example to check two integer array are equal in java?

import java.util.Arrays;

public class JavaArrayConceptsConitnue
{
	public static void main(String[] args)
	{
		int[] x = {10,12,20,30,25};
		int[] subx = new int[]{10,12,20,30,26};
		
		if(Arrays.equals(x, subx) == true)
		{
			System.out.println("Both the arrays are equal");
		}
		else
		{
			System.out.println("Arrays are not equal");
		}
	}
}
Posted by: Guest on July-05-2020
0

Check if two arrays are equal or not

function isEqual(arr1,arr2){
  let x = arr1.length;
  let y = arr2.lenght;
  
  //if lenght of array are not equal means array are not equal 
  if(x !=  y) return false;
  
  //sorting both array
  x.sort();
  y.sort();
  
  // Linearly compare elements
  for(let i=0;i<x;i++){
    if(x[i] != y[i]) return false
  }
  // If all elements were same.
    return true
}
 
let arrayOne = [3, 5, 2, 5, 2]
let arrayTwo = [2, 3, 5, 5, 2]
 
isEqual(arrayOne,arrayTwo) ? console.log("Matched") : console.log("Not Match")
Posted by: Guest on October-28-2021
-1

equal elements in two arrays in c++

bool equalelementsintwoarrays(int A[], int B[], int N) {
    sort(A, A+N);
    sort(B, B+N);
    int i = 0, j = 0;
    while (i < N && j < N) {
        if (A[i] == B[j]) return true;
        else if (A[i] > B[j]) j++;
        else i++;
    }
    return false;
}
Posted by: Guest on July-01-2020

Code answers related to "Check if two arrays are equal or not"

Browse Popular Code Answers by Language