- 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 8894 Articles for Front End Technology
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
155 Views
ProblemConsider an increasing sequence which is defined as follows −The number seq(0) = 1 is the first one in seq.For each x in seq, then y = 2 * x + 1 and z = 3 * x + 1 must be in seq too.There are no other numbers in seq.Therefore, the first few terms of this sequence will be −[1, 3, 4, 7, 9, 10, 13, 15, 19, 21, 22, 27, ...]We are required to write a function that takes in a number n and returns the nth term of this sequence.ExampleFollowing is the code − Live Democonst num = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
495 Views
ProblemWe are required to write a JavaScript function that lives on the prototype object of the string class.This function should simply change case of all the alphabets present in the string to uppercase and return the new string.ExampleFollowing is the code − Live Democonst str = 'This is a lowercase String'; String.prototype.customToUpperCase = function(){ const legend = 'abcdefghijklmnopqrstuvwxyz'; const UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; let res = ''; for(let i = 0; i < this.length; i++){ const el = this[i]; const index = legend.indexOf(el); if(index !== -1){ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
741 Views
ProblemWe are required to write a JavaScript function that takes in a number and returns its reversed number.One thing that we should keep in mind is that numbers should preserve their sign; i.e., a negative number should still be negative when reversed.ExampleFollowing is the code − Live Democonst num = -224; function reverseNumber(n) { let x = Math.abs(n) let y = 0 while (x > 0) { y = y * 10 + (x % 10) x = Math.floor(x / 10) }; return Math.sign(n) * y }; console.log(reverseNumber(num));Output-422
![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
302 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