- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Equal partition of an array of numbers - JavaScript
- Check if some elements of array are equal JavaScript
- How to check two numbers are approximately equal in JavaScript?
- Group array by equal values 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?
- How to convert array of strings to array of numbers in JavaScript?
- Special type of sort of array of numbers in JavaScript
- Are mean mode of a dataset equal in JavaScript
- Taking part from array of numbers by percent JavaScript

Advertisements