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 isObject(obj) { | |
var type = typeof obj; | |
return (type === 'function' || type === 'object') && !!obj; // this will handle obj , null and undefined | |
}; | |
function deepClone(src) { | |
let target = {}; | |
let keys = Object.keys(src); | |
for (let i = 0, len = keys.length; i < len; i++ ) { | |
let key = keys[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
console.delayLog = function(time, message) { | |
var style = | |
"color: rgb(249, 162, 34);" + | |
"font-size: 60px;" + | |
"font-weight: bold;" + | |
"text-shadow: 1px 1px 5px rgb(249, 162, 34);" + | |
"filter: dropshadow(color=rgb(249, 162, 34), offx=1, offy=1);"; | |
setTimeout(function() { | |
console.log(message, style); | |
}, delay); |
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 getTransitionEndEventName() { | |
var transitions = { | |
"transition" : "transitionend", | |
"OTransition" : "oTransitionEnd", | |
"MozTransition" : "transitionend", | |
"WebkitTransition": "webkitTransitionEnd" | |
} | |
let bodyStyle = document.body.style; | |
for(let transition in transitions) { | |
if(bodyStyle[transition] != undefined) { |
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 rand(min, max) { | |
let randomNum = Math.random() * (max - min) + min; | |
return Math.round(randomNum); | |
} | |
var generateColor = function () { | |
// hex numbers | |
var hex = ['a', 'b', 'c', 'd', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; | |
var color = '#'; |
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 names = ["ram", "raj"]; | |
var result = names.reduce( (acc, name) => { | |
let obj = { | |
name, | |
len : name.length | |
} | |
acc.push(obj); | |
return acc; |
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 users = [{"user": "👩🏻💻"},{"user": "👨🏾💻"},{"user": "💃"},{"user": "👨🏻🎓"},{"user": "🧑🏻🏫"},{"user": "🦸♂️"},{"user": "🧟♂️"}]; | |
let resultDetails = users.map(user => { | |
let mark = Math.random() * 100; | |
user.mark = mark; | |
return user | |
}); | |
//for me resultDetails | |
/* | |
0: {user: "👩🏻💻", mark: 76.03572182106969} |
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 search(array, searchElement) { | |
let low = 0; | |
let high = array.length - 1; | |
while(low <= high) { | |
let mid = Math.floor((low+high) /2); | |
let middleElement = array[mid]; | |
if(middleElement == searchElement) { | |
return mid; | |
} else if(middleElement > searchElement) { | |
high = mid -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
function deepFreeze(object) { | |
// Retrieve the property names defined on object | |
var propNames = Object.getOwnPropertyNames(object); | |
// Freeze properties before freezing self | |
for (let name of propNames) { | |
let value = object[name]; |
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 sayHi(user) { | |
let name = (user && user.name && user.name.toUpperCase()) || "Unknown"; | |
console.log(`Hi Mr. ${name}`); | |
} | |
sayHi({}); // Hi Mr. Unknown | |
sayHi(); // Hi Mr. Unknown |
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 square = document.getElementById('square'); | |
square.addEventListener('animationstart', (ev) => { | |
console.log("Animation Startted", ev); | |
}); | |
square.addEventListener('animationiteration', (ev) => { | |
console.log("animation_iteration", ev); | |
}); | |
square.addEventListener('animationend', (ev) => { |