Nikhilesh Aleti

Nikhilesh Aleti

69 Articles Published

Articles by Nikhilesh Aleti

Page 4 of 7

How to implement quick sort in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

In this article, we are going to discuss how to implement quick sort in JavaScript with suitable examples. Quick Sort The Quick sort is a divide and conquer algorithm similar to the merge sort. In this, we pick a pivot element and divide the array around the pivot element. There are many ways to pick the pivot element. Always pick the first element as a pivot element. Always pick the last element as a pivot element. (Implemented in the below program) Pick a random element as pivot ...

Read More

How to find maximum value in an array using spread operator in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 1K+ Views

In this article, we will learn how to find the maximum value in an array using the spread operator with Math.max() in JavaScript. This approach is much cleaner and more efficient than passing array elements individually. What is the Spread Operator? The spread operator (...) expands an array or object into individual elements. It's perfect for passing array elements as separate arguments to functions like Math.max(). // Syntax Math.max(...arrayName) The Problem with Manual Approach Without the spread operator, you'd need to pass each array element individually to Math.max(), which becomes tedious for large ...

Read More

How to use spread operator to join two or more arrays in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 8K+ Views

The spread operator (...) provides a clean, modern way to join multiple arrays in JavaScript. It can be used for both immutable merging (creating new arrays) and mutable merging (modifying existing arrays). What is the Spread Operator? The spread operator (...) expands array elements, allowing you to copy values from one array to another. It performs a shallow copy of the original array. const mergedArray = [...array1, ...array2]; Method 1: Immutable Array Joining This approach creates a new array containing elements from all source arrays, leaving the original arrays unchanged. Joining Two ...

Read More

Is 'floating-point arithmetic' 100% accurate in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 603 Views

In JavaScript, floating-point arithmetic is not 100% accurate due to how computers store decimal numbers in binary format. This leads to precision errors that can affect calculations involving decimal values. Understanding Floating Point Numbers A floating-point number is any number with a decimal point, such as 1.52, 0.14, or -98.345. In JavaScript, all numbers are stored using the IEEE 754 double precision format, which uses 64 bits to represent numbers. Sign Exponent (11 bits) Mantissa/Fraction (52 bits) ...

Read More

In-order traversal in Javascript Tree

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

The tree is a data structure that is comprised of nodes and edges. These entities are interconnected to each other to form a tree structure. Traversing a data structure means visiting each and every node in that structure and bringing out a sequence of values from that. There are three types of traversals namely, in-order (L→ Root→R ), pre-order(Root→L→R) and, post-order(L→ R → Root) In-order Traversal In the In-order Traversal, the left subtree is visited first, followed by the Root node and finally the right subtree. A binary tree will provide sorted key values in ascending order ...

Read More

Removing a node in a Javascript Tree

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

In JavaScript, removing a node from a tree is a fundamental operation that requires handling different scenarios based on the node's structure. This article covers the three main cases for node deletion in Binary Search Trees (BST). Tree Structure and Traversal Overview A tree is a nonlinear data structure consisting of nodes connected by edges. Tree traversal retrieves and processes data from each node in a specific order: In-order traversal − Follows the path (Left → Root → Right) Pre-order traversal − Follows the path (Root → Left → Right) Post-order traversal − Follows the path ...

Read More

How to select a radio button by default in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 14K+ Views

Radio buttons allow users to select one option from multiple choices. Unlike checkboxes, only one radio button in a group can be selected at a time. To make a radio button selected by default, you can use the HTML checked attribute or JavaScript's checked property. Basic Radio Button Syntax Radio buttons are created using the HTML tag with type="radio": Option 1 Option 2 Method 1: Using HTML checked Attribute The simplest way to select a radio button by default is adding the checked attribute directly in HTML: ...

Read More

How to remove event handlers in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 30K+ Views

An event is defined as a change in an object's state. There are a number of events in HTML that show when a user or browser performs a certain action. JavaScript responds to these events when JavaScript code is embedded in HTML and allows execution. The process of responding to events is known as event handling. As a result, JavaScript uses event handlers to handle HTML events. In this article, we are going to discuss how to remove event handlers in JavaScript. Here, we use the removeEventListener() method to remove an event handler from an element in JavaScript. ...

Read More

How to implement merge sort in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 9K+ Views

The Merge Sort algorithm is a divide-and-conquer sorting technique that recursively divides an array into smaller subarrays until each contains a single element, then merges them back in sorted order. The algorithm works by continuously splitting the array in half until it cannot be divided further. Once we have individual elements, we merge them back together in a sorted manner, comparing elements from each subarray and placing them in the correct order. Input-output Scenario Consider an unsorted array that we want to sort using merge sort: Input = [12, 34, 11, 1, 54, 25, 67, ...

Read More

How to clone an object in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 5K+ Views

An object is said to be an entity which has properties and types in it. Example, consider a Person as an object and it has properties like height, weight, age and salary. In the similar way JavaScript also have objects and their defined properties. An object in JavaScript is a complicated data type where it can store various data types in it. Let's consider this example below: const employee = { ...

Read More
Showing 31–40 of 69 articles
Advertisements