The Javascript BigUint64Array findIndex()
method searches an index in the typed array by the provided testing function.
-1 is returned if not found.
BigUint64Array.findIndex(callback[, thisArg])
Parameter | Optional | Meaning |
---|---|---|
callback | Required | Function to execute on each value Taking three arguments: element - the current element being processed. index - the index of the current element. array - the typed array itself. |
thisArg | Optional | Object to use as this when executing callback. |
Find the index of a prime number in a typed array
function isPrime(element, index, array) { var start = 2;// w w w . ja v a2 s. co m while (start <= Math.sqrt(element)) { if (element % start++ < 1) { return false; } } return element > 1; } var uint8 = new BigUint64Array([12n, 5n, 8n, 130n, 44n]); console.log(uint8); var uint16 = new BigUint64Array([4, 6, 7, 12]); console.log(uint16); console.log(uint8.findIndex(isPrime)); console.log(uint16.findIndex(isPrime));