This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # ============================================================================= | |
| # cleanup-branches.sh — Bulk delete GitHub branches with whitelist protection | |
| # ============================================================================= | |
| # | |
| # Usage: | |
| # ./cleanup-branches.sh --repo owner/repo --whitelist whitelist.txt [OPTIONS] | |
| # | |
| # Options: | |
| # --repo OWNER/REPO Target repository (required) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Checks if the given date is a weekday. | |
| - Use `Date.prototype.getDay()` to check weekday by using a modulo operator (`%`). | |
| - Omit the argument, `d`, to use the current date as default. | |
| const isWeekday = (d = new Date()) => d.getDay() % 6 !== 0; | |
| isWeekday(); // true (if current date is 2019-07-19) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Checks if the given date is a weekend. | |
| // - Use `Date.prototype.getDay()` to check weekend by using a modulo operator (`%`). | |
| // - Omit the argument, `d`, to use the current date as default. | |
| const isWeekend = (d = new Date()) => d.getDay() % 6 === 0; | |
| isWeekend(); // 2018-10-19 (if current date is 2018-10-18) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Filters an array of objects based on a condition while also filtering out unspecified keys. | |
| // | |
| // - Use `Array.prototype.filter()` to filter the array based on the predicate `fn` so that it returns the objects for which the condition returned a truthy value. | |
| // - On the filtered array, use `Array.prototype.map()` to return the new object. | |
| // - Use `Array.prototype.reduce()` to filter out the keys which were not supplied as the `keys` argument. | |
| const reducedFilter = (data, keys, fn) => | |
| data.filter(fn).map(el => | |
| keys.reduce((acc, key) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Creates an array with the unique values filtered out. | |
| // | |
| // - Use the `Set` constructor and the spread operator (`...`) to create an array of the unique values in `arr`. | |
| // - Use `Array.prototype.filter()` to create an array containing only the non-unique values. | |
| const filterUnique = arr =>[...new Set(arr)].filter(i => arr.indexOf(i) !== arr.lastIndexOf(i)); | |
| filterUnique([1, 2, 2, 3, 4, 4, 5]); // [2, 4] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Finds all the keys in the provided object that match the given value. | |
| // | |
| // - Use `Object.keys()` to get all the properties of the object. | |
| // - Use `Array.prototype.filter()` to test each key-value pair and return all keys that are equal to the given value. | |
| const findKeys = (obj, val) => Object.keys(obj).filter((key) => obj[key] === val); | |
| const ages = { | |
| Leo: 20, | |
| Zoey: 21, | |
| Jane: 20, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function intToBin(number) { | |
| if (number === 0) { | |
| return '0'; | |
| } | |
| let res = ''; | |
| while (number > 0) { | |
| res = String(number % 2) + res; | |
| number = parseInt(number / 2, 10); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Checks if a string contains only alphanumeric characters. | |
| // | |
| // - Use `RegExp.prototype.test()` to check if the input string matches against the alphanumeric regexp pattern. | |
| const isAlphaNumeric = str => /^[a-z0-9]+$/gi.test(str); | |
| isAlphaNumeric('hello123'); // true | |
| isAlphaNumeric('123'); // true | |
| isAlphaNumeric('hello 123'); // false (space character is not alphanumeric) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters). | |
| - Use `String.prototype.toLowerCase()` and `String.prototype.replace()` with an appropriate regular expression to remove unnecessary characters. | |
| - Use `String.prototype.split()`, `Array.prototype.sort()` and `Array.prototype.join()` on both strings to normalize them, then check if their normalized forms are equal. | |
| const isAnagram = (str1, str2) => { | |
| const normalize = str => | |
| str | |
| .toLowerCase() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Checks if a valid date object can be created from the given values. | |
| - Use the spread operator (`...`) to pass the array of arguments to the `Date` constructor. | |
| - Use `Date.prototype.valueOf()` and `Number.isNaN()` to check if a valid `Date` object can be created from the given values. | |
| const isDateValid = (...val) => !Number.isNaN(new Date(...val).valueOf()); | |
| isDateValid('December 17, 1995 03:24:00'); // true | |
| isDateValid('1995-12-17T03:24:00'); // true |
NewerOlder