{"id":19604692,"url":"https://github.com/victorvoid/reduces-js","last_synced_at":"2025-09-01T09:39:57.686Z","repository":{"id":89705951,"uuid":"65056698","full_name":"victorvoid/reduces-js","owner":"victorvoid","description":":honeybee: reduce everywhere","archived":false,"fork":false,"pushed_at":"2016-08-17T03:17:04.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-26T16:19:38.793Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/victorvoid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-08-06T00:11:57.000Z","updated_at":"2016-08-16T03:46:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"5b4ccda2-eb66-4e6f-b3fd-18d3b84cebcd","html_url":"https://github.com/victorvoid/reduces-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/victorvoid/reduces-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorvoid%2Freduces-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorvoid%2Freduces-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorvoid%2Freduces-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorvoid%2Freduces-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/victorvoid","download_url":"https://codeload.github.com/victorvoid/reduces-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victorvoid%2Freduces-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273100861,"owners_count":25045700,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-11T09:37:52.831Z","updated_at":"2025-09-01T09:39:57.667Z","avatar_url":"https://github.com/victorvoid.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reduces Js\nUnderstand Javascript Array Reduce with examples everywhere.\n\n# When to use Reduce ? \n\nYou may use reduce when to want to find a cumulative or concatenated value based on elements across the array, \nand a cumulative value can to be one way to solve many problems.\n\n## Examples\n\n1.\n\n```js\n/*It should remove all values from list a, which are present in list b.\ndifference([1,2],[1]) == [2] difference([1,2,2,2,3],[2]) == [1,3] */\nlet array_diff = (a, b) =\u003e a.reduce((prev, curr) =\u003e (!b.includes(curr) \u0026\u0026 prev.push(curr), prev), [])\n```\n\n2.\n```js\n/* Returns the sum of all the multiples of 3 or 5 below the number passed in.\n10 =\u003e 23, 5 =\u003e 3*/\nlet multiplebelow = number =\u003e\n\t number \u003c= 0 ? 0 :\n\t Array.from(new Array(number-1), (x, i) =\u003e i + 1)\n\t.reduce((prev, curr) =\u003e (curr % 3 == 0 || curr % 5 == 0) ? prev + curr: prev ,0)\n\n```\n\n3.\n```js\n/*An isogram is a word that has no repeating letters, consecutive or non-consecutive.\naspol =\u003e true, asspol =\u003e false*/\nlet isIsogram = str =\u003e\n\t!str\n\t.toLowerCase()\n\t.split('')\n\t.reduce((prev, curr, i, array) =\u003e array\n\t\t.slice(array.indexOf(curr)+1)\n\t\t.includes(curr) ? prev + 1: prev + 0, 0) \u003e 0\n```\n\n4.\n```js\n// ('1234fnb') =\u003e '###4fnb'\nlet maskify = cc =\u003e\n\tcc\n\t.split('')\n\t.reduce((total, curr, currentIndex, arr) =\u003e \n\t\tcurrentIndex \u003c (arr.length-4) ? total + '#': total + arr[currentIndex], '')\n```\n\n5.\n\n```js\n//promise all\nconst fs = require('fs');\n\nfunction promiseAll (arr) {\n  return Promise.all(arr)\n  .then(function success(res){\n    return res.map(a =\u003e JSON.parse(a))\n    .reduce((init,actual) =\u003e { \n      init = init.concat(actual)\n      return init; \n    },[]);\n  })\n  .catch(function error(err) {\n    throw err; \n  });\n}\n\nfunction readFile (path) {\n  return new Promise(function(resolve, reject) {\n    fs.readFile(path,'utf8',function(err, res) {\n      err ? reject(err) : resolve(res);\n    });\n  });\n}\n\npromiseAll([\n  readFile('./file01.json'),\n  readFile('./file02.json')\n])\n.then( res =\u003e  console.log(res))\n.catch(err =\u003e console.error(err));\n```\n\n6.\n\n```js\n\nlet users_values = {\n\tname: [ \n\t  \"Victor Igor\"\n\t, \"José Carlos\"\n\t, \"Joao Messias\"\n\t, \"Andy Self\"\n\t, \"Archer Gly\"\n\t],\t\n\tusername: [\n\t  \"vitus\"\n\t, \"jose123\"\n\t, \"juau\"\n\t, \"joaome\"\n\t, \"andy321\"\n\t]\n};\n\nlet addUsers = user =\u003e user['name']\n\t.reduce((prev, curr, i, a) =\u003e {\n\t\tprev.push({\n\t\t  name: curr\t\t\n\t\t, bio: \"place your bio here\"\n\t\t, dateregister: Date.now()\n\t\t, avatarpath: \"place your avatar here\"\n\t\t, auth: {\n\t\t    username: user['username'][i]\n\t\t  , email:    user['username'][i]+\"@hotmail.com\"\n\t\t  ,\tpassword: curr + Math.random().toString(36)\n\t\t  , online:   true\n\t\t  , disabled: false\n\t\t  , hashtoken: 'hash()'\n\t\t  }\n\t\t})\n\t\treturn prev;\n\t},[]);\n```\n\n7.\n\n```js\n//alphabet position\nconst fs = require('fs');\n\nlet alphabet = fs.readFileSync('alphabet.txt', 'utf8')\n\t.trim()\n\t.split(' ')\n\t.map(n =\u003e n.toLowerCase())\n\nlet alphabetPosition = (text) =\u003e {\n\treturn text\n\t.split('')\n\t.filter(n =\u003e n != ' ')\n\t.reduce((prev, curr) =\u003e prev.concat(alphabet.indexOf(curr) + 1), [])\n\t.join(' ')\n}\t\n```\n\n8.\n\n```js\n/*\n    deleteNth ([1,1,1,1],2) // return [1,1]\n    deleteNth ([20,37,20,21],1) // return [20,37,21]\n    \u003c= \n    deleteNth([16,16,16,20,20,1,2], 2) //return [16,16,20,20,1,2]\n*/\nfunction deleteNth(arr,x){\n    'use strict'\n    let countArr = (v, newarr) =\u003e {\n        let obj = newarr.reduce((p, v)=\u003e{\n            if(v in p)\n                p[v]++;\n            else\n                p[v] = 1;\n            return p;\n        }, {})\n         return obj[v];\n    };\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorvoid%2Freduces-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorvoid%2Freduces-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorvoid%2Freduces-js/lists"}