Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
Mixins in Dart Programming
Mixins in Dart are a way of using the code of a class again in multiple class hierarchies. We make use of the with keyword followed by one or more mixins names.Mixins can be used in two ways, the first case is when we want to make use of class code in such a way that the class doesn't have any constructor and the object of the class is extended. In such a case, we use the with keyword.Another case is when we want our mixin to be usable as a regular class, then we make use of the mixin keyword ...
Read MoreChecking for vowels in array of numbers using JavaScript
ProblemWe are required to write a JavaScript function that takes in takes in an array of numbers. If in that array there exists any number which is the char code any vowel in ascii we should switch that number to the corresponding vowel and return the new array.ExampleFollowing is the code −const arr = [5, 23, 67, 101, 56, 111]; const changeVowel = (arr = []) => { for (let i=0, l=arr.length; i
Read MoreChecking if all array values are smaller than a limit using JavaScript
ProblemWe are required to write a JavaScript function that takes in an array of numbers and a number. We should return true if all the numbers in the array are smaller than the number given as second argument, false otherwise.ExampleFollowing is the code −const arr = [5, 34, 23, 14, 78, 45, 78]; const limit = 99; const checkEvery = (arr = [], limit = 1) => { const allSmaller = arr.every(el => { return el < limit; }); return allSmaller; }; console.log(checkEvery(arr, limit));Outputtrue
Read MoreImplement a custom function similar to Array.prototype.includes() method using JavaScript
ProblemWe are required to write a JavaScript function that lives on the prototype object of Array.It must take in a literal value, and return true if that value is present in the array it is being called upon, false otherwise.ExampleFollowing is the code −const arr = [1, 2, 3, 4, 5, 6, 7, 8]; const num = 6; Array.prototype.customIncludes = function(num){ for(let i = 0; i < this.length; i++){ const el = this[i]; if(num === el){ return true; }; }; return false; }; console.log(arr.customIncludes(num));Outputtrue
Read MoreAccumulating array elements to form new array in JavaScript
ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument and a number, num, (num { const res = []; let sum = 0, right = 0, left = 0; for(; right < num; right++){ sum += arr[right]; }; res.push(sum); while(right < arr.length){ sum -= arr[left]; sum += arr[right]; right++; left++; res.push(sum); }; return res; }; console.log(accumulateArray(arr, num));OutputFollowing is the console output−[3, 5, 7, 9, 11]
Read MoreSumming array of string numbers using JavaScript
ProblemWe are required to write a JavaScript function that takes in an array that contains integers and string numbers.Our function should sum all the integers and string numbers together to derive a new number and return that number.ExampleFollowing is the code −const arr = [67, 45, '34', '23', 4, 6, '6']; const mixedSum = (arr = []) => { let sum = 0; for(let i = 0; i < arr.length; i++){ const el = arr[i]; sum += +el; }; return sum; }; console.log(mixedSum(arr));Output185
Read MoreFinding average age from array of Objects using JavaScript
ProblemWe are required to write a JavaScript function that takes in an object that contains data about some people.Our function should simply find the average of the age property for those people.ExampleFollowing is the code −const people = [ { fName: 'Ashish', age: 23 }, { fName: 'Ajay', age: 21 }, { fName: 'Arvind', age: 26 }, { fName: 'Mahesh', age: 28 }, { fName: 'Jay', age: 19 }, ]; const findAverageAge = (arr = []) => { const { sum, count } = arr.reduce((acc, val) => { let { sum, count } = acc; sum += val.age; count++; return { sum, count }; }, { sum: 0, count: 0 }); return (sum / (count || 1)); }; console.log(findAverageAge(people));Output23.4
Read MoreChecking existence of all continents in array of objects in JavaScript
ProblemWe are required to write a JavaScript function that takes in an array of objects that contains data about the continent of belonging for some people.Our function should return true if it finds six different continents in the array of objects, false otherwise.ExampleFollowing is the code −const people = [ { firstName: 'Dinesh', lastName: 'A.', country: 'Algeria', continent: 'Africa', age: 25, language: 'JavaScript' }, { firstName: 'Ishan', lastName: 'M.', country: ...
Read MoreChecking for special numbers in JavaScript
ProblemWe are required to write a JavaScript function that takes in a number, num, as the first and the only argument.Our function should return true if the sum of the digits of the number num is a palindrome number, false otherwise.For example, if the input to the function is −const num = 781296;Then the output should be −const output = true;Output ExplanationBecause the digit sum of 781296 is 33 which is a palindrome number.ExampleFollowing is the code −const num = 781296; const findSum = (num, sum = 0) => { if(num){ return findSum(Math.floor(num / 10), sum + (num % ...
Read MoreReplacing digits to form binary using JavaScript
ProblemWe are required to write a JavaScript function that takes in a string of digits. Our function should replace any digit below 5 with '0' and any digit 5 and above with '1' and return the resulting string.ExampleFollowing is the code −const str = '262355677834342'; const convert = (str = '') => { let res = ''; for(let i = 0; i < str.length; i++){ const el = +str[i]; if(el < 5){ res += 0; }else{ res += 1; }; }; return res; }; console.log(convert(str));Output010011111100000
Read More