Javascript Articles

Page 104 of 534

Algorithm for matrix multiplication in JavaScript

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

Matrix multiplication is a fundamental operation in linear algebra where two matrices are multiplied to produce a third matrix. In JavaScript, we can implement this algorithm using nested loops to calculate the dot product of rows and columns. Matrix Multiplication Rules For matrix multiplication to be valid, the number of columns in the first matrix must equal the number of rows in the second matrix. If matrix A is m×n and matrix B is n×p, the result will be an m×p matrix. Matrix A (m×n) ...

Read More

Program to implement Bucket Sort in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 731 Views

Bucket Sort is an efficient sorting algorithm that works by distributing elements into multiple buckets based on their values, then sorting each bucket individually. This approach is particularly effective when the input is uniformly distributed across a range. How Bucket Sort Works The algorithm follows these key steps: Find the minimum and maximum values in the array Create a specific number of buckets to hold ranges of values Distribute array elements into appropriate buckets Sort each bucket using a suitable sorting algorithm (like insertion sort) Concatenate all sorted buckets to get the final result ...

Read More

Computing zeroes (solutions) of a mathematical equation in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 145 Views

We are required to write a JavaScript function that takes in three numbers representing the coefficients of a quadratic equation (ax² + bx + c = 0). The function should find the real roots of the equation or return false if the roots are complex (non-real). A quadratic equation has real roots when its discriminant (b² - 4ac) is greater than or equal to zero. The roots are calculated using the quadratic formula: x = (-b ± √discriminant) / (2a). Syntax // Quadratic formula: x = (-b ± √(b² - 4ac)) / (2a) // Discriminant = ...

Read More

Finding place value of a number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 852 Views

In JavaScript, finding the place value of digits means extracting each digit's positional worth. For example, in the number 1234, the place values are [1000, 200, 30, 4]. We need to write a function that takes a positive integer and returns an array with the place values of all digits. Problem Example If the input number is: const num = 1234; Then the output should be: [1000, 200, 30, 4] Using Recursive Approach This problem is well-suited for recursion since we need to process each digit and calculate ...

Read More

Reversing the even length words of a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 403 Views

We are required to write a JavaScript function that takes in a string and reverses the words in the string that have an even number of characters in them. Let's say the following is our string: const str = 'This is an example string'; We want to reverse the even length words of the above string i.e. reverse the following words: This (4 characters) is (2 characters) an (2 characters) string (6 characters) The word "example" has 7 characters (odd length), so it remains unchanged. Syntax ...

Read More

Differences in two strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 508 Views

We are required to write a JavaScript function that takes in two strings and find the number of corresponding dissimilarities in the strings. The corresponding elements will be dissimilar if they are not equal at the same position. Example Strings Let's say the following are our strings: const str1 = 'Hello world!!!'; const str2 = 'Hellp world111'; In this case, we need to compare each character at the same index and count how many positions have different characters. Method 1: Using a For Loop const str1 = 'Hello world!!!'; const str2 ...

Read More

Finding the index of the first repeating character in a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 637 Views

We are required to write a JavaScript function that takes in a string and returns the index of the first character that appears twice in the string. If there is no such character then we should return -1. Let's say the following is our string − const str = 'Hello world, how are you'; We need to find the index of the first repeating character. Understanding the Problem In the string "Hello world, how are you", we need to find which character repeats first. The character 'l' appears at index 2 and again ...

Read More

Column sum of elements of 2-D arrays in JavaScript

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

We have an array of arrays and are required to write a function that takes in this array and returns a new array that represents the sum of corresponding elements of original array. If the original array is: [ [43, 2, 21], [1, 2, 4, 54], [5, 84, 2], [11, 5, 3, 1] ] Then the output should be: [60, 93, 30, 55] This means we add all elements at index 0 (43+1+5+11=60), all elements at index 1 (2+2+84+5=93), ...

Read More

Finding smallest number that satisfies some conditions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 261 Views

We are required to write a JavaScript function that takes in a number as the first argument, say n, and an array of numbers as the second argument. The function should return the smallest n-digit number which is a multiple of all the elements specified in the array. If there exist no such n-digit element then we should return the smallest such element. For example: If the array is − const arr = [12, 4, 5, 10, 9] For both n = 2 and n = 3, we need to find the smallest number ...

Read More

Finding the inclination of arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 162 Views

We are required to write a JavaScript function that takes in an array of numbers and returns true if it's either strictly increasing or strictly decreasing, otherwise returns false. In Mathematics, a strictly increasing function is that function in which the value to be plotted always increases. Similarly, a strictly decreasing function is that function in which the value to be plotted always decreases. Understanding the Concept An array has a consistent inclination when: Strictly increasing: Each element is greater than the previous one Strictly decreasing: Each element ...

Read More
Showing 1031–1040 of 5,340 articles
« Prev 1 102 103 104 105 106 534 Next »
Advertisements