Found 6710 Articles for Javascript

Difference Between PHP and JavaScript

Kiran Kumar Panigrahi
Updated on 28-Jul-2022 12:42:36

8K+ Views

JavaScript and PHP are two of the most widely used and flexible computer languages that are used for building websites.PHP is currently the most widely used scripting language for server-side development, whereas JavaScript is a client-side scripting language. PHP is responsible for handling things on the server side, whereas JavaScript is responsible for handling things on the client side of the browser.Since PHP is derived from the C programming language, it is quite simple to learn for anyone who already possesses a solid foundation in C. Although both are used on websites in order to enhance their functionality, one of ... Read More

Checking if a string can be made palindrome in JavaScript

Aayush Mohan Sinha
Updated on 04-Aug-2023 09:49:48

772 Views

Exploring the realm of string manipulation in JavaScript reveals a fascinating challenge: determining whether a given string can be transformed into a palindrome. Palindromes, words or phrases that read the same forwards and backwards, possess an inherent allure and pique the curiosity of developers seeking to unravel their mystical properties. In this article, we embark on an enlightening journey to unravel the intricacies of checking if a string can be made into a palindrome using the powerful language features and algorithms inherent to JavaScript. By delving into the depths of string manipulation and employing innovative techniques, we unravel the enigma ... Read More

Finding n most frequent words from a sentence in JavaScript

AmitDiwan
Updated on 27-Feb-2021 17:08:31

1K+ Views

For the purpose of this question, we define a sentence as a string that contains English alphabets and punctuations and a word is a substring of that sentence joined together by whitespaces.We are required to write a JavaScript function that takes in a sentence string, str, as the first argument and a number, num, as the second argument. The function should first count the frequency of each word in the sentence and then return an array of length num containing num most frequent words placed according to decreasing frequencies.For example −If the input sentence and the number is −const str ... Read More

Can array be divided into n partitions with equal sums in JavaScript

AmitDiwan
Updated on 27-Feb-2021 17:22:40

230 Views

We are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a number, num, as the second argument.The function should determine whether there exists a way of distributing the elements of the array arr into num groups such that all the groups have equal sum. If there exists any such way, our function should return true, false otherwise.For example −If the input array and the number are −const arr = [4, 6, 3, 3, 7, 4, 1]; const num = 4;Then the output should be −const output = true;because the ... Read More

Counting all possible palindromic subsequence within a string in JavaScript

AmitDiwan
Updated on 27-Feb-2021 17:24:49

415 Views

Palindrome Sequence:A string sequence is known as palindrome sequence if it reads the same from front and the back. For instance, 'aba', 'madam, 'did' are all valid palindrome sequences.We are required to write a JavaScript function that takes in a string as the first and the only argument. The string taken as input is guaranteed to consist of only 'a', 'b', 'c' and 'd'. Our function should count and return the number of all contiguous or noncontiguous palindrome subsequences that appear in the string.For example −If the input string is −const str = 'bccb';Then the output should be −const output ... Read More

Find Smallest Letter Greater Than Target in JavaScript

AmitDiwan
Updated on 27-Feb-2021 17:27:05

413 Views

Suppose we are given an array of sorted characters letters containing only lowercase letters. And given a target letter target.We are required to write a JavaScript function that takes in the array as the first argument and the letter as the second. The function is supposed to find the smallest element in the list that is larger than the given target.We have to keep in mind that letters also wrap around. For example, if the target is target = 'z' and letters = ['a', 'b'], the answer is 'a'.For Example −If the input array and letter are −const arr = ... Read More

Finding all valid word squares in JavaScript

AmitDiwan
Updated on 27-Feb-2021 17:29:33

262 Views

Word Square:A word square consists of a set of words written out in a square grid, such that the same words can be read both horizontally and vertically.For instance, once valid word square is −H E A R T E M B E R A B U S E R E S I N T R E N DWe are required to write a JavaScript function that takes in an array of words. The function should return true if the array given as input forms a valid word square, false otherwise.For example −If the input word array is −const arr ... Read More

Finding gcd of two strings in JavaScript

AmitDiwan
Updated on 27-Feb-2021 17:32:38

3K+ Views

In the number system, the Greatest Common Divisor (GCD) of two numbers is that greatest number which divides both the numbers. Similarly, if we apply this concept to strings, the gcd of two strings is the greatest substring (greatest in length) that is present in both the strings.For example −If the two strings are −const str1 = 'abcabc'; const str2 = 'abc';Then the gcd of these strings will be −const gcd = 'abc';We are required to write a JavaScript function that takes in two strings str1 and str2 and computes and returns their gcd.ExampleThe code for this will be − Live ... Read More

Checking digit sum of smallest number in the array in JavaScript

AmitDiwan
Updated on 27-Feb-2021 17:35:00

226 Views

We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument. The function should first pick the smallest number from the array and then calculate the sum of all the digits of the number.If the digit sum of that number is even, we should return true, false otherwise.For example −If the input array is −const arr = [12, 657, 23, 56, 34, 678, 42];Then the output should beconst output = false;because the smallest number in the array is 12 and its digit sum is 1 + 2 = 3, ... Read More

Finding confusing number within an array in JavaScript

AmitDiwan
Updated on 27-Feb-2021 17:37:17

250 Views

Confusing Numbers:A number in an array is confusing if it becomes another number which is also present in the array after we rotate the number by 180 degrees vertically and horizontally. For instance, if we rotate 6 by 180 degrees vertically and horizontally it becomes 9 and vice-versa.We have to keep in mind that only rotations of 0, 1, 6, 8, 9 yield a valid number.We are required to write a JavaScript function that takes in a natural number, num, as the first and the only argument. The function should first construct an array of all natural numbers upto num, ... Read More

Advertisements