- 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)
369 Views
ProblemWe are required to write a JavaScript function that takes in a English alphabet string. Our function should return the top three most frequent words present in the string.ExampleFollowing is the code − Live Democonst str = 'Python was developed by Guido van Rossum in the late eighties and early nineties at the National Research Institute for Mathematics and Computer Science in the Netherlands. Python is derived from many other languages, including ABC, Modula-3, C, C++, Algol-68, SmallTalk, and Unix shell and other scripting languages. Python is copyrighted. Python source code is now available under the GNU General Public License (GPL)'; ... Read More
![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 a lowercase alphabet string and number num.Our function should remove num characters from the array in alphabetical order. It means we should first remove ‘a’ if they exist then ‘b’ , ‘c’ and so on until we hit the desired num.ExampleFollowing is the code − Live Democonst str = 'abascus'; const num = 4; const removeAlphabetically = (str = '', num = '') => { const legend = "abcdefghijklmnopqrstuvwxyz"; for(let i = 0; i < legend.length; i+=1){ while(str.includes(legend[i]) && num > 0){ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
160 Views
ProblemWe are required to write a JavaScript function that takes in a number, gap as the first argument and a range array of two numbers as the second argument. Our function should return an array of all such prime pairs that have an absolute difference of gap and falls between the specified range.ExampleFollowing is the code − Live Democonst gap = 4; const range = [20, 200]; const primesInRange = (gap, [left, right]) => { const isPrime = num => { for(let i = 2; i < num; i++){ if(num % i === ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
102 Views
ProblemWe are required to write a JavaScript function that takes in an array in which all the numbers appear thrice except one which appears twice and one which appears only one. Our function should find and return these two numbers.ExampleFollowing is the code − Live Democonst arr = [1, 1, 1, 2, 2, 3]; const findMissing = (arr = []) => { let x = 0; let y = 0; for(let i = 0; i < arr.length; i++){ if(arr.filter(a => a === arr[i]).length === 2){ y = arr[i]; }; if(arr.filter(b => b === arr[i]).length === 1){ x = arr[i]; }; }; return [x, y]; }; console.log(findMissing(arr));OutputFollowing is the console output −[3, 2]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
91 Views
ProblemWe are required to write a JavaScript class, Projectile, which takes in 3 arguments when initialized −starting height (0 ≤ h0 < 200)starting velocity (0 < v0 < 200)angle of the projectile when it is released (0° < a < 90°, measured in degrees).We need to write the following method for the Projectile class.A horiz method, which also takes in an argument t and calculates the horizontal distance that the projectile has traveled. [takes in a double, returns a double]ExampleThe code for this class will be − Live Democlass Projectile{ constructor(h, u, ang){ this.h = h; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
61 Views
ProblemWe are required to write a JavaScript function that takes in a number. Our function should return an array of strings containing the number cut off at each digit.ExampleFollowing is the code − Live Democonst num = 246; const cutOffEach = (num = 1) => { const str = String(num); const res = []; let temp = ''; for(let i = 0; i < str.length; i++){ const el = str[i]; temp += el; res.push(temp); }; return res; }; console.log(cutOffEach(num));OutputFollowing is the console output −[ '2', '24', '246' ]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
ProblemWe are required to write two JavaScript functions −First function should take in a long url and return a short url that corresponds to it.The second function should take in the short url and redirect to the original url.ExampleFollowing is the code − Live Democonst url = 'https://www.google.com/search?client=firefox-b-d&q=google+search'; const obj = {}; const urlShortener = (longURL = '') => { let shortURL = "short.ly/" + longURL.replace(/[^a-z]/g, '').slice(-4); if(!obj[shortURL]){ obj[shortURL] = longURL; }; return shortURL; } const urlRedirector = (shortURL = '') => { return obj[shortURL]; }; const short = urlShortener(url); const ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
59 Views
ProblemWe are required to write a JavaScript function that takes in a time string in “HH:MM:SS” format.But there was a problem in addition, so many of the time strings are broken which means the MM part may exceed 60, and SS part may as well exceed 60.Our function should make required changes to the string and return the new rectified string.For instance −"08:11:71" -> "08:12:11"ExampleFollowing is the code − Live Democonst str = '08:11:71'; const rectifyTime = (str = '') => { if(!Boolean(str)){ return str; }; const re = /^(\d\d):(\d\d):(\d\d)$/; if (!re.test(str)){ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
340 Views
ProblemIn mathematics, the look-and-say sequence is the sequence of integers beginning as follows −1, 11, 21, 1211, 111221, 312211, …To generate a member of the sequence from the previous member, we read off the digits of the previous member, counting the number of digits in groups of the same digit.For instance, the next number to 1211 is −111221Because if we read the digit of 1211 louder it will be −One one, one two, two one which gives us 111221We are required to write a JavaScript function that takes in a number n and returns the first n terms of look ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
995 Views
ProblemWe are required to write a JavaScript function that takes in two IPv4 addresses, and returns the number of addresses between them (including the first one, excluding the last one).This can be done by converting them to decimal and finding their absolute difference.ExampleFollowing is the code − Live Democonst ip1 = '20.0.0.10'; const ip2 = '20.0.1.0'; const countIp = (ip1, ip2) => { let diff = 0; const aIp1 = ip1.split("."); const aIp2 = ip2.split("."); if (aIp1.length !== 4 || aIp2.length !== 4) { return "Invalid IPs: incorrect format"; } for (x ... Read More