
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 9150 Articles for Object Oriented Programming

361 Views
We have to write a function maximumDifference() that takes in a positive number n and returns the difference between the maximum number and the minimum number that can be formed out of the number n.For example −If the number n is 203, The maximum number that can be formed from its digits will be 320The minimum number that can be formed from its digits will be 23 (placing the zero at one’s place)And the difference will be −320-23 = 297Therefore, the output should be 297Let's write the code for this function −Exampleconst digitDifference = num => { const asc ... Read More

198 Views
We are required to write a function that takes in a string of definite characters and the function should return the difference between the count of vowels plus other characters and consonants in the string.For example −If the string is −"HEllo World!!"Then, we have 7 consonants, 3 vowels and 3 other characters here so the output should be −|7 - (3+3)| = 1Hence, the output should be 1Let's write the code for this function −Exampleconst str = 'HEllo World!!'; const findDifference = str => { const creds = str.split("").reduce((acc, val) => { let { v, c ... Read More

753 Views
We are required to write a function, say nearestPalindrome() that takes in a number n and returns a palindromic number that is nearest to the number n.For example −If the input number is 264, then the output should be 262If the input number is 7834, then the output should be 7887Basically, the approach will be, we divide the number into two halves (w.r.t. its length) and return the new number which is just the first half concatenated twice.Exampleconst findNearestPalindrome = num => { const strNum = String(num); const half = strNum.substring(0, Math.floor(strNum.length/2)); const reversed = half.split("").reverse().join(""); ... Read More

379 Views
Let’s say, we have an array of arrays that contains some elements like this −const arr = [3, 5, 7, 2, [4, NaN, null, 4, 8, [3, undefined, 24, null], null, 5, 1], NaN, 45, 2, 1];Our job is to write a recursive function that takes in this nested array and replaces all the fale values inside the array (NaN, undefined and null) with 0.Therefore, let's write the code for this function −Exampleconst arr = [3, 5, 7, 2, [4, NaN, null, 4, 8, [3, undefined, 24, null], null, 5, 1], NaN, 45, 2, 1]; const recursiveSimplify = (arr) => ... Read More

447 Views
We are required to write a function, say reverseSum() that takes in two arrays of Numbers, let’s say first and second and returns a new array that contains, Sum of first element of first array and last element of second array as first element, sum of second element of first array and second last element of second array, and so on.When any of the array runs out of element before the other, we simply push all the remaining elements to the array. Therefore, let's write the code for this function −Exampleconst first = [23, 5, 7, 2, 34, 7, 8]; ... Read More

570 Views
We are required to write a function that takes a positive integer n and returns an array of next n leap years. We will break this problem into three parts −Part 1: Finding current year via JSThe code to find current year via JS will be −// getting the current year from a new instance of Date object const year = new Date().getFullYear();Part 2: Checking for leap yearWe will now write a function isLeap() that takes in a number and returns a boolean based on the number being a leap year or not.A year is considered as a leap year ... Read More

344 Views
We are required to write a function with a while-statement that determines the length of the largest consecutive subarray in an array of positive integers.For instance −If the input array is −const input = [6, 7, 8, 6, 12, 1, 2, 3, 4] --> [1, 2, 3, 4]Then the output should be −4If the input array is −const input = [5, 6, 1, 8, 9, 7] --> [8, 9]Then the output should be −2Therefore, let’s write the code for this function −Exampleconst arr = [6, 7, 8, 6, 12, 1, 2, 3, 4]; const arr1 = [5, 6, 1, 8, ... Read More

319 Views
Given an array of arrays, each of which contains a set of numbers. We have to write a function that returns an array where each item is the sum of all the items in the corresponding subarray.For example −If the input array is −const numbers = [ [1, 2, 3, 4], [5, 6, 7], [8, 9, 10, 11, 12] ];Then output of our function should be −const output = [10, 18, 50];So, let’s write the code for this function −Exampleconst numbers = [ [1, 2, 3, 4], [5, 6, 7], [8, 9, 10, 11, ... Read More

312 Views
Let’s say, we are required to write a recursive function that sums all the elements of an array of Numbers but with a twist and the twist is that the recursive function we write cannot initialize any extra variable (memory).Like we cannot use a variable to store the sum or to keep a count of the index of the array, it all has to be using what we already have.Here’s the solution −We already have an array and can use its first element (i.e., the element at zeroth index to hold the recursive sum).The approach is that we repeatedly pop ... Read More

451 Views
We are required to write a JavaScript function that takes in a number and returns a boolean based on the fact whether or not it comes in the fibonacci series.For example −If the function call is like this −fibonacci(12); fibonacci(89); fibonacci(55); fibonacci(534);Then the output should be −False true true falseNow, let’s write a recursive solution to this problem −Exampleconst fibonacci = (query, count = 1, last = 0) => { if(count < query){ return fibonacci(query, count+last, count); }; if(count === query){ return true; } return false; }; console.log(fibonacci(12)); console.log(fibonacci(55)); ... Read More