
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Quickest Way to get the Maximum Value of an Array of Numbers (Typed or Untyped)
:fire: The Quickest Way to get the Maximum Value of an Array of Numbers (Typed or Untyped)
npm install fast-max
This library excels with typed arrays. It takes into account the theoretical maximum of a typed array. For example, if you have a Uint8Array, it's not possible for a maximum value to be greater than 255, so if we encounter a 255 in the array, we can stop searching for a higher value.
const fastMax = require("fast-max"); // or import max from "fast-max";
const result = fastMax([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// result is 10
const fastMax = require("fast-max");
const pixel_values = Uint8Array.from([0, 128, 255, 34, ...]);
const result = fastMax(pixel_values);
// result is 255
If you know that an array's values can't exceed a specific number, you can set the theoretical_max.
const fastMax = require("fast-max");
const numbers = [0, 9, 4, 2, 10, ...]);
const result = fastMax(numbers, { theoretical_max: 10 });
// result is 10
If you want to ignore one or more specific values, you can set the no_data value.
const fastMax = require("fast-max");
const numbers = [99, 0, 7, 99, 5, ...];
const result = fastMax(numbers, { no_data: 99 });
// result is 7
const result = fastMax(numbers, { no_data: [7, 99] });
// result is still 5
Here are test results comparing fast-max to two other popular libraries underscore and lodash. Tests have been conducted by creating an array of ten million random numbers from zero to the maximum theoretical value of the typed array.
| array type | library | average duration in milliseconds |
|---|---|---|
| Int8Array | fast-max | < 1 |
| Int8Array | lodash | 20.9 |
| Int8Array | underscore | 14.3 |
| Uint8Array | fast-max | 0.1 |
| Uint8Array | lodash | 21.4 |
| Uint8Array | underscore | 14.3 |
| Int16Array | fast-max | 1.4 |
| Int16Array | lodash | 21 |
| Int16Array | underscore | 13.7 |
| Uint16Array | fast-max | 1.9 |
| Uint16Array | lodash | 20.9 |
| Uint16Array | underscore | 13.8 |
| Int32Array | fast-max | 31.2 |
| Int32Array | lodash | 21.2 |
| Int32Array | underscore | 14.2 |
| Uint32Array | fast-max | 109.8 |
| Uint32Array | lodash | 73.3 |
| Uint32Array | underscore | 15 |
| BigInt64Array | fast-max | 115.4 |
| BigInt64Array | lodash | 237.5 |
| BigInt64Array | underscore | 222.4 |
| BigUint64Array | fast-max | 113.9 |
| BigUint64Array | lodash | 236.4 |
| BigUint64Array | underscore | 219.7 |
FAQs
Quickest Way to get the Maximum Value of an Array of Numbers (Typed or Untyped)
We found that fast-max demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.