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 strCharCount (str) { | |
| const chars = {}; | |
| for (let char of str) { | |
| chars[char] = 0; | |
| } | |
| for (let char of str) { | |
| if(Object.keys(chars).includes(char)) { |
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 isAnagram (word1, word2) { | |
| return word1.toLowerCase().split("").sort().join("") === word2.toLowerCase().split("").sort().join("") | |
| } |
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 isPalindrome (word) { | |
| invertedString = []; | |
| for (let i = word.length - 1; i >= 0; i--) { | |
| invertedString.push(word[i]) | |
| } | |
| return word.toLowerCase() === invertedString.join("").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
| function sequentialSearch (array, query) { | |
| isItemFound = false; | |
| for (let i = 0; i < array.length; i++) { | |
| if (array[i] === query) return true; | |
| } | |
| return isItemFound; | |
| } |
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 fizzBuzz () { | |
| for (let i = 1; i <= 100; i++) { | |
| if (i % 3 === 0 && i % 5 === 0) { | |
| console.log("FizzBuzz"); | |
| } else if (i % 3 === 0) { | |
| console.log("Fizz"); | |
| } else if (i % 5 === 0) { | |
| console.log("Buzz"); | |
| } else { | |
| console.log(i) |
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 countdown(targetDate) { | |
| const now = new Date(); | |
| const future = new Date(targetDate) | |
| const feb29 = new Date(`February 29 ${future.getFullYear()} 00:00:00`); | |
| const isLeapYear = feb29.getDate() === 29 ? true : false; | |
| const years = future.getFullYear() - now.getFullYear(); | |
| const months = (future.getMonth() + 1) - (now.getMonth() + 1) >= 0 ? |
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
| const nums = []; | |
| function bingo() { | |
| let draw = Math.ceil(Math.random() * 75); | |
| nums.includes(draw) ? bingo() : nums.push(draw); | |
| return nums; | |
| } |
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
| // USING ARRAY | |
| function generatePassword(passwordLength) { | |
| const components = [ | |
| ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"], | |
| ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"], | |
| [0,1,2,3,4,5,6,7,8,9], | |
| ["!", "#", "$", "%", "&", "/", "*", "~", "^", "+", "-",".", "?", "@", "(", ")","[", "]", "{", "}",":", ";"] | |
| ] | |
| const password = []; |
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 invertString (str) { | |
| invertedString = []; | |
| for (let i = str.length - 1; i >= 0; i--) { | |
| invertedString.push(str[i]) | |
| } | |
| return invertedString.join("") | |
| } |