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 checkPalindrome (str) { | |
| return str == str.split('').reverse().join(''); | |
| } | |
| console.log(checkPalindrome("Marek")); // --> false | |
| console.log(checkPalindrome("kayak")); // --> true | |
| // https://stackoverflow.com/questions/14813369/palindrome-check-in-javascript |
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 firstNonRepeat(string) { | |
| return string.split('').filter(function (character, index, obj) { | |
| return obj.indexOf(character) === obj.lastIndexOf(character); | |
| }).shift(); | |
| } | |
| console.log(firstNonRepeat("----Marek-----")); // --> "M" |
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 reverseWords(str) { | |
| var result = ""; | |
| var wordArray = str.split(" "); | |
| for(var i = wordArray.length - 1; i >= 0; i--) { | |
| result += wordArray[i] + " "; | |
| } | |
| return result.trim(); | |
| } | |
| console.log(reverseWords("Marek E. Sautter")); // --> "Sautter E. Marek" |
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 getAllPermutations(string) { | |
| var results = []; | |
| if (string.length === 1) { | |
| results.push(string); | |
| return results; | |
| } | |
| for (var i = 0; i < string.length; i++) { | |
| var firstChar = string[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 maxChar(myStr) { | |
| let charObj = {}; | |
| return [...myStr].reduce((_, char) => { | |
| if (char in charObj) charObj[char]++; | |
| else if (char !== " ") charObj[char] = 1; | |
| return Object.keys(charObj).reduce((a, b) => { | |
| return charObj[a] > charObj[b] ? a : b; | |
| }); | |
| }); | |
| } |
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 isLowerCase(str) { | |
| return str === str.toLowerCase(); | |
| } | |
| let fname = "Marek"; | |
| let lname = "sautter"; | |
| console.log(isLowerCase(fname)); // --> false | |
| console.log(isLowerCase(lname)); // --> true |
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 isUpperCase(str) { | |
| return str === str.toUpperCase(); | |
| } | |
| let fname = "Marek"; | |
| let lname = "SAUTTER"; | |
| console.log(isUpperCase(fname)); // --> false | |
| console.log(isUpperCase(lname)); // --> true |
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
| let str = "marek"; | |
| console.log(str.split("").reverse().join("")); // --> "keram" | |
| // Takes string, splits into char array, reverses array, then joins back to string |
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
| let arr = [1,2,3,4,5] | |
| console.log(arr.reverse()); //--> [5,4,3,2,1] | |
| // Performs on original array | |
| console.log(arr); // --> [5,4,3,2,1] |
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 removeVowels = (str) => { | |
| return str.replace(/[aeiou]/gi, ''); | |
| } | |
| //https://stackoverflow.com/questions/13829289/javascript-strip-vowels |