JSFiddle - React, Tailwind, and code Playground
HTML
<ul>
<li><a href="https://teratail.com/questions/42302">JavaScript - 特定の配列を内包する配列を検知したい(42302)|teratail</a></li>
</ul>
JavaScript
'use strict';
function arrayIn (array, innerArray) {
return array.reduce(function (previous, current) {
var i = previous.indexOf(current);
if (i !== -1) {
previous.splice(i, 1);
}
return previous;
}, [].concat(innerArray)).length === 0;
}
console.log(arrayIn([1, 1, 3, 4, 5], [1, 2])); // false
console.log(arrayIn([1, 3, 4, 5], [1, 1])); // false
console.log(arrayIn([1, 3, 4, 2], [1, 2])); // true
console.log(arrayIn([1, 2, 3, 4, 5], [1, 2])); // true