Recursive method to add sum of integers

In this small article I am going to show you how we can easily perform a recursive method to add sum of integers till the given number. let sum = (n)=> n ? n + sum(n-1) :...
Read More ⟶

Debounce in JavaScript

Debounce in JavaScript generally states that you want to delay a function in particular event. Events such as mouse move, click etc. Lets take an example:- you have an event of mouse move on a button. When you move your mouse over the button it will fire the event...
Read More ⟶

Multiple bracket function in JavaScript

Multiple bracket function in JavaScript are tricky to understand. The bracket generally resemble a function without bracket it would be a variable. So, if you want multiple bracket function you would need to return multiple function in it. For eg: look at the code...
Read More ⟶

Call, Apply and Bind in JavaScript

Call, Apply and Bind in JavaScript are very powerful function that allows you to borrow object properties and method. To understand this I am going to put a very simple example to output same result using all three function. (call, apply and bind). Let us look at the...
Read More ⟶

JavaScript regular expression to validate URL

var expression = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi; var regex = new RegExp(expression); var t = 'www.facebook.com'; if (t.match(regex)) { alert("Successful match"); } else { alert("No...
Read More ⟶

Create custom filter using Array Prototype

As a JavaScript developer most of us are pretty familiar with filter method of JavaScript. Like the code below. let num = [1,2,3,4,5,6]; num.filter(x=> x>2 ); console.log(num); // output is [3,4,5,6] In the above function we have simply inbuilt filter...
Read More ⟶

Validate URL for image with valid extension

This function will allow you to validate any image url that ends with either jpeg, jpg, gif or png. function checkURL(url) { return(url.match(/\.(jpeg|jpg|gif|png)$/) !=...
Read More ⟶

Angular Lifecycle Hooks

In this article, we will know about the lifecycle of Angular components. Since, in Angular, a component is the main building block of the application, it is very important to understand the lifecycle processing steps of the components so that we can understand the...
Read More ⟶

CaesarCipher string manipulation

function CaesarCipher(str,num) { if(num < 0) { return CaesarCipher(str, num + 26); } let output = ""; for(let i=0; i<str.length; i++) { let c = str[i]; if(c.match(/[a-z]/i)) { let code = str.charCodeAt(i); if(code >=...
Read More ⟶

Sorting Algorithms

Sorting an array with an higher order function now a days is very easy. let x = [2,5,8,1,3] x.sort() //[1,2,3,5,8] Now doing same thing with vanilla JavaScript algorithms. let a = [5,2,1,3,7,100]; let Alen = a.length; let ans = []; for(let...
Read More ⟶