
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

380 Views
ProblemWe are required to write a JavaScript function that takes in a number, num, as the first and the only argumentOur function should do two thingsFirst of all, it should check whether the number is prime with 10 or not, if its not, we should return -1 (a number is prime with any other number if the only common factor they share is 1).If the number is prime with 10, then we should return the length of the decimal part which repeats itself, when that very number divides 1.For example, if the input to the function is −Inputconst num = ... Read More

91 Views
ProblemWe are required to write a JavaScript function that takes in an array of positive integers, arr, as the first and the only argument.Our function should first join the numbers present in the array and find the single number represented by the array and then return a new array that represents the number which is greater than the input array number by a magnitude of 1.For example, if the input to the function is −Inputconst arr = [6, 7, 3, 9];Outputconst output = [6, 7, 4, 0];Output ExplanationBecause the number represented by input array is 6739 and the required number ... Read More

600 Views
ProblemWe are required to write a JavaScript function that takes in a string of uppercase English alphabets, str, as the first and the only argument.Consider the following mapping between English and Greek letters −A=α (Alpha) B=β (Beta) D=δ (Delta) E=ε (Epsilon) I=ι (Iota) K=κ (Kappa) N=η (Eta) O=θ (Theta) P=ρ (Rho) R=π (Pi) T=τ (Tau) U=μ (Mu) V=υ (Upsilon) W=ω (Omega) X=χ (Chi) Y=γ (Gamma)For all the alphabets that have a Greek mapping our function should create a new string in which the English letter is replaced by corresponding Greek letter and if there exists no mapping we should persist ... Read More

621 Views
ProblemWe are required to write a JavaScript function that takes in an array of integers, arr, as the first and the only argument.The array either consists of all even numbers and just one odd number or consists of all odd numbers and just one even number. Our function should return this one different element from the array.For example, if the input to the function is −Inputconst arr = [5, 9, 7, 11, 34, 23, 77];Outputconst output = 34;Output ExplanationBecause the array consists of all odd numbers but 34 which is even.ExampleFollowing is the code − Live Democonst arr = [5, 9, ... Read More

151 Views
Arithmetic ProgressionArithmetic Progression (AP) is a sequence of numbers such that the difference of any two consecutive numbers is a constant value (aka common difference).For instance, 1, 2, 3, 4, 5, 6, … is an AP, which has a common difference equal to 1 (2 -1).ProblemWe are required to write a JavaScript function that takes in an array of integers, arr, as the first and the only argument.The task of our function is to return the number of arithmetic progressions of size 3 that are possible from that list. In each progression, the differences between the elements must be the ... Read More

171 Views
ProblemWe are required to write a JavaScript function that takes in a number, num, as the first and the only argument.Our function should compute and return the number of digits in the factorial of the number num.For example, if the input to the function is −Inputconst num = 7;Outputconst output = 4;Output ExplanationBecause the value of 7! Is 5040 which contains 4 digits.ExampleFollowing is the code − Live Democonst num = 7; const countDigits = (num = 1) => { let res = 0; while(num >= 2){ res += Math.log10(num); num--; }; return ~~res + 1; } console.log(countDigits(num));Output4

571 Views
ProblemWe are required to write a JavaScript function that takes in an array of integers, arr, as the first and the only argument.Our function is required to pick and return one such index from the array such that the sum of elements on its left side is equal to the sum of elements on its right side. If there exists no such index in the array, we should return -1.For example, if the input to the function is −Inputconst arr = [1, 2, 3, 4, 3, 2, 1];Outputconst output = 3;Output ExplanationBecause the sum of elements at either side of ... Read More

214 Views
ProblemWe are required to write a JavaScript function that takes in a string, str, as the first and the only argument.Our function should create a new string based on the input string where each character in the new string is '(' if that character appears only once in the original string, or ')' if that character appears more than once in the original string.And we should ignore capitaliFor example, if the input to the function is −Inputconst str = 'Success';Outputconst output = ')())())';ExampleFollowing is the code − Live Democonst str = 'Success'; const mapString = (str = '') => { ... Read More

238 Views
ProblemWe are required to write a JavaScript function that takes in an array of integers, arr, that may contain duplicates as the first argument, and a number, num, as the second and final argument.The task of our function is to iterate through the array and check whether there exists some number that appears for more than n times in the array.If there exists any such element, we should delete its extra occurrences to limit its occurrence to at most num.For example, if the input to the function is −Inputconst arr = [4, 1, 3, 1, 4, 1, 3, 4, 2]; ... Read More

1K+ Views
To convert an array to a phone number string in JavaScript can be done by formatting the array elements into the desired phone number pattern. Following are the steps to learn how to convert array to phone number string in Javascript − Ensure that the array has the correct number of elements (usually 10 for a standard phone number). Join the elements of the array into a single string. Format the string into the desired phone number pattern, such as (XXX) XXX-XXXX. Let us understand through ... Read More