{"id":22345799,"url":"https://github.com/gerhynes/array-cardios","last_synced_at":"2026-04-30T00:33:26.035Z","repository":{"id":106044198,"uuid":"105751676","full_name":"gerhynes/array-cardios","owner":"gerhynes","description":"Exercises to practice array methods. Part of Wes Bos' JavaScript 30 course. ","archived":false,"fork":false,"pushed_at":"2017-11-27T20:27:37.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-31T11:49:43.074Z","etag":null,"topics":["arrays","filter","javascript","javascript30","map","reduce","sort"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/gerhynes.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":"2017-10-04T09:31:51.000Z","updated_at":"2023-04-11T15:21:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"317c46d9-fb3b-4b65-b7da-5d9b71bd6697","html_url":"https://github.com/gerhynes/array-cardios","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gerhynes%2Farray-cardios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gerhynes%2Farray-cardios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gerhynes%2Farray-cardios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gerhynes%2Farray-cardios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gerhynes","download_url":"https://codeload.github.com/gerhynes/array-cardios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245632926,"owners_count":20647308,"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":["arrays","filter","javascript","javascript30","map","reduce","sort"],"created_at":"2024-12-04T09:18:44.034Z","updated_at":"2026-04-30T00:33:25.959Z","avatar_url":"https://github.com/gerhynes.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Array Cardios\n\nExercises to practise array methods. Part of Wes Bos'\n[JavaScript 30](https://javascript30.com/) course.\n\n![Screenshot of array cardios in Firefox](https://image.prntscr.com/image/rtT7Be0NSzSmiscOf1sXmg.png)\n\n## Notes\n\n### array.prototype.filter()\n\n`filter()` runs a function containing a test, loops over every element in an\narray, and returns those that pass the test.\n\n```js\nconst fifteen = inventors.filter(\n  inventor =\u003e inventor.year \u003e= 1500 \u0026\u0026 inventor.year \u003c 1600\n);\n```\n\n### array.prototype.map()\n\n`map()` takes in an array, does something with it, and returns a new array of\nthe same length, i.e. it returns the same amount of elements that you give it.\n\nTo add a space when using map, you can either concatenate in a space `+ '' +` or\nuse ES6 template literals `${} ${}`.\n\n```js\nconst fullNames = inventors.map(\n  inventor =\u003e `${inventor.first} ${inventor.last}`\n);\n```\n\n### array.prototype.sort()\n\n`sort()` compares the values of pairs of elements in an array and bubbles them\nup or down by returning 1 or -1.\n\n```js\nconst ordered = inventors.sort(function(a, b) {\n  if (a.year \u003e b.year) {\n    return 1;\n  } else {\n    return -1;\n  }\n});\n```\n\nor more succinctly\n\n```js\nconst ordered = inventors.sort((a, b) =\u003e (a.year \u003e b.year ? 1 : -1));\n```\n\n### array.prototype.reduce()\n\n`reduce()` accepts two parameters (the accumulator and the current element\nvalue). It runs a function on every element in an array accepting a new current\nvalue each time. Finally it retuns a single total value.\n\n```js\nconst totalYears = inventors.reduce((total, inventor) =\u003e {\n  return total + (inventor.passed - inventor.year);\n}, 0);\nconsole.log(totalYears);\n```\n\n### console.table\n\n`console.table()` logs your data to the console as a table.\n\n### console.log({})\n\n`console.log({})` will show you the name of the variable and its value.\n\n### Node Lists\n\nNode lists do not have all the methods arrays have. You can convert a node list\ninto an array using `Array.from()` or by creating an array and using ES6 spread\nto spread every element into the array: `[...category.querySelectorAll('a')]`.\n\n### array.prototype.some()\n\n`some()` will check whether at least one element in your array meets what you\nare looking for. It executes a callback function on every element until it finds\none that returns a truthy value.\n\n```js\nconst isAdult = people.some(\n  person =\u003e new Date().getFullYear() - person.year \u003e= 19\n);\nconsole.log({ isAdult });\n```\n\n### array.prototype.every()\n\n`every()` checks whether every element in an array passes the test you set in\nthe callback function.\n\n```js\nconst allAdults = people.every(\n  person =\u003e new Date().getFullYear() - person.year \u003e= 19\n);\nconsole.log({ allAdults });\n```\n\n### array.prototype.find()\n\n`find()` works similarly to `filter()` but return the first element that it\nfinds, rather than a subset of the array.\n\n```js\nconst comment = comments.find(comment =\u003e comment.id === 823423);\nconsole.log(comment);\n```\n\n### array.prototype.findIndex()\n\n`findIndex()` returns the index of the first element in the array that meets the\nprovided test. It could be used to find the index of an element in order to\ndelete it, for example. You could then use splice or create a new array and\nspread the desired elements into it.\n\n```js\nconst index = comments.findIndex(comment =\u003e comment.id === 823423);\nconsole.log(index);\n\n// comments.splice(index, 1);\n\nconst newComments = [...comments.slice(0, index), ...comments.slice(index + 1)];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgerhynes%2Farray-cardios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgerhynes%2Farray-cardios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgerhynes%2Farray-cardios/lists"}