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
// Through the console? | |
window.location.replace("https://google.com"); | |
// Put it on a button? | |
document.getElementById("myBtn").addEventListener("click", () => { | |
window.location.href = "https://google.com"; | |
}); |
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]; | |
// Remove from the front | |
arr.pop(); | |
console.log(arr); // --> [2, 3, 4, 5]; | |
// Remove from back | |
arr.unshift( ); |
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 RegEx | |
String.prototype.replaceAll = function(search, replacement) { | |
var target = this; | |
return target.replace(new RegExp(search, 'g'), replacement); | |
}; | |
// Split and Join (Functional Implementation) | |
String.prototype.replaceAll = function(search, replacement) { |
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 lengthOfLongestSubstring = s => { | |
let longest = 0; | |
let start = 0; | |
const seen = {}; | |
[...s].forEach((char, i) => { | |
if (char in seen && start <= seen[char]) { | |
longest = Math.max(i - start, longest); | |
start = seen[char] + 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 |
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
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
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
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 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; | |
}); | |
}); | |
} |