Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/writetome51/arrays-match
An array-comparison function
https://github.com/writetome51/arrays-match
arrays comparison comparison-tool javascript match matching
Last synced: 3 days ago
JSON representation
An array-comparison function
- Host: GitHub
- URL: https://github.com/writetome51/arrays-match
- Owner: writetome51
- License: mit
- Created: 2018-09-26T05:48:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-24T03:10:32.000Z (almost 4 years ago)
- Last Synced: 2024-11-08T22:39:26.175Z (about 2 months ago)
- Topics: arrays, comparison, comparison-tool, javascript, match, matching
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm version](https://badge.fury.io/js/%40writetome51%2Farrays-match.svg)](https://badge.fury.io/js/%40writetome51%2Farrays-match) ![NpmLicense](https://img.shields.io/npm/l/%40writetome51%2Farrays-match.svg) ![npm](https://img.shields.io/npm/dw/%40writetome51%2Farrays-match.svg)
# arraysMatch(array1, array2): boolean
If `array1` and `array2` match, returns true.
It automatically handles checking nested arrays.How the matching is done:
If `(array1 === array2)`, returns true.
Else, it tries element-by-element matching:
if `array1[i] === array2[i]` for every `i` in `array1` and `array2`, it's a match.
If `array1[i]` and `array2[i]` are both arrays of equal length, they're passed
into a recursive function call.## Examples
```js
arraysMatch([], []); // truearraysMatch(['h', 'j'], ['h', 'j']); // true
arraysMatch(['h', 'j'], ['h', 'j', 'k']); // false
arraysMatch([1, 2, [3]], [1, 2, [3]]); // true
let obj = {prop: 1};
arraysMatch([obj], [{prop:1}]); // falsearraysMatch([obj], [obj]); // true
let obj2 = obj;
arraysMatch([obj], [obj2]); // true
```## Installation
`npm i @writetome51/arrays-match`## Loading
```js
import {arraysMatch} from '@writetome51/arrays-match';
```