Skip to content

Instantly share code, notes, and snippets.

View Jagathishrex's full-sized avatar
🎯
Focusing

Jagathishrex

🎯
Focusing
View GitHub Profile
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];
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);
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) {
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 = '#';
var names = ["ram", "raj"];
var result = names.reduce( (acc, name) => {
let obj = {
name,
len : name.length
}
acc.push(obj);
return acc;
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}
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;
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];
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
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) => {