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
Javascript Articles
Page 143 of 534
Finding 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 MoreMaximum Product of Two Numbers in a List of Integers in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the first and only argument. The function should find the maximum product that can be achieved by multiplying any two elements of the array. The condition is that we have to do this in linear time O(n) and constant space O(1). For example, if the input array is: const arr = [3, 9, 2, 1, 0]; Then the output should be: const output = 27; because it's the greatest product and can be achieved ...
Read MoreSubarray pairs with equal sums in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the only argument. The function should determine whether there exists any way in which we can split the array into two subarrays such that the sum of the elements present in the two subarrays are equal. While dividing the elements into subarrays we have to make sure that no element from the original array is left. Problem Understanding For example, if the input array is: const arr = [5, 3, 7, 4, 1, 8, 2, 6]; Then ...
Read MoreSum of All Possible Odd Length Subarrays in JavaScript
We are required to write a JavaScript function that takes in an array of integers as the only argument. The function should first permute all possible subarrays from the original array that have an odd length. And then the function should find the combined sum of all the elements of those subarrays and return the sum. For example, if the input array is: const arr = [1, 2, 3]; Then the output should be: const output = 12; Because the desired subarrays are [1], [2], [3], [1, 2, 3] with ...
Read More