- 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 6683 Articles for Javascript
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
180 Views
ProblemWe are required to write a JavaScript function that takes in takes in an array of numbers. If in that array there exists any number which is the char code any vowel in ascii we should switch that number to the corresponding vowel and return the new array.ExampleFollowing is the code − Live Democonst arr = [5, 23, 67, 101, 56, 111]; const changeVowel = (arr = []) => { for (let i=0, l=arr.length; i
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
267 Views
ProblemWe are required to write a JavaScript function that takes in an array of strings.Our function should return the first string of the array after sorting it alphabetically and each character of that string should be separated by ‘***’.ExampleFollowing is the code − Live Democonst arr = ['this', 'is', 'some', 'string', 'array']; const specialSort = (arr = '') => { const copy = arr.slice(); copy.sort(); const el = copy[0]; const res = el .split('') .join('***'); return res; }; console.log(specialSort(arr));Outputa***r***r***a***y
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
70 Views
ProblemWe have an amount of money amt > 0 and we deposit it with an interest rate of p percent divided by 360 per day on the 1st of January 2021. We want to have an amount total >= a0.Our function should take these three parameters and return the date at which the amount will be equal to the desired amountExampleFollowing is the code − Live Democonst principal = 100; const amount = 150; const interest = 2; const findDate = (principal, amount, interest) => { const startingDate = new Date('2021-01-01') const dailyInterestRate = interest / 36000 let ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
200 Views
ProblemWe are required to write a JavaScript function that takes in a matrix of N * N order. The walls in the matrix are marked by ‘W’ and empty positions are marked by ‘_’We can move in any of the four directions at any point. Our function should return true if we can reach to the end [N - 1, N - 1], false otherwise.ExampleFollowing is the code − Live Democonst maze = [ ['_', 'W', 'W', 'W'], ['_', 'W', 'W', 'W'], ['W', '_', '_', 'W'], ['W', 'W', 'W', '_'] ]; const canFindPath = (m = []) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
231 Views
ProblemWe are required to write a JavaScript function that takes in the length, height and width of a room.Our function should calculate the number of sheets required to cover the whole room given that the width of one single sheet is .52 units and length is 10 units.For the sake of convenience, we should return the number of rolls such that the length is 15% more than the required length.ExampleFollowing is the code − Live Democonst findSheet = (length, width, height) => { if(length === 0 || width === 0){ return 0; } const roomArea ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
223 Views
ProblemWe are required to write a JavaScript function that takes in an expression in the form (ax+b)^n where a and b are integers which may be positive or negative, x is any single character variable, and n is a natural number. If a = 1, no coefficient will be placed in front of the variable.Our function should return the expanded form as a string in the form ax^b+cx^d+ex^f... where a, c, and e are the coefficients of the term, x is the original one-character variable that was passed in the original expression and b, d, and f, are the powers ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
71 Views
ProblemWe are required to write a JavaScript function that takes in a positive integer n and returns the maximum number we got doing only left rotations to the digits of the number.ExampleFollowing is the code − Live Democonst num = 56789; const findMaximum = (num = 1) => { let splitNumbers = num.toString().split(""); let largestNumber = num; for(let i = 0; i < splitNumbers.length - 1; i++) { splitNumbers.push(splitNumbers.splice(i, 1)[0]); let newNumber = Number(splitNumbers.join("")); if(newNumber >= largestNumber) { largestNumber = newNumber; } }; return largestNumber; }; console.log(findMaximum(num));Output68957
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
261 Views
Problem Suppose there are 5 squares embedded inside a rectangle like this −Their perimeter will be −4 + 4 + 8 + 12 + 20 = 48 unitsWe are required to write a JavaScript function that takes in a number n and return the sum of the perimeter if there are n squares embedded.ExampleFollowing is the code − Live Democonst num = 6; const findPerimeter = (num = 1) => { const arr = [1,1]; let n = 0; let sum = 2; for(let i = 0 ; i < num-1 ; i++){ n = arr[i] + arr[i+1]; arr.push(n); sum += n; }; return sum * 4; }; console.log(findPerimeter(num - 1));Output80
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
150 Views
ProblemWe are required to write a JavaScript function that takes in a string of English alphabets. Our function should push every alphabet forward by 10 places. And if it goes past 'z', we should start again at 'a'.ExampleFollowing is the code − Live Democonst str = 'sample string'; const moveStrBy = (num = 10) => { return str => { const calcStr = (ch, code) => String .fromCharCode(code + (ch.charCodeAt(0) - code + num) % 26); const ACode = 'A'.charCodeAt(0); const aCode = 'a'.charCodeAt(0); return str.replace(/[a-z]/gi, ch => ( ch.toLowerCase() == ch ? calcStr(ch, aCode) : calcStr(ch, ACode) )); }; }; const moveByTen = moveStrBy(); console.log(moveByTen(str));Outputckwzvo cdbsxq