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

arithmetik

v2.0.0

Published

basic arithmetic and algebra methods

Downloads

1

Readme

Arithmetik

About

This is one of my first contributions to the open source community that I have undertaken to learn how to create an NPM package. It is experimental and is used to build skills in learning a new technology. This package will allow users to perform basic arithmatic and algebra processes with minimal code. ENJOY!

1. Getting Started.

$ npm install arithmetik --save
const { average, pronumeral, multiply, addition } = require('arithmetik')

2. Four methods.

•addition – will add all the values of an array of numbers and give you its total.

•multiply- will multiply all the numbers of an array and give you its product.

•pronumeral- will find the missing lengths of a right triangle.

•average- will find the average of an array of numbers.

Addition, multiply, and average use a process of vetting your arrays to make sure that they are in fact arrays and also arrays of numbers. Any other data type introduced to any one of these methods will not be accepted as valid and an error will be thrown.

const arr = [8,12,37,63,1,22,68,97,4,77,2]
addition(arr) //==> 391
multiply(arr) //==> 20003111073792
average(arr) //==>195.5

Pronumeral is the only method that can take up to three parameters. Only two are required.

pronumeral(8,99) //==>99.32
//Here we enter an ‘a’ and a ‘b’ value and we have left ‘hypotenuse’, which is the third parameter, with its default of undefined. The method will then return ‘hypotenuse’.
pronumeral(undefined,10,23) //==>20.71
//Above we pass in undefined so that the method will return the value of the missing side.
pronumeral(8, undefined, 9) //==>4.12

It makes use of Javascript’s default parameter property. Two parameters would then be entered and a third value will be produced. For it to produce the answer that is desired the user must enter the values as they would appear on their right triangle i.e., a, b, or hypotenuse The numbers that are returned from the pronumeral method are always rounded up to the nearest hundredth. For example if the answer is 99.123344344 the rounded answer that the client should expect is 99.12.

3. _isNumericArray

This is a built-in method that is used by the others: addition, multiply, average. It performs checks on arrays that would otherwise make our code non-DRY. Currently it is only used for vetting arrays, making sure that they are in fact just arrays of numbers.

const _isNumericArray = (arr) => {
    if (Array.isArray(arr) === true) {
        if (arr.length < 2){
           throw new Error('Please enter a valid array of numbers.')
        }
        for (let a = 0; a < arr.length; a++) {
            if (typeof arr[a] !== 'number') {
               throw new Error('All items in array must be numbers.') 
            }
        }
    }
    else{
        throw new Error('Please enter a valid array of numbers.')
    }
}