
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

2K+ Views
We are required to write a JavaScript function that takes in the following array of numbers,const arr = [34, 56, 3, 56, 4, 343, 68, 56, 34, 87, 8, 45, 34];and returns a new filtered array that does not contain any prime number.ExampleFollowing is the code −const arr = [34, 56, 3, 56, 4, 343, 68, 56, 34, 87, 8, 45, 34]; const isPrime = n => { if (n===1){ return false; }else if(n === 2){ return true; }else{ for(let x = 2; x < n; x++){ if(n % x === 0){ return false; } } return true; }; }; const filterPrime = arr => { const filtered = arr.filter(el => !isPrime(el)); return filtered; }; console.log(filterPrime(arr));OutputFollowing is the output in the console −[ 34, 56, 56, 4, 343, 68, 56, 34, 87, 8, 45, 34 ]

104 Views
We are required to write a JavaScript function that imitates a network request, for that we can use the JavaScript setTimeout() function, that executes a task after a given time interval.Our function should return a promise that resolves when the request takes place successfully, otherwise it rejectsExampleFollowing is the code −const num1 = 45, num2 = 48; const res = 93; const expectedSumToBe = (num1, num2, res) => { return new Promise((resolve, reject) => { setTimeout(() => { if(num1 + num2 === res){ resolve('success'); ... Read More

1K+ Views
We are required to write a JavaScript function that contains the following string −const str = 'This string will be used to calculate frequency distribution';We need to return an object that represents the frequency distribution of various elements present in the array.ExampleFollowing is the code −const str = 'This string will be used to calculate frequency distribution'; const frequencyDistribution = str => { const map = {}; for(let i = 0; i < str.length; i++){ map[str[i]] = (map[str[i]] || 0) + 1; }; return map; }; console.log(frequencyDistribution(str));OutputFollowing is the output in the console ... Read More

483 Views
We are required to write a JavaScript function that takes in two strings. The first string is some mistyped string and the second string is the correct version of this sting. We can assume that the two strings we are getting as argument will always have the same length.We have to return the number of mistakes that exist in the first array.ExampleFollowing is the code −const str1 = 'Tkos am er exakgrg fetwnh'; const str2 = 'This is an example string'; const countMistakes = (mistaken, correct) => { let count = 0; for(let i = 0; i < ... Read More

2K+ Views
We are required to write a JavaScript function that takes in two arrays of numbers, second being smaller in size than the first.Our function should be a sorted version of the first array (say in increasing order) but put all the elements that are common in both arrays to the front.For example − If the two arrays are −const arr1 = [5, 4, 3, 2, 1]; const arr2 = [2, 3];Then the output should be −const output = [2, 3, 1, 4, 5];ExampleFollowing is the code −const arr1 = [5, 4, 3, 2, 1]; const arr2 = [2, 3]; // ... Read More

478 Views
Proper FractionA proper fraction is the one that exists in the p/q form (both p and q being natural numbers)Mixed FractionSuppose we divide the numerator of a fraction (say a) with its denominator (say b), to get quotient q and remainder r.The mixed fraction form for fraction (a/b) will be −qrbAnd it is pronounced as "q wholes and r by b”.We are required to write a JavaScript function that takes in an array of exactly two numbers representing a proper fraction and our function should return an array with three numbers representing its mixed formExampleFollowing is the code −const arr ... Read More

198 Views
We are required to write a JavaScript function that takes in a string that contains strings joined by whitespaces. Our function should create a new string that has all the words from the original string and the words whose length is a prime number reversed i.e. words with length 2, 3, 5, 7, 100, etc.ExampleFollowing is the code −const str = 'His father is an engineer by profession'; // helper functions const isPrime = n => { if (n===1){ return false; }else if(n === 2){ return true; }else{ ... Read More

579 Views
We are required to write a JavaScript function that takes in a string representing a temperature either in Celsius or in Fahrenheit.Like this −"23F", "43C", "23F"We are required to write a JavaScript function that takes in this string and converts the temperature from Celsius to Fahrenheit and Fahrenheit to Celsius.ExampleFollowing is the code −const temp1 = '37C'; const temp2 = '100F'; const tempConverter = temp => { const degree = temp[temp.length-1]; let converted; if(degree === "C") { converted = (parseInt(temp) * 9 / 5 + 32).toFixed(2) + "F"; }else { ... Read More

528 Views
In this article, we will learn two approaches to check if a number is pandigital using JavaScript. Pandigital numbers are fascinating because they include each digit at least once within a specific range. Checking if a number is pandigital can be a common problem in programming challenges or number theory explorations. What is a Pandigital Number? A Pandigital number is a number that includes all the digits within a specific range at least once. For example − A 0-9 pandigital number contains each digit from 0 to 9 at least once, regardless of order. ... Read More

160 Views
We are required to write a JavaScript function that takes in two strings, creates and returns a new string with first two words of first string, next two words of second string, then first, then second and so on.For example −If the strings are −const str1 = 'Hello world'; const str2 = 'How are you btw';Then the output should be −const output = 'HeHollw o arwoe rlyodu btw';ExampleLet us write the code for this function −const str1 = 'Hello world'; const str2 = 'How are you btw'; const twiceJoin = (str1 = '', str2 = '') => { let ... Read More