I have the following array of numbers:
1. [2, 4, 6, 8]
2. [4, 2, 5, 7]
I need to check whether or not each number of the first array is included in the second array. In that case, a function needs to return true
. If at least one number of the first array is not included in the second array, the function needs to return false
.
I can do this by comparing each pairs of numbers, but that doesn't seem the most computationally efficient function. What would be the most gas-efficient way to achieve this in Solidity?
UPD: The first array numbers are function inputs, the second array numbers are global variables.
O(n*log n)
instead ofO(n^2)
), but requires changing state variables, which would ultimately consume a lot of gas. – goodvibration Oct 14 '18 at 12:39