PseudoSavant

The Musings of Paul Ellis

  • About me
  • psMathStats 2.0

    javascript-icon.pngI just pushed the latest version of psMathStats to GitHub. It had been sitting on the shelf 95% done for probably a year, but it is out at last. There are some new methods and while the syntax is almost exactly the same, it isn’t a drop-in replacement for 1.0 as it now uses my ps namespace.

    New Features

    A full breakdown of all the methods and functions of 2.0 are available on GitHub, but these are some of the new features.

    • Array.sample
    • Array.histogram
    • Array.countByType
    • Array.percentile
    • ps.math.even
    • ps.math.odd
    • ps.math.product
    • ps.math.randomBetween
    • ps.math.randomNormal

    Array.sample

    Probably the biggest new feature is the ability to do sampling for any of the Array methods using Array.sample. It returns a randomly sampled array of any length less than or equal to the source array length. You can use it to quickly do calculations over large datasets (1MM+ rows) very quickly while sacrificing only a small amount of accuracy.

    Here is an example:

    // This will take a long time (many seconds) to run.
    // Makes the browser become unresponsive
    tenMillionRowArray.stdDev();
    
    // Takes only a few milliseconds to run, and the
    // returned value is almost exactly the same.
    tenMillionRowArray.sample(20000).stdDev();

    Suggestions

    As always, if you have any other useful math or statistics functions you’d like to see implemented just drop me a line at Twitter or GitHub with some details on how to perform the calculation. Even better, just send me a pull-request with your implementation. ;)

    Filed In: JavaScript
    June 14, 2013
  • Subscribe via Email

    Enter your email address to receive new posts to this blog in your inbox. I'll never mail anything else. Seriously.

  • Links

    • GitHub
    • Homemarks
  • Recent Posts

    • Meta “When is it stealing?” Inception.
    • Craftsman
© 2026 J. Paul Ellis