
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

338 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

103 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

315 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

239 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

274 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function should return a string made of four parts −a four character 'word', made up of the characters derived from the first two and last two numbers in the array. order should be as read left to right (first, second, second last, last), the same as above, post sorting the array into ascending order, the same as above, post sorting the array into descending order, the same as above, post converting the array into ASCII characters and sorting alphabetically.The four parts should form a ... Read More

262 Views
ProblemWe are required to write a JavaScript function that takes in a string of English alphabets. Our function should construct a new string and every consonant should be pushed forward 9 places through the alphabet. If they pass 'z', start again at 'a'. And every vowel should be pushed by 5 places.ExampleFollowing is the code − Live Democonst str = 'sample string'; const moveWords = (str = '') => { str = str.toLowerCase(); const legend = 'abcdefghijklmnopqrstuvwxyz'; const isVowel = char => 'aeiou'.includes(char); const isAlpha = char => legend.includes(char); let res = ''; for(let i ... Read More

283 Views
ProblemWe are required to write a JavaScript function that takes in a string. Our function should convert the string according to following rules −The words should be Caps, Every word should end with '!!!!', Any letter 'a' or 'A' should become '@', Any other vowel should become '*'.ExampleFollowing is the code − Live Democonst str = 'ban censored words'; const maskWords = (str = '') => { let arr=str.split(' '); const res=[] for (let i=0; i

177 Views
ProblemWe are required to write a JavaScript function that takes in a string of some mathematical operation and return its literal wording.ExampleFollowing is the code −const str = '5 - 8'; const convertToWords = (str = '') => { const o = { "+" : "Plus", "-" : "Minus", "*" : "Times", "/" : "Divided By", "**" : "To The Power Of", "=" : "Equals", "!=" : "Does Not Equal", } const n = { ... Read More

255 Views
ProblemWe are required to write a JavaScript function that takes in two strings. The first string specifies the user name and second the owner name.If the user and owner are the same our function should return ‘hello master’, otherwise our function should return ‘hello’ appended with the name of that user.ExampleFollowing is the code − Live Democonst name = 'arnav'; const owner = 'vijay'; function greet (name, owner) { if (name === owner){ return 'Hello master'; } return `Hello ${name}`; }; console.log(greet(name, owner));OutputHello arnav