Uncategorized

Count pairs that add up to a given sum “k”.

Problem Description: Find the number of pairs in a given array arr that add up to produce a given number k. Basic Approach: function findPairs(arr, k) { let numOfPairs = 0; // 'numerOfPairs' will return double the actual number of pairs because of nested...

read more

Array map(), filter() & reduce() Polyfill

Array.map() Polyfill const array = [1,2,3,4,5]; Array.prototype.myMap = function(callback) { let result = []; for (let i = 0; i < this.length; i++) { result.push(callback(this[i], i, this)); } return result; } let answer1 = array.map((element) => element * 2);...

read more

React Virtual DOM

In React, the Virtual DOM (Document Object Model) is a concept and technique used to efficiently update the user interface (UI) by minimizing direct manipulations to the actual browser DOM. When we use React to build an application, we define the UI using React...

read more

Debouncing

Debouncing Debouncing is a programming technique used to limit the number of invocations of a time-consuming function in order to improve the application performance. const debounce = (func, delay) => { let timerId = null; if (timerId) { clearTimeout(timerId); }...

read more

Lexical Environment

In JavaScript, lexical environment is a data structure that holds variable and function declarations during the execution of the program. It consists of two main components: an environment record and a reference to the outer environment (aka outer/parent scope). The...

read more

Closures

A closure in JavaScript refers to the capability of a function to retain access to variables and other resources from the scope in which it was defined, even when the function is executed outside that scope. It allow a function to remember and access its surrounding...

read more