{"id":22345568,"url":"https://github.com/gerhynes/sort-without-articles","last_synced_at":"2025-06-25T19:39:56.458Z","repository":{"id":106047971,"uuid":"107462828","full_name":"gerhynes/sort-without-articles","owner":"gerhynes","description":"A page built to practice sorting arrays. Built for Wes Bos' JavaScript 30 course. ","archived":false,"fork":false,"pushed_at":"2018-01-22T22:07:09.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-31T11:34:28.247Z","etag":null,"topics":["javascript","javascript30","sort"],"latest_commit_sha":null,"homepage":"https://gk-hynes.github.io/sort-without-articles/","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/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-18T21:04:18.000Z","updated_at":"2018-01-23T21:44:01.000Z","dependencies_parsed_at":"2024-05-02T21:42:52.514Z","dependency_job_id":null,"html_url":"https://github.com/gerhynes/sort-without-articles","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%2Fsort-without-articles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gerhynes%2Fsort-without-articles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gerhynes%2Fsort-without-articles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gerhynes%2Fsort-without-articles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gerhynes","download_url":"https://codeload.github.com/gerhynes/sort-without-articles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245632414,"owners_count":20647194,"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":["javascript","javascript30","sort"],"created_at":"2024-12-04T09:18:07.252Z","updated_at":"2025-03-26T10:14:33.313Z","avatar_url":"https://github.com/gerhynes.png","language":"JavaScript","readme":"# Sort Without Articles\n\nA page built to practice sorting arrays. Built for Wes Bos' [JavaScript 30](https://javascript30.com/) course.\n\n[![Screenshot of the Sort Without Articles page](https://res.cloudinary.com/gerhynes/image/upload/v1516657054/Screenshot-2018-1-22_Sort_Without_Articles_oysjib.jpg)](https://gk-hynes.github.io/sort-without-articles/)\n\n## Notes\n\nTo sort the bandnames, create a variable, `sortedBands`, and call `sort` on it.\n\n`Sort` takes a function with parameters, `a` and `b`, the first and second element passed to it. It moves the bigger one, or the one that comes first alphabetically, to the top.\n\nInside `sort`, use an if statment to check if `a \u003e b`.\n\nThis will alphabetize the array but will take articles into account.\n\nSo, make a new function, `strip`, and pass it `bandName`.\n\nReturn `bandName` but run `replace` on it. You can use a regular expression to replace a, an, and the in one go. Call `trim` on the end of it to remove unnecessary spaces.\n\n```js\nfunction strip(bandName) {\n  return bandName.replace(/^(a |the |an )/i, \"\").trim();\n}\n```\n\nBack inside the `sort` function, you can use a ternary operator, calling `strip` on `a` and `b`.\n\n```js\nconst sortedBands = bands.sort((a, b) =\u003e (strip(a) \u003e strip(b) ? 1 : -1));\n```\n\n### Displaying the bands\n\nNow you can select the ul `bands` and set their innerHTML.\n\nTake `sortedBands`, loop over them using `map`, return each band inside an li, and `join` them.\n\n```js\ndocument.querySelector(\"#bands\").innerHTML = sortedBands\n  .map(band =\u003e `\u003cli\u003e${band}\u003c/li\u003e`)\n  .join(\"\");\n```\n\nWhen you try to set something to innerHTML that is not a string, such as an array, `toString` is called on it and by default a comma is put between each element.\n\n`join(\"\")` prevents this and joins the elements into one big string.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgerhynes%2Fsort-without-articles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgerhynes%2Fsort-without-articles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgerhynes%2Fsort-without-articles/lists"}