{"id":18563961,"url":"https://github.com/rbrtsmith/js-snippets","last_synced_at":"2025-05-15T18:14:19.020Z","repository":{"id":26357572,"uuid":"29806629","full_name":"rbrtsmith/js-snippets","owner":"rbrtsmith","description":"Short JavaScript snippets","archived":false,"fork":false,"pushed_at":"2017-05-07T14:29:42.000Z","size":22,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-17T13:12:55.527Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/rbrtsmith.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}},"created_at":"2015-01-25T07:29:45.000Z","updated_at":"2018-08-07T00:16:10.000Z","dependencies_parsed_at":"2022-08-28T01:00:51.268Z","dependency_job_id":null,"html_url":"https://github.com/rbrtsmith/js-snippets","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/rbrtsmith%2Fjs-snippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbrtsmith%2Fjs-snippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbrtsmith%2Fjs-snippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbrtsmith%2Fjs-snippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rbrtsmith","download_url":"https://codeload.github.com/rbrtsmith/js-snippets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254394726,"owners_count":22063984,"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":[],"created_at":"2024-11-06T22:13:54.681Z","updated_at":"2025-05-15T18:14:18.999Z","avatar_url":"https://github.com/rbrtsmith.png","language":"JavaScript","readme":"# js-snippets\nShort JavaScript snippets written in both ES5 and ES6\n\n## average\nA utility function that takes an array of numbers and returns the average value.\n\n## countOccurencies\nA untility function that takes an array and a value.  Returns an integer value equal to the number of times the value occurs in the array.\n\n## flatten\nRecursevly flatten an array of nested arrays.\nExample:\n```\nvar names = [[\"Robert\", \"Smith\"], [\"John\", \"Paul\"], [\"Jack\", [1,2,3], \"Jones\"]];\nflatten(names); // [\"Robert\", \"Smith\", \"John\", \"Paul\", \"Jack\", 1, 2, 3, \"Jones\"]\n```\n\n## getTotal\nUtility function, accepts an array of numbers and returns the sum.\n\n## isArray\nA utility function that allows you to type check an array.  JavaScripts TypeOf method returns object which is incorrect.\nThis returns true if the argument passed is an array, and false for anything else.\n\n## isLetter\nA utility function that takes a single charcter string and returns true if it is a letter, false for any other value.\n\n## isPrime\nUtility function that takes an integer and returns true if it is a prime.\n\n## loopOverObj\nTakes two arguments, an object and a callback function.  Loops over each own property on the passed object and calls the callback function with each iteration passing in the objects key.\n\n## maximum\nTakes an array of numbers and returns the highest value.\n\n## minimum\nTakes an array of numbers and returns the lowest value.\n\n## merge\nFunction that takes any number of objects and returns a new object containing all the properties of the passed objects.\nDuplicate properties will overwrite one another.\n\n## removeDuplicates\nTakes an array and returns a new array of unique values \u0026mdash; removes duplicates.\n\n## reverseString\nTakes a string and returns the string with the characters in reverse order. \n\n## simple closure\nA very crude example of closure within JavaScript, the concole logs are the to show that the inner function retains the outer functions scope even though it is executing outside of that scope.\n\n## wrap text\nWraps all individual characters and words within the passed elements with spans that have corresponding classnames.\nThis is useful if you wish to manipulate each individual character or word, with an animation.\nTakes any valid DOM selector:\n`wrapText('.js-text');`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbrtsmith%2Fjs-snippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frbrtsmith%2Fjs-snippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbrtsmith%2Fjs-snippets/lists"}