Skip to content

Instantly share code, notes, and snippets.

View sranka23's full-sized avatar
🎯
Focusing

Shourya Ranka sranka23

🎯
Focusing
View GitHub Profile
@sranka23
sranka23 / bubbleCapture.js
Created September 9, 2021 17:57
Event Bubbling and Event Capturing
/*
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.
@sranka23
sranka23 / areStringsCompatible.js
Last active September 9, 2021 13:09
Compatible substrings - 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).
/*
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)){
@sranka23
sranka23 / arrayToObjectParser.js
Last active September 9, 2021 13:00
Object Builder (arrayToObjectParser) : Provided an array of strings, the program returns an output object with key in correct hierarchy.
/*
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:{}
}