Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Path with smallest sum in JavaScript
This problem involves finding the path through a 2D array that picks exactly one element from each row, where no two adjacent rows can have elements from the same column, and the path has the minimum sum. Problem Statement Given a 2D array, we need to: Pick exactly one element from each row No two elements from adjacent rows can be in the same column Return the minimum sum among all valid paths For example, with the input: const arr = [ [4, 7, 1], ...
Read MoreRemoving a specific substring from a string in JavaScript
We are given a main string and a substring, our job is to create a function, let's say removeString() that takes in these two arguments and returns a version of the main string which is free of the substring. Here, we need to remove the separator from a string, for example: this-is-a-string Using split() and join() Method The most common approach is to split the string by the substring and then join the parts back together: const removeString = (string, separator) => { // we split the string ...
Read MoreDetecting the first non-unique element in array in JavaScript
We are required to write a function that returns the index of the very first element that appears at least twice in the array. If no element appears more than once, we have to return -1. We have to do this in constant space (i.e., without utilizing extra memory). So, let's write the solution for this problem. We will use a for loop to iterate over the array and use the Array.prototype.lastIndexOf() method to check for duplicacy. How It Works The algorithm works by comparing each element's current index with its last occurrence index using lastIndexOf(). ...
Read MoreReversing vowels in a string JavaScript
We are required to write a JavaScript function that takes a string as input and reverse only the vowels of a string. Problem Example If the input string is: const str = 'Hello'; Then the output should be: 'Holle' Notice how 'e' and 'o' swap positions while consonants 'H', 'l', 'l' remain in their original places. Solution Using Two Pointers The most efficient approach uses two pointers from opposite ends of the string: const str = 'Hello'; const reverseVowels = (str = '') => { ...
Read MoreRemoving already listed intervals in JavaScript
JavaScript function that takes in a 2-D array, arr, as the first and the only argument. Each subarray of our input array is an array of exactly two numbers, specifying a time interval. Our function should remove all intervals that are covered by another interval in the array arr. Interval [a, b) is covered by interval [c, d) if and only if c { arr.sort(([a, b], [c, d]) => (a === c ? d - b : a - c)); console.log("After sorting:", arr); ...
Read MoreHow to add Summernote Editor to the webpage in Javascript?
To add Summernote Editor in a webpage, we first need to include the Summernote CSS and JS files in the head of our HTML document. Next, we need to initialize the Summernote editor on a specific text area or div element by calling the Summernote function on it. Finally, we can customize the editor's options and functionality by passing options as an object to the Summernote function. Let us first understand what Summernote editor is. What is Summernote? Summernote is a JavaScript library that allows for the creation and editing of rich text within a web ...
Read MoreChecking for the Gapful numbers in JavaScript
A gapful number is a special type of number that meets specific criteria. Understanding gapful numbers can be useful in mathematical programming and number theory applications. What is a Gapful Number? A number is considered gapful when: It has at least three digits, and It is exactly divisible by the number formed by combining its first and last digits Examples 1053 is a gapful number because it has 4 digits and is divisible by 13 (first digit 1 + last digit 3). 135 is ...
Read MoreDetecting the largest element in an array of Numbers (nested) in JavaScript
We need to find the largest number in a nested array of any depth. This problem requires recursion to traverse through all nested levels and compare each number to find the maximum value. For example, if we have this nested array: const arr = [ 34, 65, 67, [ 43, 76, 87, 23, 56, 7, [ 54, 7, 87, 23, 79, 994, 2 ], ...
Read MoreJavaScript - Complementary Colors Builder
In this article, we will learn to build a JavaScript function that calculates the complementary color for a given hex color code. In web development, working with colors and their relationships is an essential aspect of design and user interface. One of the concepts that designers often use is complementary colors—colors that are opposite each other on the color wheel, providing contrast and enhancing visual appeal. You can try our Online Color Picker Tool to create new colors. Understanding Complementary Colors The following concepts help us understand complementary colors: Complementary Colors: ...
Read MoreJavaScript One fourth element in array
In JavaScript, finding an element that occurs more than one-fourth (25%) of the time in a sorted array is a common algorithmic problem. This requires checking specific positions and using binary search for efficiency. Problem Statement Given a sorted array of integers in increasing order, find the integer that appears more than 25% of the time. There is exactly one such element in the array. For example, in the array [3, 5, 5, 7, 7, 7, 7, 8, 9], the number 7 appears 4 times out of 9 elements (44%), which is more than 25%. Algorithm ...
Read More