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
/* | |
Author: Shourya Ranka | |
Objective: Demonstrate event bubbling and capturing | |
*/ | |
// event binding on parent <div> is captured by child elements too. Clicking on inner divs will pick this event. | |
document.querySelector('#target1').addEventListener('click', function(e){ | |
console.log(e.target.id); | |
},true); | |
// below three events indicate event bubbling, any event triggered on the child element will be bubbled up to parent too. |
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
/* | |
Author: Shourya Ranka | |
Objective: Two strings are compatible if one string of length "m" is made of of "m" consecutive characters in the second string of length "n" (m<=n). | |
1. "facebook", "beo" // compatible - b,e,o are consecutive letters in 'facebook' though the order is different. | |
2. "facebook", "aco" // not compatible - a,c,o are not consective letters present in 'facebook' | |
*/ | |
const stringSorter = str => str.split('').sort().join(''); | |
const areStringsCompatible = (str1, str2) => { | |
if(!(str1 && str2)){ |
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
/* | |
Author: Shourya Ranka | |
Objective : Provided an array of strings, the program returns an output object with key in correct hierarchy. | |
input : ["root", "root.user", "root.user.a", "root.a"] | |
output : { | |
root: { | |
a:{}, | |
user:{ | |
a:{} | |
} |