- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 10710 Articles for Web Development
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
ProblemWe are required to write a JavaScript function that takes in an array of Boolean values and a logical operator.Our function should return a Boolean result based on sequentially applying the operator to the values in the array.ExampleFollowing is the code − Live Democonst array = [true, true, false]; const op = 'AND'; function logicalCalc(array, op){ var result = array[0]; for(var i = 1; i < array.length; i++){ if(op == "AND"){ result = result && array[i]; } if(op == "OR"){ result = result || array[i]; } if(op == "XOR"){ result = result != array[i]; } } return result; } console.log(logicalCalc(array, op));Outputfalse
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
224 Views
ProblemWe are required to write a JavaScript function that takes in an array of names (string). This array specifies the names of people that liked a particular post on some social networking site.If the count of likes are less than or equal to three our function should simply return all names saying these people liked the post but if the count is greater than three then our function should return first two names and remaining count.ExampleFollowing is the code − Live Democonst names = ['Ram', 'Manohar', 'Jay', 'Kumar', 'Vishal']; const displayLikes = (names) => { return [ ... Read More
303 Views
Understanding how to reverse an array of digits from a number using JavaScript is a significant skill that empowers developers to manipulate and transform data with precision. In the realm of web development, the ability to reverse the order of digits in a number opens doors to a plethora of possibilities, enhancing algorithms, data processing, and user interactions. This article delves into the intricacies of reversing an array of digits from a number using JavaScript, unraveling the lesser-known techniques and methods that enable developers to efficiently manipulate numerical data. By mastering this technique, developers can unlock the potential to create ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
115 Views
ProblemSuppose the following number name string −const str = 'TOWNE';If we rearrange this string, we can find two number names in it 2 (TWO) and 1 (ONE).Therefore, we expect an output of 21We are required to write a JavaScript function that takes in one such string and returns the numbers present in the string.ExampleFollowing is the code − Live Democonst str = 'TOWNE'; const findNumber = (str = '') => { function stringPermutations(str) { const res = []; if (str.length == 1) return [str]; if (str.length == 2) return [str, str[1]+str[0]]; ... Read More
1K+ Views
In the realm of text processing and data manipulation, the removal of punctuations from a string holds significant importance. JavaScript, a versatile programming language, offers developers the tools to accomplish this task with utmost precision and efficiency. While the act of eliminating punctuations may seem mundane, mastering this skill is indispensable when it comes to various text-based applications, such as natural language processing, data analysis, and information retrieval. In this article, we will explore the intricacies of removing punctuations from a string using JavaScript, delving into the lesser-known techniques and functions that enable developers to effectively cleanse textual data. By ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers (positive and negative). Our function should calculate and return the sum of all the positive numbers present in the array.ExampleFollowing is the code − Live Democonst arr = [5, -5, -3, -5, -7, -8, 1, 9]; const sumPositives = (arr = []) => { const isPositive = num => typeof num === 'number' && num > 0; const res = arr.reduce((acc, val) => { if(isPositive(val)){ acc += val; }; return acc; }, 0); return res; }; console.log(sumPositives(arr));OutputFollowing is the console output −15
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
512 Views
ProblemWe are required to write a JavaScript function that takes in an array of integers. Our function should return the sum of all the integers that have an even index, multiplied by the integer at the last index.const arr = [4, 1, 6, 8, 3, 9];Expected output −const output = 117;ExampleFollowing is the code − Live Democonst arr = [4, 1, 6, 8, 3, 9]; const evenLast = (arr = []) => { if (arr.length === 0) { return 0 } else { const sub = arr.filter((_, index) => index%2===0) const sum = sub.reduce((a,b) => a+b) const posEl = arr[arr.length -1] const res = sum*posEl return res } } console.log(evenLast(arr));OutputFollowing is the console output −117
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
614 Views
ProblemWe are required to write a JavaScript function that takes in a string str. Our function should construct a new string that contains only the unique characters from the input string and remove all occurrences of duplicate characters.ExampleFollowing is the code − Live Democonst str = 'hey there i am using javascript'; const removeAllDuplicates = (str = '') => { let res = ''; for(let i = 0; i < str.length; i++){ const el = str[i]; if(str.indexOf(el) === str.lastIndexOf(el)){ res += el; continue; }; }; return res; }; console.log(removeAllDuplicates(str));OutputFollowing is the console output −Ymungjvcp
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
253 Views
ProblemWe are required to write a JavaScript function that takes in a string that contains numbers separated by spaces.Our function should return a string that contains only the greatest and the smallest number separated by space.Inputconst str = '5 57 23 23 7 2 78 6';Outputconst output = '78 2';Because 78 is the greatest and 2 is the smallest.ExampleFollowing is the code − Live Democonst str = '5 57 23 23 7 2 78 6'; const pickGreatestAndSmallest = (str = '') => { const strArr = str.split(' '); let creds = strArr.reduce((acc, val) => { let { greatest, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
73 Views
ProblemWe are required to write a JavaScript function that takes in a sentence of words and a number. The function should return an array of all words greater than the length specified by the number.Inputconst str = 'this is an example of a basic sentence'; const num = 4;Outputconst output = [ 'example', 'basic', 'sentence' ];Because these are the only three words with length greater than 4.ExampleFollowing is the code − Live Democonst str = 'this is an example of a basic sentence'; const num = 4; const findLengthy = (str = '', num = 1) => { const strArr ... Read More