Articles on Trending Technologies

Technical articles with clear explanations and examples

Determining rank on basis of marks in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 964 Views

We are required to write a JavaScript function that takes in an array of numbers representing student marks and returns an array of ranks based on their performance. The function should assign rank 1 to the highest marks, rank 2 to the second highest, and so on. Each student's rank corresponds to their position when marks are sorted in descending order. Problem Statement Given an array of marks, we need to determine the rank of each student based on how their marks compare to others in the class. For example, if the input is: ...

Read More

Moving vowels and consonants using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 333 Views

We are required to write a JavaScript function that takes in a string of English alphabets. Our function should construct a new string where every consonant is pushed forward 9 places through the alphabet, and every vowel is pushed backward 5 places. If they pass 'z', start again at 'a', and if they go before 'a', wrap around to 'z'. Problem Breakdown The transformation rules are: Vowels (a, e, i, o, u): Move backward 5 positions Consonants: Move forward 9 positions Non-alphabetic characters: Keep unchanged Wrapping: Use modulo arithmetic to handle alphabet boundaries Example ...

Read More

What is JavaScript Error Constructor?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 1K+ Views

A JavaScript constructor is a function that creates and initializes an object instance of a class. A constructor is used to create a new object and set values for existing object properties. The Error() constructor in JavaScript is used to create new error objects. Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. Syntax Following is the syntax for an Error() constructor: new Error() new Error(message) new Error(message, options) new Error(message, fileName) new Error(message, fileName, lineNumber) Parameters The Error() constructor ...

Read More

Pair of (adjacent) elements of an array whose sum is lowest JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 539 Views

We are required to write a JavaScript function that takes in an array of numbers. The function should return a subarray of two adjacent elements from the original array whose sum is the least amongst all adjacent pairs of the array. If the length of the array is less than 2, we should return boolean false. Example Input For example, if the input array is: const arr = [41, 44, -12, 13, -23, 1, 5, -4, 2, 2]; Here, the sum of pair [-23, 1] is -22 which is the least for any ...

Read More

JavaScript group array - find the sets of numbers that can be traveled to using the edges defined

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 145 Views

Consider the following input and output arrays: const input = ["0:3", "1:3", "4:5", "5:6", "6:8"]; const output = [ [0, 1, 3], [4, 5, 6, 8] ]; Considering each number as a node in a graph, and each pairing x:y as an edge between nodes x and y, we are required to find the sets of numbers that can be traveled to using the edges defined. In graph theory terms, we need to find the distinct connected components within such a graph. For instance, in the above arrays, there ...

Read More

Next Greater Element in Circular Array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 360 Views

Circular Array An array in which the next element of the last element is the first element of the array is often termed as circular. This concept allows us to treat arrays as if they wrap around, where after the last index, we continue from the first index. Obviously, there exists no such mechanism to store data like this. Data will still be stored in continuous memory blocks, and circular arrays are more like a logical concept than physical reality. Problem We need to find the next greater element for each element in a circular array. The Next ...

Read More

Transforming array of numbers to array of alphabets using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 348 Views

Problem We need to write a JavaScript function that takes an array of numbers and transforms it into a string with four parts separated by hyphens. Each part creates a 4-character "word" from the first two and last two elements of the array under different conditions. The four parts are: Characters from the original array (first, second, second-last, last) Same as above, after sorting the array in ascending order Same as above, after sorting the array in descending order Same as above, after converting to ASCII characters and sorting alphabetically Example Implementation Here's ...

Read More

How to create dynamic breadcrumbs using JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 4K+ Views

The breadcrumbs help website users to understand the navigation path, and windows file explorer is the best example that provides the breadcrumbs. When you open a file explorer, you can see the current location in the file explorer at the top bar. Also, if you click on any location, it jumps to that location. There are two main benefits of using dynamic breadcrumbs on the website. The first is that users can know about the navigation path, and another is users can jump on any location directly in the navigation path. Here, we will see different approaches to ...

Read More

Using recursion to remove consecutive duplicate entries from an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 555 Views

We are supposed to write a function that takes in an array of number/string literals. The function should remove all the redundant consecutive elements of the array without using extra memory space. For example, if the input array is − const arr = [17, 17, 17, 12, 12, 354, 354, 1, 1, 1]; Then the output should be − const output = [17, 12, 354, 1]; Therefore, let's write the code for this function − How the Algorithm Works The recursive function works by checking each element against its ...

Read More

Filter JavaScript array of objects with another array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 640 Views

Suppose, we have an array of objects like this − const arr = [ {area: 'NY', name: 'Bla', ads: true}, {area: 'DF', name: 'SFS', ads: false}, {area: 'TT', name: 'SDSD', ads: true}, {area: 'SD', name: 'Engine', ads: false}, {area: 'NSK', name: 'Toyota', ads: false}, ]; We are required to write a JavaScript function that takes in one such array as the first argument and an array of string literals as the second argument. Our function should then filter the input ...

Read More
Showing 16321–16330 of 61,297 articles
Advertisements