Web Development Articles

Page 261 of 801

Integers have sum of squared divisors as perfect square in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 345 Views

Problem We need to write a JavaScript function that takes a range specified by two numbers m and n, and finds all integers between m and n where the sum of their squared divisors is itself a perfect square. The function should return an array of subarrays, where each subarray contains the number and the sum of its squared divisors. Understanding the Concept For a number to qualify, we need to: Find all divisors of the number Square each divisor and sum them up ...

Read More

Finding the length of the diagonal of a cuboid using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 282 Views

We need to write a JavaScript function that calculates the diagonal length of a cuboid (rectangular box) given its length, width, and height dimensions. Problem We are required to write a JavaScript function that takes in the length, width and height of a cuboid and return the length of its diagonal. Formula The space diagonal of a cuboid is calculated using the 3D Pythagorean theorem: diagonal = √(length² + width² + height²) Example Following is the code: const height = 10; const width = 12; const length = 15; ...

Read More

Squared and square rooted sum of numbers of an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 461 Views

Problem We are required to write a JavaScript function that takes in an array of numbers. Our function should take each number in the array and square it if it is even, or square root the number if it is odd and then return the sum of all the new numbers rounded to two decimal places. Example Following is the code − const arr = [45, 2, 13, 5, 14, 1, 20]; const squareAndRootSum = (arr = []) => { const res = arr.map(el => { ...

Read More

Turn each character into its ASCII character code and join them together to create a number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 432 Views

Problem We need to write a JavaScript function that takes a string and converts each character to its ASCII code, joins them to create a number, replaces all instances of 7 with 1, and returns the difference between the original and modified numbers. Understanding the Process The algorithm involves several steps: Convert each character to its ASCII code using charCodeAt() Join all ASCII codes to form one large number Replace all occurrences of digit 7 with 1 Calculate the difference between original and modified numbers ...

Read More

Unique pairs in array that forms palindrome words in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 207 Views

We are required to write a JavaScript function that takes in an array of unique words. Our function should return an array of all such index pairs, the words at which, when combined yield a palindrome word. Problem Given an array of unique words, find all pairs of indices where concatenating the words at those indices creates a palindrome. A palindrome reads the same forwards and backwards, like "racecar" or "abccba". Example Following is the code: const arr = ["abcd", "dcba", "lls", "s", "sssll"]; const findPairs = (arr = []) => { ...

Read More

Sorting according to number of 1s in binary representation using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 240 Views

Problem We need to write a JavaScript function that takes an array of numbers and sorts them in descending order based on the count of 1s in their binary representation. Understanding Binary Representation Every number has a binary representation. For example: 5 → 101 (two 1s) 78 → 1001110 (four 1s) 11 → 1011 (three 1s) Solution Approach We'll create two functions: one to count 1s in binary representation and another to sort the array. const arr = [5, 78, 11, 128, 124, 68, 6]; const countOnes = (num) => ...

Read More

Moving all vowels to the end of string using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 398 Views

In JavaScript, you can move all vowels to the end of a string while maintaining the relative positions of consonants. This is useful for text processing and string manipulation tasks. Problem We need to write a JavaScript function that takes a string and constructs a new string where all consonants maintain their relative positions and all vowels are moved to the end. Approach The solution involves iterating through the string, separating vowels and consonants into different variables, then concatenating them with consonants first and vowels at the end. Example const str = 'sample ...

Read More

Finding number of open water taps after n chances using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 161 Views

Problem Suppose a school organises this game on their Annual Day celebration − There are "n" water taps and "n" students are chosen at random. The instructor asks the first student to go to every tap and open it. Then he has the second student go to every second tap and close it. The third goes to every third tap and, if it is closed, he opens it, and if it is open, he closes it. The fourth student does this to every fourth tap, and so on. After the process is completed with the "n"th student, how many taps ...

Read More

Sum of individual even and odd digits in a string number using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 657 Views

We are required to write a JavaScript function that takes in a string containing digits and our function should return true if the sum of even digits is greater than that of odd digits, false otherwise. Problem Statement Given a string of digits, we need to: Separate even and odd digits Calculate the sum of even digits Calculate the sum of odd digits Compare which sum is greater Example Let's implement a solution that processes each digit and compares the sums: ...

Read More

Finding the sum of all numbers in the nth row of an increasing triangle using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 298 Views

For the purpose of this problem, an increasing triangle is a structure where numbers are arranged in rows, with each row containing one more number than the previous row, and all numbers are consecutive starting from 1. Understanding the Triangle Structure The increasing triangle looks like this: 1 2 3 4 5 6 7 8 9 10 Each row n contains n consecutive numbers. Row 1 has 1 number, row 2 has 2 numbers, row 3 has 3 numbers, and so on. Problem Statement We need ...

Read More
Showing 2601–2610 of 8,010 articles
« Prev 1 259 260 261 262 263 801 Next »
Advertisements