math-problems
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

math-problems

Solve math problems easily with this utility library. Includes temperature conversions, geometric area calculations, number utilities, and population statistics.

Installation

npm install math-problems

Usage

import {
  area,
  toCelsius,
  isEven,
  populationDensity,
  population,
} from 'math-problems';

// Calculate the area of a circle with radius 5
console.log(area.circle(5)); // 78

// Convert 73°F to Celsius
console.log(toCelsius(73)); // 22.777... (repeating decimal)

// Check if a number is even
console.log(isEven(4)); // true

// Calculate population density
console.log(populationDensity(11452000, 1483)); // 7724

// Access population data
console.log(population.br.sp); // 11452000

API Documentation

📐 Area Calculations

All area functions return an object with a floored area value.

  • Rectangle
    rect(base: number, height: number)
    area.rect(4, 5) ➔ 20

  • Triangle
    triangle(base: number, height: number)
    area.triangle(4, 5) ➔ 10

  • Rhombus
    rhombus(D: number, d: number)
    area.rhombus(8, 6) ➔ 24

  • Trapezoid
    trapezoid(B: number, b: number, height: number)
    area.trapezoid(10, 6, 5) ➔ 40

  • Circle
    circle(radius: number)
    area.circle(3) ➔ 28

🌡️ Temperature Conversions

Convert between Celsius (°C), Fahrenheit (°F), and Kelvin (K).

  • toCelsius
    toCelsius(temperature: number, unit?: 'F' | 'K')
    Default unit: Fahrenheit
    toCelsius(32) ➔ 0
    toCelsius(273.15, 'K') ➔ 0

  • toFahrenheit
    toFahrenheit(temperature: number, unit?: 'C' | 'K')
    Default unit: Celsius
    toFahrenheit(0) ➔ 32
    toFahrenheit(273.15, 'K') ➔ 32

  • toKelvin
    toKelvin(temperature: number, unit?: 'C' | 'F')
    Default unit: Celsius
    toKelvin(0) ➔ 273
    toKelvin(32, 'F') ➔ 273

🔢 Number Utilities

  • isEven(number)
    Returns true if the number is even.

  • isOdd(number)
    Returns true if the number is odd.

  • difference(x, y)
    Returns the floored difference between two numbers.
    difference(10, 3.8) ➔ 6

  • PI
    Math.PI constant (≈3.14159).

📊 Interpoolation and regression

  • interpolation(input: { function: (number) => number, value: number, points: number[] })
    Interpolates a set of data points from a function and value through Newton Interpolation.
interpolation({
  function: Math.log,
  value: 2,
  points: [1, 4, 6]
})

 0.5658443469009827
  • regression(input: number[])
    Computes the linear and polynomial regression from a set of data points.
regression([
  [-2, -1],
  [1, 2],
  [4, 59],
  [-1, 4],
  [3, 24],
  [-4, -53]
]);

 {
  linear: {
    m: 10.97864768683274,
    b: 4.00355871886121
  },
  polynomial: {
    a: 6.689189189189188,
    b: 11.060810810810809,
    c: -0.34459459459459435
  }
}

📊 Population Statistics

  • populationDensity(population, area)
    Returns density (people per unit area).

  • birthRate(births, population)
    Returns births per 1000 people.

  • deathRate(deaths, population)
    Returns deaths per 1000 people.

  • Population Data
    Pre-defined population figures (as of Feb 2025):

    population.br.sp; // Brazil São Paulo: 11,452,000
    population.us.ny; // USA New York: 20,201,249

Contributing

Contributions are welcome! Please follow the contribution guidelines.

  1. Clone the repository:
    git clone https://github.com/igorwastaken/math-utils.git
  2. Install dependencies:
    npm install
  3. Run tests:
    npm test

License

MIT © Igor Figueiredo
Full License Text

Package Sidebar

Install

npm i math-problems

Weekly Downloads

17

Version

0.2.0

License

MIT

Unpacked Size

38.3 kB

Total Files

7

Last publish

Collaborators

  • igorwastaken