- 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)
70 Views
ProblemWe are required to write a JavaScript function that lives on the prototype object of the Array class. This function should take in a callback function and this function should return that very first element for which the callback function yields true.We should feed the current element and the current index to the callback function as first and second argument.ExampleFollowing is the code − Live Democonst arr = [4, 67, 24, 87, 15, 78, 3]; Array.prototype.customFind = function(callback){ for(let i = 0; i < this.length; i++){ const el = this[i]; if(callback(el, i)){ ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
455 Views
ProblemWe are required to write a JavaScript function that takes in a number n. Starting with ‘1’ our function should construct a string of length n that contains ‘1’ and ‘0’ alternatingly.ExampleFollowing is the code − Live Democonst num = 12; const buildString = (num = 1) => { let res = ''; for(let i = 0; i < num; i++){ if(i % 2 === 0){ res += 1; }else{ res += 0; }; }; return res; }; console.log(buildString(num));Output101010101010
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
86 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers.Our function should construct and return a new array that contains all the numbers of the input array that are not odd.ExampleFollowing is the code − Live Democonst arr = [5, 32, 67, 23, 55, 44, 23, 12]; const findNonOdd = (arr = []) => { const res = []; for(let i = 0; i < arr.length; i++){ const el = arr[i]; if(el % 2 !== 1){ res.push(el); continue; }; }; return res; }; console.log(findNonOdd(arr));Output[ 32, 44, 12 ]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
354 Views
ProblemWe are required to write a JavaScript function that takes in a string number of at least five digits. Our function should return the greatest sequence of five consecutive digits found within the number given.ExampleFollowing is the code − Live Democonst num = '123546544'; const findGreatestFiveDigit = (num = '') => { const str = num.toString(); const arr = []; for(let i = 0; i < str.length; i++){ arr.push(str.slice(i, i + 5)); }; return Math.max(...arr); }; console.log(findGreatestFiveDigit(num));Output54654
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
670 Views
ProblemWe are required to write a JavaScript function that takes in an array of words and punctuations. Our function should join array elements to construct a sentence based on the following rules −there must always be a space between words;there must not be a space between a comma and word on the left;there must always be one and only one period at the end of a sentence.ExampleFollowing is the code − Live Democonst arr = ['hey', ', ', 'and', ', ', 'you']; const buildSentence = (arr = []) => { let res = ''; for(let i = 0; i ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
209 Views
ProblemWe are required to write a JavaScript function that takes in a number n(n>0). Our function should return an array that contains the continuous parts of odd or even digits. It means that we should split the number at positions when we encounter different numbers (odd for even, even for odd).ExampleFollowing is the code − Live Democonst num = 124579; const splitDifferent = (num = 1) => { const str = String(num); const res = []; let temp = ''; for(let i = 0; i < str.length; i++){ const el = str[i]; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
203 Views
ProblemWe are required to write a JavaScript function that takes in a decimal number, converts it into binary and reverses its 1 bit to 0 and 0 to 1 and returns the decimal equivalent of new binary thus formed.ExampleFollowing is the code − Live Democonst num = 45657; const reverseBitsAndConvert = (num = 1) => { const binary = num.toString(2); let newBinary = ''; for(let i = 0; i < binary.length; i++){ const bit = binary[i]; newBinary += bit === '1' ? '0' : 1; }; const decimal = parseInt(newBinary, 2); return decimal; }; console.log(reverseBitsAndConvert(num));Output19878
![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 a number n and returns the sum of all perfect cube numbers smaller than or equal to n.ExampleFollowing is the code − Live Democonst num = 23546; const sumPerfectCubes = (num = 1) => { let i = 1; let sum = 0; while(i * i * i
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
193 Views
Increasing TriangleFor the purpose of this problem, suppose an increasing triangle to be like this − 1 2 3 4 5 6 7 8 9 10ProblemWe are required to write a JavaScript function that takes in a number n and returns the sum of numbers present in the nth row of increasing triangle.ExampleFollowing is the code − Live Democonst num = 15; const rowSum = (num = 1) => { const arr = []; const fillarray = () => { let num = 0; for(let i = 1; i a + b, 0); }; console.log(rowSum(num));Output1695
457 Views
In the realm of computational geometry, the ability to accurately calculate the area of a triangle based on its three sides is of paramount importance. JavaScript, a versatile programming language, offers developers the means to perform this complex mathematical task with precision. While the process may seem daunting at first, mastering the art of calculating the area of a triangle using its three sides in JavaScript is a testament to a developer's prowess in numerical algorithms and mathematical manipulation. In this enlightening article, we will embark on a journey through the intricacies of computational geometry, exploring a step-by-step approach to ... Read More