5 USEFUL ALGORITHMS IN JAVASCRIPT

FACTORIAL
The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. Such as
4! = 4 * 3 * 2 * 1 = 24
For example:

FACTORIAL RECURSIVE
We can find the factorial of a number using recursion. If you’re having trouble to understand the recursive function then try to think about stack. When a function call is placed the function call is placed on the stack and then the other function calls are placed one top of another. Try to draw the call stack on a note book then may be it will be easier to understand.
For Example:

FIBONACCI SERIES
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
For Example:

LINEAR SEARCH
In computer science, linear search or sequential search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched. Linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the list.
For Example:

BINARY SEARCH
In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful. If the search ends with the remaining half being empty, the target is not in the array.
For Example:

BUBBLE SORT
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order (ascending or descending arrangement). The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.
For Example:

SELECTION SORT
Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. Selection sort is noted for its simplicity, and it has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.
For Example:

INSERTION SORT
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
For Example:
