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

array-smooth

v1.0.0

Published

Moving average smoothing, replaces each point in the array with the average of "x" adjacent points

Downloads

294

Readme

array-smooth

Codeship Status for ndelvalle/array-smooth Coverage Status dependencies Status devDependencies Status Codacy Badge code style: prettier

In smoothing, the data points of a signal are modified so individual points (presumably because of noise) are reduced, and points that are lower than the adjacent points are increased leading to a smoother signal. The algorithm used in this implementation is the moving average (rolling average or running average)

Install

$ npm install --save array-smooth
$ yarn add array-smooth

Use

const smooth = require('array-smooth')

const arr = [15, 2, 3, 14, 5, 6, 2, 8, 9, 10, 22, 3, 2, 11, 12]
const windowSize = 2
const arrSmoothed = smooth(arr, windowSize)

// arrSmoothed: [6.666666666666667, 8.5, 7.8, 6, 6, 7, 6, 7, 10.2, 10.4, 9.2, 9.6, 10, 7, 8.333333333333334]

API

smooth(array, windowSize, [getter], [setter])

array array

An array containing the values that we want to smooth, it can be an array of numbers or an array of objects defining a specific getter and / or setter

windowSize number

The smooth window option its a number that specifies the width of the moving average. It represents how many values to the right and left of the current index the algorithm will take in account when getting the sample to generate the smoothed value

getter(value) function

This function will receive the array value as an argument, it should return the attribute to smooth the array with. Is equivalent to calling array.map(getter)

Example:

const arr = [{ value: 15 }, { value: 2 }, { value: 3 }, { value: 14 }, { value: 5 }]

const getter = (item) => item.value
setter(value, smoothedValue) function

This function receives value and smoothedValue as arguments. The response will be the item that will populate the result array

Example:

const arr = [{ value: 15 }, { value: 2 }, { value: 3 }, { value: 14 }, { value: 5 }]

const getter = (item) => item.value
const setter = (item, itemSomoothed) => ({ value: item, valueSmoothed: itemSomoothed })

Playground

Edit array-smooth