All Projects → doowb → Sma

doowb / Sma

Licence: mit
Calculate the simple moving average of an array.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sma

Negative Array
Negative array index support `array[-1]` using ES2015 Proxy
Stars: ✭ 420 (+775%)
Mutual labels:  array
Leetcode
Provide all my solutions and explanations in Chinese for all the Leetcode coding problems.
Stars: ✭ 5,619 (+11606.25%)
Mutual labels:  array
Generate Random Web V7.19.03
Projeto para um cliente, afim de automatizar a escolha de números, pois o mesmo é jogador de loterias e queria um sistema para gerar jogos prontos.
Stars: ✭ 19 (-60.42%)
Mutual labels:  array
Netfabric.hyperlinq
High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays and Span<T>.
Stars: ✭ 479 (+897.92%)
Mutual labels:  array
Deep Object Diff
Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️
Stars: ✭ 515 (+972.92%)
Mutual labels:  array
Array To Xml
A simple class to convert an array to xml
Stars: ✭ 744 (+1450%)
Mutual labels:  array
Loopy
A code generator for array-based code on CPUs and GPUs
Stars: ✭ 367 (+664.58%)
Mutual labels:  array
Kakajson
Fast conversion between JSON and model in Swift.
Stars: ✭ 867 (+1706.25%)
Mutual labels:  array
Moses
Utility library for functional programming in Lua
Stars: ✭ 541 (+1027.08%)
Mutual labels:  array
Array First
Get the first element or first n elements of an array.
Stars: ✭ 6 (-87.5%)
Mutual labels:  array
Collection
A PHP library for representing and manipulating collections.
Stars: ✭ 488 (+916.67%)
Mutual labels:  array
Android interviews
🚀Everything you need to know to find a android job. 算法 / 面试题 / Android 知识点 🔥🔥🔥 总结不易,你的 star 是我最大的动力!
Stars: ✭ 510 (+962.5%)
Mutual labels:  array
Overlaycontainer
Non-intrusive iOS UI library to implement overlay based interfaces
Stars: ✭ 777 (+1518.75%)
Mutual labels:  floating
Algodeck
An Open-Source Collection of 200+ Algorithmic Flash Cards to Help you Preparing your Algorithm & Data Structure Interview 💯
Stars: ✭ 4,441 (+9152.08%)
Mutual labels:  array
Shallow Clone
Make a shallow clone of an object, array or primitive.
Stars: ✭ 23 (-52.08%)
Mutual labels:  array
Laravel Helpers
An extensive set of Laravel framework helper functions and collection macros.
Stars: ✭ 407 (+747.92%)
Mutual labels:  array
Enfloatingview
🔥应用内悬浮窗,无需一切权限,适配所有ROM和厂商,no permission floating view.
Stars: ✭ 733 (+1427.08%)
Mutual labels:  floating
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (-27.08%)
Mutual labels:  array
Settingscompat
特殊权限(Special Permissions)兼容库,悬浮窗权限(SYSTEM_ALERT_WINDOW)与系统设置修改权限(WRITE_SETTINGS)
Stars: ✭ 942 (+1862.5%)
Mutual labels:  floating
Pyopencl
OpenCL integration for Python, plus shiny features
Stars: ✭ 790 (+1545.83%)
Mutual labels:  array

sma NPM version NPM monthly downloads NPM total downloads Linux Build Status

Calculate the simple moving average of an array.

Please consider following this project's author, Brian Woodward, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save sma

Usage

var sma = require('sma');

API

sma

Calculate the simple moving average of an array. A new array is returned with the average of each range of elements. A range will only be calculated when it contains enough elements to fill the range.

Params

  • arr {Array}: Array of numbers to calculate.
  • range {Number}: Size of the window to use to when calculating the average for each range. Defaults to array length.
  • format {Function}: Custom format function called on each calculated average. Defaults to n.toFixed(2).
  • returns {Array}: Resulting array of averages.

Example

console.log(sma([1, 2, 3, 4, 5, 6, 7, 8, 9], 4));
//=> [ '2.50', '3.50', '4.50', '5.50', '6.50', '7.50' ]
//=>   │       │       │       │       │       └─(6+7+8+9)/4
//=>   │       │       │       │       └─(5+6+7+8)/4
//=>   │       │       │       └─(4+5+6+7)/4
//=>   │       │       └─(3+4+5+6)/4
//=>   │       └─(2+3+4+5)/4
//=>   └─(1+2+3+4)/4

Attribution

Thanks to @jonschlinkert for simplifying the algorithm. For more moving average modules checkout the related projects below.

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

exponential-moving-average: Calculate an exponential moving average from an array of numbers. | homepage

Author

Brian Woodward

License

Copyright © 2018, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on September 12, 2018.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].