{"id":15297137,"url":"https://github.com/mitevpi/algos","last_synced_at":"2025-04-13T23:01:28.871Z","repository":{"id":51756178,"uuid":"201545665","full_name":"mitevpi/algos","owner":"mitevpi","description":"Low-level JavaScript algorithms for data processing/manipulation as shorthand for everyday use in frontend \u0026 backend code.","archived":false,"fork":false,"pushed_at":"2021-05-11T01:06:35.000Z","size":2614,"stargazers_count":6,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T13:12:48.143Z","etag":null,"topics":["algorithm","backend","core","frontend","javascript","library","package","shorthand"],"latest_commit_sha":null,"homepage":"https://mitevpi.github.io/algos/","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/mitevpi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-09T21:58:21.000Z","updated_at":"2024-05-16T23:03:45.000Z","dependencies_parsed_at":"2022-08-23T05:32:06.899Z","dependency_job_id":null,"html_url":"https://github.com/mitevpi/algos","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitevpi%2Falgos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitevpi%2Falgos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitevpi%2Falgos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitevpi%2Falgos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitevpi","download_url":"https://codeload.github.com/mitevpi/algos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248794565,"owners_count":21162614,"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":["algorithm","backend","core","frontend","javascript","library","package","shorthand"],"created_at":"2024-09-30T19:15:19.662Z","updated_at":"2025-04-13T23:01:28.829Z","avatar_url":"https://github.com/mitevpi.png","language":"JavaScript","readme":"# Algos\r\n\r\n[![Generic badge](https://img.shields.io/badge/Docs-Web-Green.svg)](https://mitevpi.github.io/algos/) [![Generic badge](https://img.shields.io/badge/Docs-MD-Green.svg)](docs/README.md) [![Generic badge](https://img.shields.io/badge/Samples-JS-Green.svg)](samples)\r\n\r\n[![npm](https://img.shields.io/npm/v/@mitevpi/algos.svg)](https://www.npmjs.com/package/@mitevpi/algos) [![npm bundle size](https://img.shields.io/bundlephobia/min/@mitevpi/algos.svg)](https://bundlephobia.com/result?p=@mitevpi/algos) [![npm](https://img.shields.io/npm/dw/@mitevpi/algos.svg)](https://www.npmjs.com/package/@mitevpi/algos) [![npm2](https://img.shields.io/npm/dt/@mitevpi/algos.svg)](https://www.npmjs.com/package/@mitevpi/algos)\r\n\r\n![Azure DevOps builds](https://img.shields.io/azure-devops/build/pmitevpi/pmitevpi/2) ![Azure DevOps Tests](https://img.shields.io/azure-devops/tests/pmitevpi/pmitevpi/2) [![GitHub issues](https://img.shields.io/github/issues/mitevpi/algos.svg)](https://github.com/mitevpi/algos/issues) ![David](https://img.shields.io/david/dev/mitevpi/algos.svg) [![GitHub last commit](https://img.shields.io/github/last-commit/mitevpi/algos.svg)](https://github.com/mitevpi/algos/commits/master)\r\n\r\nLow-level JavaScript algorithms as shorthand for everyday use in frontend \u0026 backend code.\r\n\r\n## Usage\r\n\r\nTo use this module, install locally using the command below, or clone this repository and import the .js files directly from source. Full documentation can be found on the [GitHub Pages Site](https://mitevpi.github.io/algos/) for this project.\r\n\r\n```cmd\r\nnpm i @mitevpi/algos\r\n```\r\n\r\n### Imports\r\n\r\nImports can be done through the aggregating index.js file or via individual members.\r\n\r\n#### Full Import\r\n\r\n```js\r\n// es5\r\nconst algos = require('./index.js'); // from source\r\nconst algos = require('@mitevpi/algos') // from npm\r\n\r\n// es6\r\nimport * as Algos from \"../src\"; // from source\r\nimport * as Algos from from \"@mitevpi/algos\"; // from npm\r\n```\r\n\r\n#### Individual Import\r\n\r\n```js\r\n// from source\r\nconst Arrays = require(\"./Arrays\");\r\nconst Numbers = require(\"./Numbers\");\r\n\r\n// from npm\r\nconst { Arrays } = require(\"@mitevpi/algos\");\r\nconst { Numbers } = require(\"@mitevpi/algos\");\r\nimport { Arrays, Numbers } from \"@mitevpi/algos\"; // es6\r\n```\r\n\r\n#### CDN\r\n\r\n```html\r\n\u003chtml lang=\"en\"\u003e\r\n  \u003chead\u003e\r\n    \u003cmeta charset=\"utf-8\" /\u003e\r\n    \u003c!-- import minified script from CDN or copy it locally --\u003e\r\n    \u003cscript src=\"../dist/algos.umd.min.js\"\u003e\u003c/script\u003e\r\n  \u003c/head\u003e\r\n\r\n  \u003cbody\u003e\r\n    \u003cscript\u003e\r\n      var arr = [1, 2, 3, 4, 5]; // create array\r\n      var result = algos.Arrays.sum(arr); // sum the array\r\n      console.log(\"LIBRARY\", algos); // imported lib object: classes, functions\r\n      console.log(\"RESULT\", result); // 15\r\n    \u003c/script\u003e\r\n  \u003c/body\u003e\r\n\u003c/html\u003e\r\n```\r\n\r\n### Sample Usage\r\n\r\nFor full examples of usage, please refer to the [test](/test) and [samples](/samples) folder which have a wide variety of use and test cases to learn from.\r\n\r\n#### Arrays\r\n\r\nThis is a suite of functions to be used on Arrays of any kind and data type.\r\n\r\nConsidering the following input:\r\n\r\n```js\r\nimport { Arrays } from \"@mitevpi/algos\";\r\n```\r\n\r\n##### Flatten\r\n\r\n```js\r\n// any level of nesting as an input\r\nconst array01 = [\r\n  [1, 2, 3],\r\n  [4, 5, 7]\r\n];\r\nconst array02 = [[[1, 2, 3]], [4, 5, 7]];\r\nconst array03 = [[[1, 2, 3]], [[4, 5, 7]]];\r\nconst array04 = [1, [0, [[1, [2, 3], 0]]], [[4, 5, 7]]];\r\n\r\nconst flat01 = Arrays.flatten(array01); // uniform nesting like array02/array03\r\n// [1, 2, 3, 4, 5, 7] \u003c- Expected Result\r\n\r\nconst flat04 = Arrays.flatten(array04); // non-uniform nesting\r\n// [1, 0, 1, 2, 3, 0, 4, 5, 7] \u003c- Expected Result\r\n```\r\n\r\n#### Summarize\r\n\r\n```js\r\nconst array2 = [\"tom\", \"peter\", \"mary\", \"tom\", \"mary\", \"mary\", \"jeremy\"];\r\nconst res = Arrays.summarize(array2); // get a summary of the array contents\r\n// {tom: 2, peter: 1, mary: 3, jeremy: 1} \u003c- Expected Result\r\n```\r\n\r\n#### Object Arrays\r\n\r\nThis is a suite of functions to be used on Arrays which contain Objects.\r\n\r\nConsidering the following input:\r\n\r\n```js\r\nimport { ArraysObjective } from \"@mitevpi/algos\";\r\nconst states = [\r\n  { population: 10, size: 13, state: \"OH\", near: \"KY\" },\r\n  { population: 20, size: 20, state: \"KY\", near: \"TN\" },\r\n  { population: 60, size: 20, state: \"IN\", near: \"PA\" },\r\n  { population: 40, size: 13, state: \"PA\", near: \"NY\" }\r\n];\r\n```\r\n\r\n##### Auto Normalize\r\n\r\n```js\r\n// Auto Normalize all values between 0 to 1 on objects\r\n// which have keys containing numerical value\r\nconst res = ArraysObjective.normalizeAuto(states);\r\n\r\n// We expect the return object to look like this:\r\nconsole.log(res);\r\n0:Object {population: 0, size: 0, state: \"OH\", …}\r\n1:Object {population: 0.2, size: 1, state: \"KY\", …}\r\n2:Object {population: 1, size: 1, state: \"IN\", …}\r\n3:Object {population: 0.6, size: 0, state: \"PA\", …}\r\n```\r\n\r\n##### Normalize By Key\r\n\r\n```js\r\n// Normalize all values between 0 to 1 on values of objects in the array\r\n// which correspond to the input key\r\nconst res = ArraysObjective.normalizeByKey(states, \"population\");\r\n\r\n// We expect the return object to look like this:\r\nconsole.log(res);\r\n0:Object {population: 0, size: 13, state: \"OH\", …}\r\n1:Object {population: 0.2, size: 20, state: \"KY\", …}\r\n2:Object {population: 1, size: 20, state: \"IN\", …}\r\n3:Object {population: 0.6, size: 13, state: \"PA\", …}\r\n```\r\n\r\n##### Group By Key\r\n\r\n```js\r\n// reformat the array to be grouped by unique same values in a corresponding key\r\nconst res = ArraysObjective.groupBy(states, \"size\");\r\n\r\n// We expect that the return object will be reformatted and grouped\r\n// by the two unique values in the \"size\" key\r\nconsole.log(res);\r\n13:Array(2) [Object, Object]\r\n0:Object {population: 10, size: 13, state: \"OH\", …}\r\n1:Object {population: 40, size: 13, state: \"PA\", …}\r\n20:Array(2) [Object, Object]\r\n0:Object {population: 20, size: 20, state: \"KY\", …}\r\n1:Object {population: 60, size: 20, state: \"IN\", …}\r\n```\r\n\r\n## Development\r\n\r\n### Building\r\n\r\nThe module can be built by running `npm run build` in the root directory of this repository. Documentation is built using the [Documentation module](https://www.npmjs.com/package/documentation) from npm, and by running `npm run docs` in the root directory of this repository. This will create [markdown](docs/README.md) and [HTML documentaion](docs/index.html).\r\n\r\n### Testing\r\n\r\nTesting is handled using [jest](https://jestjs.io/) and code coverage is evaluated using [nyc](https://www.npmjs.com/package/nyc). Tests can be initiated by running `npm test` in the root directory of this repository (be sure to first set your required env variables such as GMAPS_KEY).\r\n\r\n## Commands\r\n\r\nThe following commands are available during development.\r\n\r\n```sh\r\nnpm test # run tests with Jest\r\nnpm run coverage # run tests with coverage and open it on browser\r\nnpm run lint # lint code\r\nnpm run docs # generate docs\r\nnpm run build # transpile code\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitevpi%2Falgos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitevpi%2Falgos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitevpi%2Falgos/lists"}