Posts

Binary Sreach Algorithm : Optimized way to get the index of the mid element

The classical way to find the mid element in an array would be (start+end)/2.  But integershave a limited range and what if the size of the array is too large and (start+end) exceeds the range of integers in java?? Hence, inorder to make optimize it I learnt a new way to find the mid element which is  start + (end-start)/2 in this way, even if the size of the array exceeds the integer range, the end-start would make it smaller. 

The third parameter - Event bubbling and Event capturing

I have been learning about events in JavaScript lately. I stumbled upon a very popular topic and learned something new that I wanted to share. It's about event bubbling and event capturing. As you can see, I have created a ul element with 5 images listed under it, each inside li elements. I've also added corresponding IDs to target each image and the ul element. __________________________________________ In the above code, one event listener targets the ul element as a whole. Whenever an image inside the ul element is clicked, the event fires, and it is logged in the console. Notice that the third parameter is set to false. Secondly, there's another event listener that gets triggered when the specific target sheep image inside the ul element is clicked, logging the corresponding message. Now, note that the third parameter in both events is false, leading to two consequences: Case 1: Event Bubbling (3rd parameter: false) When an image inside the ul element is clicked (other ...