npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-mathjss

v1.0.3

Published

A simple package for basic math operations and sorting algorithms

Downloads

9

Readme

Simple Math

Simple Math is a lightweight Node.js library for basic mathematical operations, including addition, subtraction, multiplication, division, factorial calculation, and the evaluation of mathematical expressions.

Installation

To use Simple Math in your Node.js project, you can install it using npm:

npm install simple-mathjss

Usage

Import the library

const simpleMath = require('simple-mathjss');
or
import {...} = require('simple-mathjss');

Functions

Addition

const sum = simpleMath.add(5, 3);
console.log(sum); // 8

Subtraction

const dif = simpleMath.sub(10, 3);
console.log(dif); // 7

Multiplication

const product = simpleMath.mul(4, 6);
console.log(product); // 24

Division

try {
  const div = simpleMath.div(8, 2);
  console.log(div); // 4
} catch (error) {
  console.error(error.message);
}

Factorial

const fact = simpleMath.factorial(5);
console.log(fact); // 120

Calculate Expression

const result = simpleMath.calc('2 * (3 + 4) / 5');
console.log(result); // 2.8

Sorting Algorithms

Bubble Sort

  • Description: Bubble Sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
  • Time Complexity: O(n^2)
const { bubbleSort } = require('simple-mathjss');

const unsortedArray = [4, 2, 7, 1, 3];
const sortedArray = bubbleSort(unsortedArray);
console.log(sortedArray); // [1, 2, 3, 4, 7]

Selection Sort

  • Description: Selection Sort divides the input list into two parts: the left subarray, which is sorted, and the right subarray, which is unsorted. It repeatedly selects the minimum element from the unsorted subarray and places it at the beginning of the sorted subarray.
  • Time Complexity: O(n^2)
const { selectionSort } = require('simple-mathjss');

const unsortedArray = [4, 2, 7, 1, 3];
const sortedArray = selectionSort(unsortedArray);
console.log(sortedArray); // [1, 2, 3, 4, 7]

Insertion Sort

  • Description: Insertion Sort builds the final sorted array one element at a time. It takes each element from the unsorted part and inserts it into its correct position in the sorted part.
  • Time Complexity: O(n^2)
const { insertionSort } = require('simple-mathjss');

const unsortedArray = [4, 2, 7, 1, 3];
const sortedArray = insertionSort(unsortedArray);
console.log(sortedArray); // [1, 2, 3, 4, 7]

Merge Sort

  • Description: Merge Sort divides the array in half, sorts each half, and then merges the sorted halves to produce a single sorted array.
  • Time Complexity: O(n log n)
const { mergeSort } = require('simple-mathjss');

const unsortedArray = [4, 2, 7, 1, 3];
const sortedArray = mergeSort(unsortedArray);
console.log(sortedArray); // [1, 2, 3, 4, 7]

Quick Sort

  • Description: Quick Sort selects a 'pivot' element and partitions the array into two sub-arrays according to the pivot. It then recursively sorts the sub-arrays.
  • Time Complexity: O(n log n) on average, O(n^2) in worst case
const { quickSort } = require('simple-mathjss');

const unsortedArray = [4, 2, 7, 1, 3];
const sortedArray = quickSort(unsortedArray);
console.log(sortedArray); // [1, 2, 3, 4, 7]

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

@thewyolar