This file contains 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
// Smooth scrolling | |
$("a[href*='#']:not([href='#'])").click(function () { | |
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') | |
|| location.hostname == this.hostname) { | |
var target = $(this.hash); | |
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); | |
if (target.length) { | |
$('html,body').animate({ |
This file contains 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 isInViewPort(element){ | |
let elementTop = $(element).offset().top; | |
let elementBottom = elementTop + $(element).outerHeight(); | |
let viewPortTop = $(window).scrollTop(); | |
let viewPortBottom = viewPortTop + $(window).height(); | |
return elementBottom > viewPortTop && elementTop < viewPortBottom; | |
} |
This file contains 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
// Set hash location for url address | |
function setHashLocation(id) { | |
var scrollmem = $('html,body').scrollTop(); | |
window.location.hash = id; | |
$('html,body').scrollTop(scrollmem); | |
} |
This file contains 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
1) First fetch all changes: | |
$ git fetch --all | |
2) Then reset the master: | |
$ git reset --hard origin/master | |
3) Pull/update: | |
$ git pull |
This file contains 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 person = { | |
name : 'Bob', | |
sayName : function() { | |
setTimeout(function() { | |
console.log(`I'm ${this.name}`); | |
}, 1000); | |
} | |
}; | |
person.sayName(); |
This file contains 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, 5, 'a', 3, 'f', '3', 5, 3, 'b', 'e', 'f']; | |
let ans = deduplicate(arr); | |
console.log(ans); | |
// Expected output: [1, 5, "a", 3, "f", "3", "b", "e"] | |
function deduplicate(arr) { | |
let isExist = (arr, x) => { | |
for(let i = 0; i < arr.length; i++) { | |
if (arr[i] === x) return true; |
This file contains 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 a = { | |
x: 1, | |
getX: function() { | |
return this.x; | |
} | |
}; | |
let b = Object.create(a); | |
b.x = 10; |
This file contains 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
Object.prototype.objCustom = function() {}; | |
Array.prototype.arrCustom = function() {}; | |
let a = [3, 5, 7]; | |
a.x = 'hello'; | |
Object.defineProperty(a, 'y', {}); | |
Object.defineProperty(a, 'z', { | |
enumerable: true | |
}); |
This file contains 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, "hi", {x : 2}, [3, 4]]; | |
delete arr[1]; | |
console.log(arr.length); | |
// What will console print? |
This file contains 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 foo = function bar() { | |
return "hello"; | |
} | |
console.log(typeof bar); | |
// What will console print? | |
// Ref: Named function expression | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function |