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
Web Development Articles
Page 241 of 801
Finding the elements of nth row of Pascal's triangle in JavaScript
Pascal's triangle is a triangular array constructed by summing adjacent elements in preceding rows. Each row starts and ends with 1, and each interior element is the sum of the two elements above it. The first few rows of Pascal's triangle are: 1 1 1 1 2 1 1 3 3 1 ...
Read MoreForming and matching strings of an array based on a random string in JavaScript
In JavaScript, we can check if strings from an array can be formed using characters from a given string. This involves counting character frequencies and matching them against each array element. Problem Statement Given an array of strings and a random string, find the first string from the array that can be completely formed using the characters available in the random string. const arr = ['Dinesh', 'Mahesh', 'Rohit', 'Kamal', 'Jatin Sapru', 'Jai']; const str = 'lsoaakjm'; console.log("Array:", arr); console.log("Available characters:", str); Array: [ 'Dinesh', 'Mahesh', 'Rohit', 'Kamal', 'Jatin Sapru', 'Jai' ] Available ...
Read MoreLargest product of n contiguous digits of a number in JavaScript
We are required to write a JavaScript function that takes in two numbers as first and the second argument, let us call them m and n. The first number will generally be a number with multiple digits and the second number will always be smaller than the number of digits in the first number. The function should find the group of n consecutive digits from m whose product is the greatest. For example, if the input numbers are: const m = 65467586; const n = 3; Then the output should be: ...
Read MoreFinding a number and its nth multiple in an array in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the first argument and a number, say n, as the second argument. The function should check whether there exists two such numbers in the array that one is the nth multiple of the other. If there exists any such pair in the array, the function should return true, false otherwise. For example, if we have an array containing numbers 2 and 8, and n = 4, then 8 is the 4th multiple of 2 (8 = 2 × 4), so the ...
Read MoreUnique number of occurrences of elements in an array in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the first and the only argument. The function should check whether all the integers that are present in the array appear for unique number of times or not. If they do, the function should return true, false otherwise. For example − If the input array is − const arr = [7, 5, 5, 8, 2, 4, 7]; Then the output should be − false because both the integers 7 and 5 appears ...
Read MoreFind Equivalent Value and Frequency in Array in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the only argument. The function should check whether there exists an integer in the array such that its frequency is same as its value. If there exists at least one such integer, we should return that integer otherwise we should return -1. For example − If the input array is − const arr = [3, 4, 3, 8, 4, 9, 7, 4, 2, 4]; Then the output should be − 4 The ...
Read MoreSubstring in infinitely extended string in JavaScript
We are required to write a JavaScript function that takes in a string of characters as the first argument and a start index and end index as second and third argument respectively. The function should find, had that string, provided as the first argument, been extended forever by appending the same string at end each time, what would have been the substring encapsulated by the start index and the end index. For example, if we have the string 'helloo' repeated infinitely like 'hellooheloohelloo...', we can extract any substring using start and end indices. Understanding the Problem If ...
Read MoreCounting largest numbers in row and column in 2-D array in JavaScript
We are required to write a JavaScript function that takes in a two-dimensional array of integers as the only argument. The task of our function is to calculate the count of all such integers from the array that are the greatest both within their row and the column. The function should then return that count. For example − If the input array is − const arr = [ [21, 23, 22], [26, 26, 25], [21, 25, 27] ]; Then the output should be ...
Read MoreReturning acronym based on a string in JavaScript
We need to write a JavaScript function that creates an acronym from a string by taking the first letter of each word that starts with an uppercase letter. The function should build and return the acronym based on the string phrase provided as input. While constructing the acronym, the function should only consider words that start with an uppercase letter. Problem Statement Given a string like "Polar Satellite Launch Vehicle", we want to extract the first letter of each capitalized word to form "PSLV". Input: 'Polar Satellite Launch Vehicle' Output: 'PSLV' Solution ...
Read MoreCheck if a string is repeating in itself in JavaScript
In JavaScript, we often need to determine if a string consists of a repeating pattern. This involves checking if the entire string can be formed by repeating a smaller substring multiple times. For example, the string 'carcarcarcar' is made by repeating 'car' four times, so it should return true. However, 'abcdef' has no repeating pattern, so it should return false. Problem Understanding We need to write a function that: Takes a string as input Returns true if the string is formed by repeating a pattern Returns false if no repeating pattern exists Example Input ...
Read More