Giter Site home page Giter Site logo

nodef / extra-number Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 463 KB

A number is a mathematical object used to count, measure, and label.

Home Page: https://www.npmjs.com/package/extra-number

License: MIT License

JavaScript 15.05% TypeScript 84.95%
extra number compare ceil floor aliquot-sum ceil-div floor-div binomial factorial

extra-number's Introduction

A number is a mathematical object used to count, measure, and label.
๐Ÿ“ฆ Node.js, ๐ŸŒ Web, ๐Ÿ“œ Files, ๐Ÿ“ฐ Docs. ๐Ÿ“˜ Wiki.

In JavaScript, Number type is double-precision 64-bit binary format IEEE 754 value. This package includes common number functions related to querying about numbers, comparing numbers, rounding numbers, performing rounded division, performing modulo operations, controlling range of numbers, performing arithmetic operations, obtaining divisors of a number (and related operations), getting the number of possible arrangements of a set of objects, performing geometry-related calculations, performing basic statistical analysis, and finding various statistical means.

This package is available in Node.js and Web formats. To use it on the web, simply use the extra_number global variable after loading with a <script> tag from the jsDelivr CDN.

Stability: Experimental.


const xnumber = require('extra-number');
// import * as xnumber from "extra-number";
// import * as xnumber from "https://unpkg.com/extra-number/index.mjs"; (deno)

xnumber.isPrime(53);
// โ†’ true

xnumber.properDivisors(6);
// โ†’ [1, 2, 3]

xnumber.round(9.1357, 0.05);
// โ†’ 9.15

xnumber.significantDigits(0.0034);
// โ†’ 2

// TOFIX:
// xnumber.fromRoman('DCXLIX');
// โ†’ 649

// xnumber.toScientific(695700000);
// โ†’ '6.957ร—10โธ' (radius of Sun in m)


Index

Property Description
is Check if value is a number.
significantDigits Count the number of significant digits in a number.
compare Compare two numbers.
floor Round down a number to specific precision.
ceil Round up a number to specific precision.
round Round a number to specific precision.
floorDiv Perform floor-divison of two numbers.
ceilDiv Perform ceiling-divison of two numbers.
roundDiv Perform rounded-divison of two numbers.
rem Find the remainder of x/y with sign of x (truncated division).
mod Find the remainder of x/y with sign of y (floored division).
modp Find the remainder of x/y with +ve sign (euclidean division).
constrain Constrain a number within a minimum and a maximum value.
normalize Normalize a number from its current range into a value between 0 and 1.
remap Re-map a number from one range to another.
lerp Linearly interpolate a number between two numbers.
isPow Check if a number is a power-of-n.
prevPow Find largest power-of-n less than or equal to given number.
nextPow Find smallest power-of-n greater than or equal to given number.
root Find the nth root of a number (โฟโˆš).
log Find the logarithm of a number with a given base.
properDivisors List all divisors of a number, except itself.
aliquotSum Sum all proper divisors of a number.
minPrimeFactor Find the least prime number which divides a number.
maxPrimeFactor Find the greatest prime number which divides a number.
primeFactors Find the prime factors of a number.
primeExponentials Find the prime factors and respective exponents of a number.
isPrime Check if number is prime.
gcd Find the greatest common divisor of numbers.
lcm Find the least common multiple of numbers.
factorial Find the factorial of a number.
binomial Find the number of ways to choose k elements from a set of n elements.
multinomial Find the number of ways to put n objects in m bins (n=sum(kแตข)).
degrees Convert radians to degrees.
radians Convert degrees to radians.
sum Find the sum of numbers (ฮฃ).
product Find the product of numbers (โˆ).
median Find the value separating the higher and lower halves of numbers.
modes Find the values that appear most often.
range Find the smallest and largest values.
variance Find the mean of squared deviation of numbers from its mean.
arithmeticMean Find the average of numbers.
geometricMean Find the geometric mean of numbers.
harmonicMean Find the harmonic mean of numbers.
quadriaticMean Find the quadriatic mean of numbers.
cubicMean Find the cubic mean of numbers.


References




ORG DOI Coverage Status Test Coverage Maintainability

extra-number's People

Contributors

wolfram77 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

extra-number's Issues

Cannot install from NPM

The package folder is empty after running npm i extra-number

ฮป ls -al node_modules\extra-number\
total 268
drwxr-xr-x 1 bryan 197609    0 Jul 22 10:12 ./
drwxr-xr-x 1 bryan 197609    0 Jul 22 10:12 ../
-rw-r--r-- 1 bryan 197609 1073 Oct 26  1985 LICENSE
-rw-r--r-- 1 bryan 197609 1772 Jul 22 10:12 package.json
-rw-r--r-- 1 bryan 197609 3429 Oct 26  1985 README.md

And if I try to install directly from github with npm i [email protected]:nodef/extra-number.git, I get an error:

npm ERR! code ENOLOCAL
npm ERR! Could not install from "github.com:nodef\extra-number.git" as it does not contain a package.json file.

too much useless loops

at least use sqrt for no waste of execution time
exemple : 1000000
=> 1x100000
=> 2x 50000
=> until 1000x1000;

rather make 1000000 loops, you have 1000; not a great deal but much much save compute memory.

my suggestion

export function properDivisors(x: number): number[] {
    const num = Math.abs(x);
    const a:number[] = [];
    const LIMIT = Math.sqrt(num)
    for (let i=1; i<LIMIT; i++){
if (num % i===0){
 a.push(i);
a.push(num/i) // if have rest of 0, the division is not a float number
}
    return uniq(a);
  }

image
https://en.wikipedia.org/wiki/Prime_number
relative to testing prime number because for testing prime number, we have to find if there are no devider except 1 and himself .

I'm sure for big number there are few tricks to make it faster : /

PostScriptum: I see that many function on fetch factor of, not have so clever algo and put a tons of loops for litterally nothing.

no var keyword!!!

https://javascript.plainenglish.io/4-reasons-why-var-is-considered-obsolete-in-modern-javascript-a30296b5f08f

using var is mainly for support old browser => compiler is for that, so you need some knowledge on tsconf.json
using "var" is "deprecated" since a decade now ... even in a javascript files.

https://caniuse.com/?search=let
97% running users browsers nowadays support "let"
99% for "const"

some devs convainced that compilers is less and less valuable for cross browser compabilities ...
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.