- 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)
810 Views
ProblemConsider the following ipv4 address −128.32.10.1If we convert it to binary, the equivalent will be −10000000.00100000.00001010.00000001And further if we convert this binary to unsigned 32 bit decimal, the decimal will be −2149583361Hence, we can say that the ipv4 equivalent of 2149583361 is 128.32.10.1We are required to write a JavaScript function that takes in a 32-bit unsigned integer and returns its equivalent ipv4 address.ExampleFollowing is the code − Live Democonst num = 2149583361; const int32ToIp = (num) => { return (num >>> 24 & 0xFF) + '.' + (num >>> 16 & 0xFF) + '.' + (num >>> 8 & 0xFF) + '.' + (num & 0xFF); }; console.log(int32ToIp(num));OutputFollowing is the console output −128.32.10.1
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
155 Views
ProblemWe are required to write a JavaScript function that takes in a number n. Our function should convert the number to binary or hex based on −If a number is even, convert it to binary.If a number is odd, convert it to hex.ExampleFollowing is the code − Live Democonst num = 1457; const conditionalConvert = (num = 1) => { const isEven = num % 2 === 0; const toBinary = () => num.toString(2); const toHexadecimal = () => num.toString(16); return isEven ? toBinary() : toHexadecimal(); }; console.log(conditionalConvert(num));OutputFollowing is the console output −5b1
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
289 Views
K-Prime NumbersA natural number is called k-prime if it has exactly k prime factors, counted with multiplicity.Which means even though the only prime factor of 4 is 2 it will be a 2-prime number because −4 = 2 * 2 and both 2s will be counted separately taking the count to 2.Similarly, 8 is 3-prime because 8 = 2 * 2 * 2 taking the count to 3.ProblemWe are required to write a JavaScript function that takes in a number k, a distance and a range.Our function should return an array of arrays containing k-prime numbers within the range the ... Read More
1K+ Views
In the realm of JavaScript programming, the ability to sort numbers in ascending order and strings in alphabetical order within an array holds paramount importance. Efficiently arranging elements in such a manner not only enhances the organization and readability of data but also plays a pivotal role in various data manipulation and analysis tasks. By harnessing the power of JavaScript's built-in sorting capabilities, developers can effortlessly arrange array elements in the desired order. In this article, we will explore the intricacies of sorting numbers in ascending order and strings in alphabetical order within an array, unveiling the underlying mechanisms and ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
534 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers. For each number in the array, we need to create an object. The object key will be the number, as a string. And the value will be the corresponding character code, as a string.We should finally return an array of the resulting objects.ExampleFollowing is the code − Live Democonst arr = [67, 84, 98, 112, 56, 71, 82]; const mapToCharCodes = (arr = []) => { const res = []; for(let i = 0; i < arr.length; i++){ const el = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
303 Views
ProblemWe are required to write a JavaScript function that takes in an array of numbers. Our function is supposed to return the average of the given array rounded down to its nearest integer.ExampleFollowing is the code − Live Democonst arr = [45, 23, 67, 68, 12, 56, 99]; const roundedMean = (arr = []) => { const { sum, count } = arr.reduce((acc, val) => { let { sum, count } = acc; count++; sum += val; return { sum, count }; }, { sum: 0, count: 0 }); const mean = sum / (count || 1); return Math.round(mean); }; console.log(roundedMean(arr));OutputFollowing is the console output −53
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
167 Views
Padovan SequenceThe Padovan sequence is the sequence of integers P(n) defined by the initial values −P(0) = P(1) = P(2) = 1and the recurrence relation,P(n) = P(n-2) + P(n-3)The first few values of P(n) are1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200, 265, …ProblemWe are required to write a JavaScript function that takes in a number n and return the nth term of the Padovan sequence.ExampleFollowing is the code − Live Democonst num = 32; const padovan = (num = 1) => { let secondPrev = 1, pPrev = 1, pCurr = 1, pNext = 1; for (let i = 3; i
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
497 Views
ProblemWe are required to write a JavaScript function that takes in a number n. Our function should return an array of all such number pairs that when summed are n and both of them are prime.ExampleFollowing is the code − Live Democonst num = 26; const isPrime = (n) => { if (n % 2 === 0) return false; let sqrtn = Math.sqrt(n)+1; for (let i=3; i < sqrtn; i+=2) { if (n % i === 0) return false; } return true; } const primeList = (a) => { if (isPrime(a)) return ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
914 Views
ProblemWe are required to write a JavaScript function that takes in a string of characters, str, and a single character, char.Our function should construct a new string that contains the immediate next character present in str after each instance of char (if any).ExampleFollowing is the code − Live Democonst str = 'this is a string'; const letter = 'i'; const findNextString = (str = '', letter = '') => { let res = ''; for(let i = 0; i < str.length; i++){ const el = str[i]; const next = str[i + 1]; if(letter === el && next){ res += next; }; }; return res; }; console.log(findNextString(str, letter));Outputssn
![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 of numbers. Our function should try and remove the least number of elements from the array so that the array becomes an increasing sequence.ExampleFollowing is the code − Live Democonst arr = [1, 100, 2, 3, 100, 4, 5]; const findIncreasingArray = (arr = []) => { const copy = arr.slice(); for(let i = 0; i < copy.length; i++){ const el = arr[i]; const next = arr[i + 1]; if(el > next){ copy[i] = undefined; }; }; return copy.filter(Boolean); }; console.log(findIncreasingArray(arr));Output[ 1, 2, 3, 4, 5 ]