Posts

Bubble sort algorithm in js

Bubble sort is the simplest, comparison-based sorting algorithm. It repeatedly steps through the list to compare and swap adjacent elements if they are in the wrong order. The pass-through process continues until the list comes out sorted. The name "Bubble Sort" was given to this algorithm because with every pass, the smaller elements in the list seem to "bubble" to the top of the list from the array. Steps of Bubble Sort: Compare the first two elements in the array. If the first is greater than the second, then swap. Now, move to the next pair of elements in the array and repeat the comparison and swapping process until it reaches the end. Pass through the array again: The greatest element will move to the end of the array after one pass is done. Do this for the remaining array until it's sorted. Check if sorted: Keep repeating until no swaps are needed, meaning it's sorted. Bubble Sort Program in JavaScript Here’s a program to sort the array const numb...

Closures in JS

Intoduction :- The closure is a function together with a reference to the surrounding state, the lexical environment. Said another way, a closure gives access to the outer function's scope from an inner function. In JavaScript, closures are created every time a function is created—at function creation time. //JS closures const OuterFunction =()=>{ let postedBy="React-Native Developer Community" // local variable created by outer function const InnerFunction=()=>{ //InnerFunction is the inner function, that forms the closure let printMsg="Post by " + postedBy // local variable created by inner function,here used postedBy variable declared in the parent function return printMsg } return InnerFunction() } const msg= OuterFunction() console.log(msg) OuterFunction() declares a local variable postedBy and a function InnerFunction(). That is, InnerFunction() is a function within a function. It is declared...

Introduction of React-Native

What is React-Native ?