nodef / extra-number Goto Github PK
View Code? Open in Web Editor NEWA number is a mathematical object used to count, measure, and label.
Home Page: https://www.npmjs.com/package/extra-number
License: MIT License
A number is a mathematical object used to count, measure, and label.
Home Page: https://www.npmjs.com/package/extra-number
License: MIT License
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);
}
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.
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.
Consider the following enhancements. Include any functions that have not already been mentioned.
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 ...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.