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
// Loop through the items in the array and replace the object keys | |
/** | |
* Input: [{ id: 1, created_at: "2021-07-19T07"}] | |
* Output: [{ id: 1, createdAt: "2021-07-19T07"}] | |
*/ | |
const parsedRows = result.rows.map(row => { | |
const replaced = {}; | |
for(let key in row) { |
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
// Calculates value of the sum of the digits recursively | |
function digital_root(n) { | |
return (n - 1) % 9 + 1; | |
} | |
digital_root(456); // returns 6 |
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 person1 = { | |
name: "Ansar", | |
sayHi() { | |
console.log("Hi " + this.name); | |
} | |
}; | |
const person2 = { | |
name: "John" | |
}; |
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
/** | |
* This function checks if the string for the scope is provided and then calls appropriate function to returns the HTML Elements. | |
* @param {String} selector | |
* @param {String} scope | |
*/ | |
window.$$ = (selector, scope) => { | |
let scoping; | |
if(scope) { | |
scoping = getElements(scope); |
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
/* | |
Given a string, return a new string with the reversed | |
order of characters | |
*/ | |
function reverse(str) { | |
return str.split('').reverse().join(''); | |
} |
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 fact = n => n === 1 ? 1 : n * fact(n - 1); | |
fact(5) // 120 |
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 Slice Method | |
* Returns an independent copy/clone of an array | |
* @param [Array] arr - Array to be cloned | |
* @returns [Array] | |
*/ | |
const arrClone = ( arr => arr.slice()); | |
/** | |
* Using Spread Operator |
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
/** | |
* ES6 - Using .assign method | |
* Returns an independent copy/clone of an object | |
* @param {Object} obj - Object to be cloned | |
* @returns {Object} | |
*/ | |
const deepClone = ( obj => Object.assign( {}, obj )); | |