
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 8591 Articles for Front End Technology

585 Views
We are required to write a JavaScript function that takes in two strings that may / may not contain some common elements. The function should return an empty string if no common element exists otherwise a string containing all common elements between two strings.Following are our two strings −const str1 = 'Hey There!!, how are you'; const str2 = 'Can this be a special string';ExampleFollowing is the code −const str1 = 'Hey There!!, how are you'; const str2 = 'Can this be a special string'; const commonString = (str1, str2) => { let res = ''; for(let i ... Read More

138 Views
In JavaScript, we can write our own custom functions and assign them to the existing standard data types (it is quite similar to writing library methods but in this case the data types are primitive and not user defined. We are required to write a JavaScript String function by the name, let’s say swapCase().This function will return a new string with all uppercase characters swapped for lower case characters, and vice versa. Any non-alphabetic characters should be kept as they are.ExampleFollowing is the code −const str = 'ThIS iS A CraZY StRInG'; String.prototype.swapCase = function(){ let res = ''; ... Read More

450 Views
Given a string, we are required to write a function that creates an object that stores the indexes of each letter in an array. The letters (elements) of the string must be the keys of objectThe indexes should be stored in an array and those arrays are values.For example −If the input string is −const str = 'cannot';Then the output should be −const output = { 'c': [0], 'a': [1], 'n': [2, 3], 'o': [4], 't': [5] };ExampleFollowing is the code −const str = 'cannot'; const mapString = str => { const map = ... Read More

432 Views
The “full house in poker” is a situation when a player, out of their five cards, has at least three cards identical. We are required to write a JavaScript function that takes in an array of five elements representing a card each and returns true if there's a full house situation, false otherwise.ExampleFollowing is the code −const arr2 = ['K', '2', 'K', 'A', 'J']; const isFullHouse = arr => { const copy = arr.slice(); for(let i = 0; i < arr.length; ){ const el = copy.splice(i, 1)[0]; if(copy.includes(el)){ ... Read More

444 Views
We are required to write a JavaScript function that takes in a string of strings joined by whitespaces. The function should calculate and return the average length of all the words present in the string rounded to two decimal placesExampleFollowing is the code −const str = 'This sentence will be used to calculate average word length'; const averageWordLength = str => { if(!str.includes(' ')){ return str.length; }; const { length: strLen } = str; const { length: numWords } = str.split(' '); const average = (strLen - numWords + 1) / numWords; ... Read More

290 Views
Lunar SumThe concept of lunar sum says that the sum of two numbers is calculated, instead of adding the corresponding digits, but taking the bigger of the corresponding digits.For example −Let’s say, a = 879 and b = 768(for the scope of this problem, consider only the number with equal digits)Then the lunar sum of a and b will be −879We are required to write a JavaScript function that takes in two numbers and returns their lunar sum.ExampleFollowing is the code −const num1 = 6565; const num2 = 7385; const lunarSum = (num1, num2) => { const numStr1 = ... Read More

276 Views
We are required to write a function that returns true if we can partition an array into one element and the rest, such that this one element is equal to the product of all other elements excluding itself, false otherwise.For example: If the array is −const arr = [1, 56, 2, 4, 7];Then the output should be trueBecause, 56 is equal to −2 * 4 * 7 * 1ExampleFollowing is the code −const arr = [1, 56, 2, 4, 7]; const isEqualPartition = arr => { const creds = arr.reduce((acc, val) => { let { prod, ... Read More

141 Views
We are required to write a JavaScript function that takes in an array of literals, such that some array elements are repeated. We are required to return an array that contains that appear only once (not repeated).For example: If the array is:>const arr = [9, 5, 6, 8, 7, 7, 1, 1, 1, 1, 1, 9, 8];Then the output should be −const output = [5, 6];ExampleFollowing is the code −const arr = [9, 5, 6, 8, 7, 7, 1, 1, 1, 1, 1, 9, 8]; const findDistinct = arr => { const res = []; for(let i = 0; i < arr.length; i++){ if(arr.indexOf(arr[i]) !== arr.lastIndexOf(arr[i])){ continue; }; res.push(arr[i]); }; return res; }; console.log(findDistinct(arr));OutputFollowing is the output in the console −[5, 6]

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