Articles on Trending Technologies

Technical articles with clear explanations and examples

JavaScript - Complementary Colors Builder

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

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 More

JavaScript One fourth element in array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 239 Views

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

Moving every alphabet forward by 10 places in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 351 Views

Problem We need to write a JavaScript function that takes a string of English alphabets and shifts every letter forward by 10 positions. When a letter goes past 'z', it wraps around to start again at 'a'. Example Following is the code − const str = 'sample string'; const moveStrBy = (num = 10) => { return str => { const calcStr = (ch, code) => String .fromCharCode(code + (ch.charCodeAt(0) - ...

Read More

JavaScript Strings: Replacing i with 1 and o with 0

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 338 Views

We are required to write a function that takes in a string as one and only argument and returns another string that has all 'i' and 'o' replaced with '1' and '0' respectively. It's one of those classic for loop problems where we iterate over the string with its index and construct a new string as we move through. Using For Loop The most straightforward approach is to iterate through each character and build a new string: const string = 'Hello, is it raining in Amsterdam?'; const replaceChars = (str) => { ...

Read More

Inserting empty string in place of repeating values in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 527 Views

We have to write a function that takes in an array, removes all duplicates from it and inserts the same number of empty strings at the end. For example: If we find 4 duplicate values we have to remove them all and insert four empty strings at the end. Therefore, let's write the code for this function − Example The code for this will be − const arr = [1, 2, 3, 1, 2, 3, 2, 2, 3, 4, 5, 5, 12, 1, 23, 4, 1]; const deleteAndInsert = arr => { ...

Read More

Finding square root of a non-negative number without using Math.sqrt() JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 523 Views

We are required to write a JavaScript function that takes in a non-negative integer and computes and returns its square root without using Math.sqrt(). We can floor off a floating-point number to an integer. For example: For the number 15, we need not return the precise value, we can just return the nearest smaller integer value that will be 3, in case of 15. We will make use of the binary search algorithm to converge to the square root of the given number. Binary Search Approach The binary search method works by maintaining a range [left, ...

Read More

Combine array of objects in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 471 Views

Suppose, we have an array of objects that contains data about some students like this: const arr = [{ name: 'A', idNo: 1, marks: { math: 98, sci: 97, eng: 89 } }, { name: 'B', idNo: 2, marks: { ...

Read More

Finding sequential digit numbers within a range in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 506 Views

A number has sequential digits if and only if each digit in the number is one more than the previous digit. For example, 1234, 2345, and 6789 are sequential digit numbers, while 1324 and 2468 are not. Problem Statement We need to write a JavaScript function that takes an array of two elements specifying a range and returns a sorted array of all integers within that range (inclusive) that have sequential digits. For example, if the input is: const arr = [1000, 13000]; The output should be: [1234, 2345, 3456, 4567, ...

Read More

Sum of perimeter of all the squares in a rectangle using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 408 Views

Problem: Suppose there are 5 squares embedded inside a rectangle like this − 1 1 2 3 5 Side lengths: 1, 1, 2, 3, 5 Perimeters: 4, 4, 8, 12, 20 The squares follow a Fibonacci-like pattern ...

Read More

How to set the border scale factor of Rectangle using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 532 Views

In this tutorial, we are going to learn how to set the border scale factor of a Rectangle using FabricJS. Rectangle is one of the various shapes provided by FabricJS. In order to create a rectangle, we will have to create an instance of fabric.Rect class and add it to the canvas. We can use the borderScaleFactor property which specifies the scale factor of the object's controlling borders. This property controls the thickness of the selection border that appears when an object is selected on the canvas. Syntax ...

Read More
Showing 16341–16350 of 61,298 articles
Advertisements