

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Are array of numbers equal - JavaScript
We are required to write a JavaScript function that takes in two arrays of Numbers, say first and second and checks for their equality.
The arrays will be considered equal if −
- They contain the same elements and in the same order.
- The product of all the elements of the first array and second array is equal.
The first array of numbers −
const first = [3, 5, 6, 7, 7];
The second array of numbers −
const second = [7, 5, 3, 7, 6];
Example
Following is the code −
const first = [3, 5, 6, 7, 7]; const second = [7, 5, 3, 7, 6]; const isEqual = (first, second) => { const prodFirst = first.reduce((acc, val) => acc*val); const prodSecond = second.reduce((acc, val) => acc*val); if(prodFirst === prodSecond){ return true; }; for(let i = 0; i < firstCopy.length; i++){ if(first[i] === second[1]){ continue; }; return false; }; return true; }; console.log(isEqual(first, second));
Output
This will produce the following output in console −
true
- Related Questions & Answers
- Equal partition of an array of numbers - JavaScript
- Check if some elements of array are equal JavaScript
- Group array by equal values JavaScript
- Are mean mode of a dataset equal in JavaScript
- Transforming array of numbers to array of alphabets using JavaScript
- Summing array of string numbers using JavaScript
- Parse array to equal intervals in JavaScript
- Array thirds with equal sums in JavaScript
- Converting array of Numbers to cumulative sum array in JavaScript
- Make array numbers negative JavaScript
- Split an array of numbers and push positive numbers to JavaScript array and negative numbers to another?
- Getting equal or greater than number from the list of numbers in JavaScript
- Finding two numbers that produce equal to the sum of rest in JavaScript
- Special type of sort of array of numbers in JavaScript
- Equal Rational Numbers in C++
Advertisements