Amount
max
1.0.0- Dependencies:
- ∟Direct: 0
- ∟Peer: 0
- Source code ↗
- Check on NPM ↗
Hidden
Overview
Section titled “Overview”Finds the maximum amount from an AmountArray by comparing the values of all amounts in the array.
amountArray.max();Features
Section titled “Features”- Returns a new
Amountinstance with the largest value - Requires all amounts to have the same currency
- Maintains immutability - original array remains unchanged
- Compares amounts based on their cent values
- Throws error for empty arrays or mixed currencies
- Simple and intuitive API
- Comprehensive testing
Arguments
Section titled “Arguments”| Arg | Type | Default Value | Required |
| No arguments required | |||
From an AmountArray instance, use the max() method to find the amount with the largest value.
import { amount, AmountArray } from '@inpulse-ui/utils';
const amounts = new AmountArray( amount(100, 'USD'), amount(50, 'USD'), amount(200, 'USD'), // Maximum value amount(75, 'USD'));
const result = amounts.max();
console.log(result); // Results in Amount instance with value 200 USDIt requires all amounts to have the same currency:
const validAmounts = new AmountArray( amount(33.33, 'EUR'), amount(33.34, 'EUR'), // Maximum value amount(33.32, 'EUR'));
const result = validAmounts.max();
console.log(result); // Results in Amount instance with value 33.34 EURIt throws an error for mixed currencies:
const mixedAmounts = new AmountArray( amount(100, 'USD'), amount(150, 'EUR') // Different currency);
// This will throw: "All amounts must have the same currency for min/max operations."const result = mixedAmounts.max();It throws an error for empty arrays:
const emptyArray = new AmountArray();
// This will throw: "AmountArray must be non-empty."const result = emptyArray.max();Works with negative values:
const amountsWithNegatives = new AmountArray( amount(-100, 'GBP'), amount(-50, 'GBP'), // Maximum value (least negative) amount(-75, 'GBP'));
const result = amountsWithNegatives.max();
console.log(result); // Results in Amount instance with value -50 GBPExamples
Section titled “Examples”Imagine a scenario in an e-commerce application. Based on store settings, you need to find the highest installment amount to present at checkout.
import { amount } from '@inpulse-ui/utils';
// Customer's shopping cart totalconst cartTotal = amount(1000, 'USD');
// Split into 6 installments using split() methodconst installments = cartTotal.split(6);
console.log(installments); // AmountArray with 6 installment amounts
// Store setting: Apply discount to the lowest installment// Need to find the highest installment to maintain profit marginsconst highestInstallment = installments.max();
console.log(`Highest installment: ${highestInstallment}`);// Use this value to ensure discount doesn't exceed acceptable limitsBuilt with by Jo Santana in Brazil.
© 2026 Inpulse. All rights reserved.