Imran Alam has Published 54 Articles

How to implement enqueue and dequeue using only two stacks in JavaScript?

Imran Alam

Imran Alam

Updated on 03-Aug-2022 13:37:11

1K+ Views

In this tutorial, we'll be implementing a queue using only two stacks. This is a pretty common interview question so it's good to know how to do it. Algorithm STEP 1 − We have two stacks, one for enqueueing and one for dequeueing. STEP 2 − We enqueue by ... Read More

How to replace characters except last with a mask character in JavaScript?

Imran Alam

Imran Alam

Updated on 03-Aug-2022 13:29:19

2K+ Views

JavaScript has a built-in function called replace() that can be used to replace characters in a string. This function takes two arguments: the first argument is the character or characters to be replaced, and the second argument is the character or characters to replace them with. Syntax Following is the ... Read More

How to create a chessboard pattern with JavaScript and DOM?

Imran Alam

Imran Alam

Updated on 03-Aug-2022 12:02:51

5K+ Views

With a little bit of JavaScript and DOM manipulation, you can create all sorts of interesting patterns on a webpage. In this tutorial, we'll show you how to create a chessboard pattern using JavaScript and the DOM.ApproachSTEP 1 − We start by creating a element with an id of ... Read More

Difference between Function.prototype.apply and Function.prototype.call in JavaScript

Imran Alam

Imran Alam

Updated on 29-Jul-2022 08:17:33

412 Views

Function.prototype.apply and Function.prototype.call are methods that allow you to call a function with a specific this value and arguments. The main difference between the two is that apply lets you pass in an array of arguments, while call requires you to list the arguments one by one.Function.prototype.applyFunction.prototype.apply is a method ... Read More

How to convert a 2D array to a CSV string in JavaScript?

Imran Alam

Imran Alam

Updated on 21-Jul-2022 14:34:55

829 Views

The CSV (Comma Separated Values) file format is a popular way of exchanging data between applications and data stores. The CSV file format is simple and easy to understand, and many applications and programming languages support it.In JavaScript, there are a number of ways to convert an array of data ... Read More

How to apply function against an accumulator and each key of object in JavaScript?

Imran Alam

Imran Alam

Updated on 02-Jul-2022 07:41:00

401 Views

In JavaScript, We can use the reduce() method to apply a function against an accumulator and each key of an object (from left to right).The reduce() method is called on a given array and takes in a callback function as its first argument. Please refer to Array reduce() for more ... Read More

How to get the sum of the powers of all numbers in JavaScript?

Imran Alam

Imran Alam

Updated on 02-Jul-2022 07:38:44

360 Views

In this tutorial, we'll be discussing how to get the sum of the powers of all the numbers from start to end in JavaScript. We'll be using the built-in Math.pow() method to calculate the powers and the Array reduce() method to sum up the values.Using the Math.pow() methodThe Math.pow() method ... Read More

How to return a passed string with letters in alphabetical order in JavaScript?

Imran Alam

Imran Alam

Updated on 01-Jul-2022 13:42:27

2K+ Views

We could apply String split(), Array sort() and Array join() methods to write a function that returns a passed string with letters in alphabetical order in JavaScript. A JavaScript function is a block of code that is executed when it is invoked. A string is a sequence of characters. In ... Read More

What is difference between unescape() and escape() functions in JavaScript?

Imran Alam

Imran Alam

Updated on 01-Jul-2022 13:08:25

2K+ Views

JavaScript provides two functions for dealing with encoded strings: escape() and unescape(). The escape() function is used to encode a string, making it safe for use in a URL. The unescape() function is used to decode an encoded string.The differencesThe main difference between the two functions is that escape() encodes ... Read More

What is the difference between undefined and not defined in JavaScript?

Imran Alam

Imran Alam

Updated on 01-Jul-2022 13:04:34

6K+ Views

In JavaScript, there are two main ways that a variable can be "undefined". The first is when you declare a variable without giving it a value. The second is when you try to access a variable that does not exist.Undefined in JavaScript When a variable is declared without a value, it ... Read More

Advertisements