Skip to content

Amount

min

1.0.0

Finds the minimum amount from an AmountArray by comparing the values of all amounts in the array.

amountArray.min();
  • Returns a new Amount instance with the smallest 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
ArgTypeDefault ValueRequired
No arguments required

From an AmountArray instance, use the min() method to find the amount with the smallest value.

import { amount, AmountArray } from '@inpulse-ui/utils';
const amounts = new AmountArray(
amount(100, 'USD'),
amount(50, 'USD'), // Minimum value
amount(200, 'USD'),
amount(75, 'USD')
);
const result = amounts.min();
console.log(result); // Results in Amount instance with value 50 USD

It requires all amounts to have the same currency:

const validAmounts = new AmountArray(
amount(33.33, 'EUR'),
amount(33.34, 'EUR'),
amount(33.32, 'EUR') // Minimum value
);
const result = validAmounts.min();
console.log(result); // Results in Amount instance with value 33.32 EUR

It throws an error for mixed currencies:

const mixedAmounts = new AmountArray(
amount(100, 'USD'),
amount(50, 'EUR') // Different currency
);
// This will throw: "All amounts must have the same currency for min/max operations."
const result = mixedAmounts.min();

It throws an error for empty arrays:

const emptyArray = new AmountArray();
// This will throw: "AmountArray must be non-empty."
const result = emptyArray.min();

Works with negative values:

const amountsWithNegatives = new AmountArray(
amount(100, 'GBP'),
amount(-50, 'GBP'), // Minimum value
amount(25, 'GBP')
);
const result = amountsWithNegatives.min();
console.log(result); // Results in Amount instance with value -50 GBP

Imagine a scenario in an e-commerce application. Based on store settings, you need to find the lowest installment amount to present at checkout.

import { amount } from '@inpulse-ui/utils';
// Customer's shopping cart total
const cartTotal = amount(1000, 'USD');
// Split into 6 installments using split() method
const installments = cartTotal.split(6);
console.log(installments); // AmountArray with 6 installment amounts
// Store setting: Apply additional fee to the smallest installment
// Find the lowest installment to adjust pricing
const lowestInstallment = installments.min();
console.log(`Lowest installment: ${lowestInstallment}`);
// Use this value to add processing fees or adjust for rounding differences

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.