- 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 9317 Articles for Object Oriented Programming
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
322 Views
We are required to write a JavaScript function that takes in a number as the first argument, say n, and an array of numbers as the second argument. The function should return the smallest n digit number which is a multiple of all the elements specified in the array. If there exist no such n digit element then we should return the smallest such element.For example: If the array is −const arr = [12, 4, 5, 10, 9]For both n = 2 and n = 3, the output should be 180ExampleFollowing is the code −const arr = [12, 4, 5, ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
567 Views
We have an array of arrays like this −const arr = [[12, 56], [3, 45], [23, 2], [2, 6], [2, 8]];Note that while the array can have any number of elements, each subarray should strictly contain two numbers.The two numbers in each subarray represents a fraction. For example, the fraction represented by the first subarray is 12/56, by the second is 3/45 and so on.We are required to write a JavaScript function that takes in one such array and calculates the sum of fractions represented by all the subarrays. Calculate the sum in fraction form (i.e., without converting them to ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
219 Views
We are required to write a JavaScript function that takes in two numbers a and b returns their digit distance.Digit distanceThe digit distance of two numbers is the absolute sum of the difference between their corresponding digits.For example: If the numbers are −345 678Then the digit distance will be −|3-6| + |4-7| + |5-8| = 3 + 3 + 3 = 9ExampleFollowing is the code −const num1 = 345; const num2 = 678; const digitDistance = (a, b) => { const aStr = String(a); const bStr = String(b); let diff = 0; for(let i = 0; ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
424 Views
We are required to write a JavaScript function that takes in two numbers, say a and b and returns the sum of all the prime numbers that fall between a and b. We should include a and b if they are prime as well.ExampleFollowing is the code −const num1 = 45; const num2 = 345; const isPrime = n => { if (n===1){ return false; }else if(n === 2){ return true; }else{ for(let x = 2; x < n; x++){ if(n % x === 0){ return false; } } return true; }; }; const primeBetween = (a, b) => { const res = []; while(a
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
343 Views
Suppose, we have the following array of strings that might contain duplicate characters −const arr = ['54gdgdfe3', '434ffd', '43frdf', '43fdhnh', 'wgcxhjny', 'fsdf34'];We are required to write a JavaScript function that takes in one such array and returns the very first element from the array that contains 0 duplicate characters.If there does not exist any such string, we should return false.ExampleFollowing is the code −const arr = ['54gdgdfe3', '434ffd', '43frdf', '43fdhnh', 'wgcxhjny', 'fsdf34']; const isUnique = str => { return str.split('').every(el => str.indexOf(el) === str.lastIndexOf(el)); }; const findUniqueString = arr => { for(let i = 0; i < ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
We are required to write a JavaScript function that takes in an array of numbers and sorts the array such that first all the even numbers appear in ascending order and then all the odd numbers appear in ascending order.For example: If the input array is −const arr = [2, 5, 2, 6, 7, 1, 8, 9];Then the output should be −const output = [2, 2, 6, 8, 1, 5, 7, 9];ExampleFollowing is the code −const arr = [2, 5, 2, 6, 7, 1, 8, 9]; const isEven = num => num % 2 === 0; const sorter = ((a, ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
587 Views
We have a string of length m that contains first m letters of the English alphabets, but somehow, one element went missing from the string. So, now the string contains, m-1 lettersWe are required to write a function that takes in one such string and returns the missing element from the stringExampleFollowing is the code −const str = "acdghfbekj"; const missingCharacter = str => { // to make the function more consistent const s = str.toLowerCase(); for(let i = 97; ; i++){ if(s.includes(String.fromCharCode(i))){ continue; }; ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
903 Views
We are required to write a JavaScript function that takes in a string and a number, say n, and the function should return a new string in which all the letters of the original string are repeated n times.For example: If the string is −const str = 'how are you'And the number n is 2Then the output should be −const output = 'hhooww aarree yyoouu'ExampleFollowing is the code −const str = 'how are you'; const repeatNTimes = (str, n) => { let res = ''; for(let i = 0; i < str.length; i++){ // using ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
536 Views
We are required to write a JavaScript function that takes in a string and changes every letter of the string from the English alphabets to its succeeding element.For example: If the string is −const str = 'how are you';Then the output should be −const output = 'ipx bsf zpv'ExampleFollowing is the code −const str = 'how are you'; const isAlpha = code => (code >= 65 && code = 97 && code code === 90 || code === 122; const nextLetterString = str => { const strArr = str.split(''); return strArr.reduce((acc, val) => { ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
595 Views
We are required to write a JavaScript function that takes in an array with both positive and negative numbers and returns the absolute sum of all the elements of the array.We are required to do this without taking help of any inbuilt library function.For example: If the array is −const arr = [1, -5, -34, -5, 2, 5, 6];Then the output should be −58ExampleFollowing is the code −const arr = [1, -5, -34, -5, 2, 5, 6]; const absoluteSum = arr => { let res = 0; for(let i = 0; i < arr.length; i++){ ... Read More