Javascript Articles

Page 159 of 534

Moving vowels and consonants using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 327 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

Transforming array of numbers to array of alphabets using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 339 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

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

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 362 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

Obtaining maximum number via rotating digits in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 140 Views

We are required to write a JavaScript function that takes in a positive integer n and returns the maximum number we can get by performing only left rotations on the digits of the number. Problem Left rotation means moving the first digit to the end. For example, rotating 12345 once gives 23451, rotating again gives 34512, and so on. We need to find which rotation produces the largest number. Example Let's implement the solution to find the maximum number through left rotations: const num = 56789; const findMaximum = (num = 1) => ...

Read More

Expanding binomial expression using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 407 Views

We need to write a JavaScript function that expands binomial expressions of the form (ax+b)^n, where a and b are integers, x is a variable, and n is a natural number. The function returns the expanded polynomial as a string. Problem Statement Given an expression like (8a+6)^4, we need to expand it using the binomial theorem. The result should be in the form ax^b+cx^d+ex^f... with coefficients and powers in decreasing order. Understanding the Binomial Theorem The binomial theorem states that (x+y)^n = Σ(C(n, k) * x^(n-k) * y^k) where C(n, k) is the binomial coefficient. ...

Read More

Counting specific digits used in squares of numbers using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 403 Views

We need to write a JavaScript function that takes an integer n (n >= 0) and a digit d (0

Read More

Finding length, width and height of the sheet required to cover some area using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 323 Views

Problem Statement We need to write a JavaScript function that calculates the number of wallpaper sheets required to cover a room's walls. Given the room's length, width, and height, we must determine how many sheets are needed when each sheet has dimensions of 0.52 units width and 10 units length. The function should return 15% more sheets than the calculated requirement to account for waste and cutting. Understanding the Calculation The total wall area of a rectangular room is calculated using the formula: 2 × (length + width) × height. This covers all four walls, excluding ...

Read More

Finding path to the end of maze using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 322 Views

Problem We are required to write a JavaScript function that takes in a matrix of N * N order. The walls in the matrix are marked by 'W' and empty positions are marked by '_'. We can move in any of the four directions at any point. Our function should return true if we can reach the end position [N - 1, N - 1] from the starting position [0, 0], false otherwise. Algorithm Approach We'll use a Breadth-First Search (BFS) algorithm to find if a path exists from the starting position to the end position. ...

Read More

Implement a custom function similar to Array.prototype.includes() method using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

We need to create a custom JavaScript function that mimics the behavior of Array.prototype.includes(). This function should check if a value exists in an array and return a boolean result. Problem We are required to write a JavaScript function that lives on the prototype object of Array. It must take in a literal value, and return true if that value is present in the array it is being called upon, false otherwise. Basic Implementation Here's a simple implementation using a for loop to iterate through the array: const arr = [1, 2, 3, 4, ...

Read More

Finding average age from array of Objects using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

Problem We need to write a JavaScript function that takes an array of objects containing people's data and calculates the average age from the age property. Example Following is the code: const people = [ { fName: 'Ashish', age: 23 }, { fName: 'Ajay', age: 21 }, { fName: 'Arvind', age: 26 }, { fName: 'Mahesh', age: 28 }, { fName: 'Jay', age: 19 }, ]; const findAverageAge = (arr = []) => { ...

Read More
Showing 1581–1590 of 5,340 articles
« Prev 1 157 158 159 160 161 534 Next »
Advertisements