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
// 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
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
// 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 str = "Masautt"; | |
let subString = "sau"; | |
console.log(str.includes(subString)); // 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
<a href="https://google.com" target="_blank">GO TO GOOGLE.COM IN SEPARATE WINDOW</a> |
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 idLength = 6; | |
Math.random().toString(36).slice(idLength); // y80wde7 |
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 = [ | |
{ prop: "7" }, | |
{ prop: "3" }, | |
{ prop: "6" }, | |
{ prop: "1" } | |
] | |
//Sort in ascending | |
arr.sort(function(a, b) { | |
return (a.prop - b.prop); |
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
var arr = ["7", "2", "5", "9"]; | |
// Sort in ascending order? | |
arr.sort(); // --> 2,5,7,9 | |
// Descending order? | |
arr.reverse(); // --> 9,7,5,2 |
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
//ES 7+ | |
Object.entries(obj).length === 0 && obj.constructor === Object | |
//ES 5+ | |
Object.keys(obj).length === 0 && obj.constructor === Object | |
//ES 5- | |
function isEmpty(obj) { | |
for(var prop in obj) { | |
if(obj.hasOwnProperty(prop)) { |