{"id":15645332,"url":"https://github.com/doowb/sma","last_synced_at":"2025-04-30T08:13:06.348Z","repository":{"id":65990639,"uuid":"87833706","full_name":"doowb/sma","owner":"doowb","description":"Calculate the simple moving average of an array.","archived":false,"fork":false,"pushed_at":"2018-09-12T22:22:19.000Z","size":13,"stargazers_count":54,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T08:12:57.172Z","etag":null,"topics":["array","array-average","array-avg","average","average-array","avg","avg-array","floating","floating-average","javascript","moving-average","nodejs","rolling","rolling-average","simple-floating-average","simple-moving-average","simple-rolling-average"],"latest_commit_sha":null,"homepage":"https://doowb.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doowb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-10T16:33:34.000Z","updated_at":"2023-09-22T08:00:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"63ed958d-e9f9-4ade-9675-0678acb74fa5","html_url":"https://github.com/doowb/sma","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fsma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/sma/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251666338,"owners_count":21624295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","array-average","array-avg","average","average-array","avg","avg-array","floating","floating-average","javascript","moving-average","nodejs","rolling","rolling-average","simple-floating-average","simple-moving-average","simple-rolling-average"],"created_at":"2024-10-03T12:06:30.382Z","updated_at":"2025-04-30T08:13:06.329Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","readme":"# sma [![NPM version](https://img.shields.io/npm/v/sma.svg?style=flat)](https://www.npmjs.com/package/sma) [![NPM monthly downloads](https://img.shields.io/npm/dm/sma.svg?style=flat)](https://npmjs.org/package/sma) [![NPM total downloads](https://img.shields.io/npm/dt/sma.svg?style=flat)](https://npmjs.org/package/sma) [![Linux Build Status](https://img.shields.io/travis/doowb/sma.svg?style=flat\u0026label=Travis)](https://travis-ci.org/doowb/sma)\n\n\u003e Calculate the simple moving average of an array.\n\nPlease consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save sma\n```\n\n## Usage\n\n```js\nvar sma = require('sma');\n```\n\n## API\n\n### [sma](index.js#L24)\n\nCalculate 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.\n\n**Params**\n\n* `arr` **{Array}**: Array of numbers to calculate.\n* `range` **{Number}**: Size of the window to use to when calculating the average for each range. Defaults to array length.\n* `format` **{Function}**: Custom format function called on each calculated average. Defaults to `n.toFixed(2)`.\n* `returns` **{Array}**: Resulting array of averages.\n\n**Example**\n\n```js\nconsole.log(sma([1, 2, 3, 4, 5, 6, 7, 8, 9], 4));\n//=\u003e [ '2.50', '3.50', '4.50', '5.50', '6.50', '7.50' ]\n//=\u003e   │       │       │       │       │       └─(6+7+8+9)/4\n//=\u003e   │       │       │       │       └─(5+6+7+8)/4\n//=\u003e   │       │       │       └─(4+5+6+7)/4\n//=\u003e   │       │       └─(3+4+5+6)/4\n//=\u003e   │       └─(2+3+4+5)/4\n//=\u003e   └─(1+2+3+4)/4\n```\n\n## Attribution\n\nThanks to [@jonschlinkert](https://github.com/jonschlinkert) for simplifying the algorithm. For more moving average modules checkout the [related projects](#related-projects) below.\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning 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:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n[exponential-moving-average](https://www.npmjs.com/package/exponential-moving-average): Calculate an exponential moving average from an array of numbers. | [homepage](https://github.com/jonschlinkert/exponential-moving-average \"Calculate an exponential moving average from an array of numbers.\")\n\n### Author\n\n**Brian Woodward**\n\n* [GitHub Profile](https://github.com/doowb)\n* [Twitter Profile](https://twitter.com/doowb)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Brian Woodward](https://doowb.com).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on September 12, 2018._","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fsma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fsma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fsma/lists"}