Skip to content

feat: Documentation cleanup#16

Open
jwalsh wants to merge 5 commits into
mainfrom
feature/jsdoc
Open

feat: Documentation cleanup#16
jwalsh wants to merge 5 commits into
mainfrom
feature/jsdoc

Conversation

@jwalsh

@jwalsh jwalsh commented Mar 3, 2023

Copy link
Copy Markdown
Owner

No description provided.

Comment thread dist/bundle.min.js
@@ -1,3 +1,3 @@
/*! @jwalsh/stochastic - 0.2.4 */
!function(r){function t(o){if(n[o])return n[o].exports;var e=n[o]={i:o,l:!1,exports:{}};return r[o].call(e.exports,e,e.exports,t),e.l=!0,e.exports}var n={};t.m=r,t.c=n,t.d=function(r,n,o){t.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,"a",n),n},t.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},t.p="",t(t.s=0)}([function(r,t,n){window.stoch=n(1)},function(r,t,n){"use strict";function o(r){if(Array.isArray(r)){for(var t=0,n=Array(r.length);t<r.length;t++)n[t]=r[t];return n}return Array.from(r)}function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],o=void 0,e=void 0,a=void 0,u=void 0,i=void 0;if(a=[0],u=0,i=0,t<=0||r<=0)return a;for(;u<t;)o=Math.random(),e=-Math.log(o)/r,(u+=e)<t&&(i+=1,a.push(u));return!1===n?[i]:a}function a(r){return r.reduce(function(r,t){return t+r},0)/r.length}function u(r){var t=a(r),n=r.map(function(r){var n=r-t;return n*n}),o=a(n);return Math.sqrt(o)}function i(r,t){return p(a(r),u(r),t||r.length)}function h(r,t,n,o,e,a){var u=[],i=[0];return o>0&&e>0?!1===a?[r*Math.exp((t-n*n/2)*o+n*p(0,Math.sqrt(o),1)[0])]:(i=g(t-n*n/2,n,o,e,!0),i.forEach(function(t){u.push(r*Math.exp(t))}),u):i}function f(r,t,n,o){if(!m(r))throw new Error("Invalid transMatrix");var e=parseInt(n,10),a=[];a.push(e);for(var u=r[e],i=void 0,h=0;h<t;h++){i=Math.random();for(var f=0,v=0;v<u.length;v++)(f+=u[v])>i&&(a.push(v),u=r[v],v=u.length)}return!1===o?a[a.length-1]:a}function v(r){for(var t=Math.max.apply(Math,o(r))+1,n=Array(t).fill(0),e=[],a=0;a<n.length;a++)e.push(n.slice());return r.reduce(function(r,t){return r.transMatrix[r.previous][t]++,r.previous=t,r},{transMatrix:e,previous:0}).transMatrix.map(function(r){var t=r.reduce(function(r,t){return r+t},0);return r.map(function(r){return r/t})})}function l(r,t,n,o){if(!m(r))throw new Error("Invalid transMatrix");for(var e={0:n},a=n,u=r[n],i=0,h=void 0,f=void 0,v=void 0;i<t;){for(var l=0,c=0;c<u.length;c++)l+=u[c];if(h=Math.random(),f=-Math.log(h)/l,(i+=f)>t)return!1===o?{t:a}:e;v=0,h=Math.random();for(var d=0;d<u.length;d++)(v+=u[d]/l)>h&&(u=r[d],e[i]=d,a=d,d=u.length)}return e}function c(r,t){for(var n=[],o=0;o<t;o++){var e=Math.floor(Math.random()*r.length),a=r[e];n.push(a)}return n}function d(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return-Math.log(Math.random())/r}function s(r,t){return r/Math.pow(Math.random(),1/t)}function M(r,t){for(var n=r.slice().sort(function(r,t){return r-t}),o=n[r.length-1],e=n[0],a=Math.round(Math.sqrt(r.length)),u=t||(o-e)/a,i={},h=[],f=0;f<a;f++){var v=e+f*u;h.push(v),i[v]=0}for(var l=0;l<r.length;l++)for(var c=e,d=0,s=!0;s;){if(n[l]===n[n.length-1]){i[h[h.length-1]]+=1,s=!1;break}if(n[l]<c+u){i[h[d]]+=1,s=!1;break}d+=1,c+=u}return i}Object.defineProperty(t,"__esModule",{value:!0}),t.poissP=e,t.average=a,t.std=u,t.mock=i,t.GBM=h,t.DTMC=f,t.collate=v,t.CTMC=l,t.sample=c,t.exp=d,t.pareto=s,t.hist=M;var p=t.norm=function(){function r(r,t){return e=Math.random(),a=Math.random(),h=Math.sqrt(-2*Math.log(e))*Math.cos(2*a*Math.PI),f=Math.sqrt(-2*Math.log(e))*Math.sin(2*a*Math.PI),u=r+t*h,i=r+t*f,[u,i]}var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,e=void 0,a=void 0,u=void 0,i=void 0,h=void 0,f=void 0,v=[];if(n<=0)return v;if(void 0===o||1===o||o%1!=0)return[r(t,n)[0]];o/2%2!=0&&v.push(r(t,n)[0]);for(var l=0;l<Math.floor(o/2);l++)v=v.concat(r(t,n));return v},g=t.brown=function(r,t,n,o,e){var a=[0],u=0,i=n/o,h=void 0;if(!(n>0&&o>0))return a;if(!1===e)return[r*n+t*p(0,Math.sqrt(n),1)[0]];for(var f=0;f<o;f++)h=r*i+t*p(0,Math.sqrt(i),1)[0],u+=h,a.push(u);return a},m=function(r){for(var t=r.length,n=0;n<t;n++){var o=0;if(r[n].length!==t)return!1;for(var e=0;e<t;e++){if(r[n][e]>1||r[n][e]<0)return!1;o+=r[n][e]}var a=4*Math.pow(10,-16);if(o<1-a||o>1+a)return!1}return!0}}]);
!function(r){function t(e){if(n[e])return n[e].exports;var o=n[e]={exports:{},id:e,loaded:!1};return r[e].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=r,t.c=n,t.p="",t(0)}([function(r,t,n){window.stoch=n(1)},function(r,t){"use strict";function n(r){if(Array.isArray(r)){for(var t=0,n=Array(r.length);t<r.length;t++)n[t]=r[t];return n}return Array.from(r)}function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],e=void 0,o=void 0,a=void 0,i=void 0,u=void 0;if(a=[0],i=0,u=0,t<=0||r<=0)return a;for(;i<t;)e=Math.random(),o=-Math.log(e)/r,i+=o,i<t&&(u+=1,a.push(i));return n===!1?[u]:a}function o(r){var t=r.reduce(function(r,t){return t+r},0);return t/r.length}function a(r){if(0===r.length)throw new Error("Cannot find mode of an empty array.");return r.reduce(function(r,t){var n=r.numMapping[t]=(r.numMapping[t]||0)+1;return n>r.greatestFreq&&(r.greatestFreq=n,r.mode=t),r},{mode:null,greatestFreq:-(1/0),numMapping:{}}).mode}function i(r){if(0===r.length)throw new Error("Input array cannot be empty");if(!r.every(Number.isFinite))throw new Error("Input array must only contain numeric values");var t=o(r),n=r.map(function(r){var n=r-t,e=n*n;return e}),e=o(n);return Math.sqrt(e)}function u(r){if(0===r.length)return{};var t=[].concat(n(r)).sort(function(r,t){return r-t}),e=t[0],a=t[t.length-1],u=[e,a],h=r.reduce(function(r,t){return r+t},0),f=i(r),v=function(r){return r.length%2===1?t[(r.length-1)/2]:(t[r.length/2-1]+t[r.length/2])/2}(r),l=o(r),d=function(r){var t=[25,50,75].reduce(function(t,n){return t[n]=percentile(r,n),t},{});return t}(t),c=s(r),s=c.length>0?c[0]:null,M={min:e,max:a,range:u,sum:h,mean:l,median:v,mode:s,stdev:f,quantile:d};return M}function h(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return m(o(r),i(r),t||r.length)}function f(r,t,n){for(var e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,o=0!==e?e/Math.sqrt(1+e*e):0,a=Math.random(),i=Math.random(),u=Math.sqrt(-2*Math.log(a))*Math.cos(2*Math.PI*i),h=o*u+Math.sqrt(1-o*o)*Math.sqrt(-2*Math.log(a))*Math.sin(2*Math.PI*i),f=t+n*h,v=new Array(r),l=0;l<r;l++)v[l]=f;return v}function v(r,t,n,e,o){var a=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],i=[],u=[0];return e>0&&o>0?a===!1?[r*Math.exp((t-n*n/2)*e+n*m(0,Math.sqrt(e),1)[0])]:(u=y(t-n*n/2,n,e,o,!0),u.forEach(function(t){i.push(r*Math.exp(t))}),i):u}function l(r,t,n){var e=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!w(r))throw new Error("Invalid transMatrix");var o=parseInt(n,10),a=[];a.push(o);for(var i=r[o],u=void 0,h=0;h<t;h++){u=Math.random();for(var f=0,v=0;v<i.length;v++)f+=i[v],f>u&&(a.push(v),i=r[v],v=i.length)}return e===!1?a[a.length-1]:a}function d(r){for(var t=Math.max.apply(Math,n(r))+1,e=Array(t).fill(0),o=[],a=0;a<e.length;a++)o.push(e.slice());var i=r.reduce(function(r,t){return r.transMatrix[r.previous][t]++,r.previous=t,r},{transMatrix:o,previous:0}),u=i.transMatrix.map(function(r){var t=r.reduce(function(r,t){return r+t},0);return r.map(function(r){return r/t})});return u}function c(r,t,n){var e=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];if(!w(r))throw new Error("Invalid transMatrix");for(var o={0:n},a=n,i=r[n],u=0,h=void 0,f=void 0,v=void 0;u<t;){for(var l=0,d=0;d<i.length;d++)l+=i[d];if(h=Math.random(),f=-Math.log(h)/l,u+=f,u>t)return e===!1?{t:a}:o;v=0,h=Math.random();for(var c=0;c<i.length;c++)v+=i[c]/l,v>h&&(i=r[c],o[u]=c,a=c,c=i.length)}return o}function s(r,t){for(var n=[],e=0;e<t;e++){var o=Math.floor(Math.random()*r.length),a=r[o];n.push(a)}return n}function M(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return-Math.log(Math.random())/r}function g(r,t){return r/Math.pow(Math.random(),1/t)}function p(r,t){for(var n=r.slice().sort(function(r,t){return r-t}),e=n[r.length-1],o=n[0],a=Math.round(Math.sqrt(r.length)),i=t||(e-o)/a,u={},h=[],f=0;f<a;f++){var v=o+f*i;h.push(v),u[v]=0}for(var l=0;l<r.length;l++)for(var d=o,c=0,s=!0;s;){if(n[l]===n[n.length-1]){u[h[h.length-1]]+=1,s=!1;break}if(n[l]<d+i){u[h[c]]+=1,s=!1;break}c+=1,d+=i}return u}Object.defineProperty(t,"__esModule",{value:!0}),t.poissP=e,t.average=o,t.mode=a,t.std=i,t.summary=u,t.mock=h,t.rsn=f,t.GBM=v,t.DTMC=l,t.collate=d,t.CTMC=c,t.sample=s,t.exp=M,t.pareto=g,t.hist=p;var m=t.norm=function(){function r(r,t){return o=Math.random(),a=Math.random(),h=Math.sqrt(-2*Math.log(o))*Math.cos(2*a*Math.PI),f=Math.sqrt(-2*Math.log(o))*Math.sin(2*a*Math.PI),i=r+t*h,u=r+t*f,[i,u]}var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,o=(arguments[3],void 0),a=void 0,i=void 0,u=void 0,h=void 0,f=void 0,v=[];if(n<=0)return v;if("undefined"==typeof e||1===e||e%1!==0)return[r(t,n)[0]];e/2%2!==0&&v.push(r(t,n)[0]);for(var l=0;l<Math.floor(e/2);l++)v=v.concat(r(t,n));return v},y=t.brown=function(r,t,n,e){var o=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],a=[0],i=0,u=n/e,h=void 0;if(!(n>0&&e>0))return a;if(o===!1)return[r*n+t*m(0,Math.sqrt(n),1)[0]];for(var f=0;f<e;f++)h=r*u+t*m(0,Math.sqrt(u),1)[0],i+=h,a.push(i);return a},w=function(r){for(var t=r.length,n=0;n<t;n++){var e=0;if(r[n].length!==t)return!1;for(var o=0;o<t;o++){if(r[n][o]>1||r[n][o]<0)return!1;e+=r[n][o]}var a=4*Math.pow(10,-16);if(e<1-a||e>1+a)return!1}return!0}}]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'n' was used before it was defined.
's' was used before it was defined.
Confusing use of '!'.
Expected '{' and instead saw 'e'.
Expected '{' and instead saw 'f'.
Expected '{' and instead saw 'n'.
Expected '{' and instead saw 'o'.
Expected '{' and instead saw 'return'.
Expected '{' and instead saw 'throw'.
Expected '{' and instead saw 'v'.
Expected an assignment or function call and instead saw an expression.
Line is too long.
Missing semicolon.
Too many errors. (66% scanned).
Wrap an immediate function invocation in parens to assist the reader in understanding that the expression is the result of a function, and not the function itself.

