Array contains subarray

Benchmark created on


Setup

const a = []
const b = [];

for (let i = 0; i < 10; i++)
	a.push(i);
	
for (let i = 3; i <= 5; i++)
	b.push(i);

function isSubArrayF(x, y)
{
	let isSubArray;
	for (let i = 0; i < x.length; i++)
	{
		isSubArray = false;
		for (let j = 0; j < y.length; j++)
			if (x[i] === y[j])
			{
				isSubArray = true;
				break;
			}
			
		if (!isSubArray)
			return false;
	}
	
	return true;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Manual check
let isSubArray = true;
for (let i = 0; i < b.length && isSubArray; i++)
{
	isSubArray = false;
	for (let j = 0; j < a.length; j++)
		if (b[i] === a[j])
		{
			isSubArray = true;
			break;
		}
}
	
ready
Includes
for (let i = 0; i < b.length; i++)
{
	if (!a.includes(b[i]))
		break;
}
	
ready
Every
let isSubArray = b.every(el => a.includes(el));
ready
function
const isSubArray = isSubArrayF(b, a);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.