Comment thread lib/index.js

// // https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Weibull.html
// // https://en.wikipedia.org/wiki/Weibull_distribution
// // Usage: in industrial engineering to represent manufacturing and delivery times

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread lib/index.js
var log = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : FALSE;
};
// // https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Binomial.html
// // Usage: only two mutually exclusive possible outcomes, for example the outcome of tossing a coin is heads or tails

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread lib/index.js
var u = Math.random();
var v = Math.random();
var x = Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
var y = t * x + Math.sqrt(1 - t * t) * Math.sqrt(-2 * Math.log(u)) * Math.sin(2 * Math.PI * v);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread lib/index.js
* @returns {number[]} array of n numbers generated from the SN distribution
*/
function rsn(n, location, scale) {
var shape = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread lib/index.js
*/
function mock(values /*: Array<number> */, num /*: number */) {
function mock(values /*: Array<number> */) {
var num /*: number */ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread lib/index.js
}

return values.reduce(function (accumulator, current) {
var val = accumulator.numMapping[current] = (accumulator.numMapping[current] || 0) + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread lib/index.js
p.mode = c;
function mode(values /*: Array<number> */) {
if (values.length === 0) {
throw new Error('Cannot find mode of an empty array.');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed double and single quotes.

Comment thread lib/index.js
* @example const poissP = stoch.poissP(1, 100, true);
* @example const emails = stoch.hist(Array(261).fill().map(e => stoch.poissP(10, 8, true).length));
* @example const poissP = stochastic.poissP(1, 100, true);
* @example const emails = stochastic.hist(Array(261).fill().map(e => stochastic.poissP(10, 8, true).length));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread lib/index.js
@@ -1,4 +1,4 @@
'use strict';
"use strict";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the function form of "use strict".

Comment thread src/index.js
excessKurtosis: kurtosis
min,
max,
range,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'object short notation' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Too many errors. (25% scanned).

Comment thread src/index.js
skewness,
excessKurtosis: kurtosis
min,
max,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'object short notation' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

Comment thread src/index.js
stdev,
skewness,
excessKurtosis: kurtosis
min,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'object short notation' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

Comment thread src/index.js
const _mode = mode(values);
// mean | moment | skewness | std | var
const modeArr = mode(values);
const mode = modeArr.length > 0 ? modeArr[0] : null; // Check if mode exists

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'mode' was used before it was declared, which is illegal for 'const' variables.

Comment thread src/index.js
const kurtosis = _kurtosis(values);
const _mode = mode(values);
// mean | moment | skewness | std | var
const modeArr = mode(values);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

Comment thread src/index.js
const quantile = (function(values) {
let result = [25, 50, 75].reduce((p, c) => {
p[c] = c;
p[c] = percentile(values, c); // Use percentile function to calculate percentiles

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread src/index.js
export function std(values /*: Array<number> */) {
const avg = average(values);
if (values.length === 0) {
throw new Error("Input array cannot be empty");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed double and single quotes.

Comment thread src/index.js
* @example const std = stochastic.std([2, 3, 4, 4, 4, 5, 6]);
* @param {number[]} values
* @returns {number} standard deviation as positive number
* @param {number[]} values - The array of values to calculate the standard deviation for.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread src/index.js
}

return values.reduce((accumulator, current) => {
var val = accumulator.numMapping[current] = (accumulator.numMapping[current] || 0) + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Comment thread src/index.js
throw new Error('Cannot find mode of an empty array.');
}

return values.reduce((accumulator, current) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Comment thread src/index.js
if (val > p.greatestFreq) {
p.greatestFreq = val;
p.mode = c;
export function mode(values /*: Array<number> */) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'export' is only available in ES6 (use 'esversion: 6').

@sonarqubecloud

sonarqubecloud Bot commented Mar 3, 2023

Copy link
Copy Markdown

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 2 Security Hotspots
Code Smell A 13 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant