
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

1K+ Views
To find the nth term of an arithmetic progression in JavaScript, we need to write a function that will calculate the nth term. In this article, we will explore how to find the nth term of an AP using JavaScript. We are required to write a JavaScript function that takes in three numbers as arguments (the first two numbers are supposed to be the starting two consecutive terms of an arithmetic progression). And the third number, say n, is the 1 index-based element of the series whose value we must calculate. If the input is 2, 5, 7 Then ... Read More

456 Views
We are required to write a JavaScript function that takes in a number and returns the count of numbers that exactly divides the input number.For example −If the number is 12, then its factors are −1, 2, 3, 4, 6, 12Therefore, the output should be 6.ExampleFollowing is the code −const num = 12; const countFactors = num => { let count = 0; let flag = 2; while(flag

1K+ Views
Suppose we have a data.txt file that lives in the same directory as our NodeJS file. Suppose the content of that file is −Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s.We are required to write a JavaScript function that loads this external ... Read More

1K+ Views
We are required to write a JavaScript function that takes in string and returns an array with two string values, and they should be the smallest and largest words respectively from the string.For example −If the string is −const str = "Hardships often prepare ordinary people for an extraordinary destiny";Then the output should be −const output = ["an", "extraordinary"];So, let's write the code for this functionExampleFollowing is the code −const str = "Hardships often prepare ordinary people for an extraordinary destiny"; const largestSmallest = str => { const strArr = str.split(" "); let min = strArr[0]; let ... Read More

879 Views
We are given the lengths of three sides of a triangle and we are required to write a function that returns the area of the triangle using the length of its sides.Heron's formulaWe can calculate the area of a triangle if we know the lengths of all three sides, using Heron's formula −Step 1 − Calculate "s" (half of the triangles perimeter) −s = (a+b+c) / 2Step 2 − Then calculate the Area using Herons formula −A = sqrt( s(s-a)(s-b)(s-c) )ExampleSo, Let’s write the code for this function −const sides = [12, 4, 9]; const areaOfTriangle = sides => { ... Read More

858 Views
We are required to write a JavaScript function that takes in a number and returns a number that can be represented as a power of 2 which is nearest to the input number.For example −If the input number if 365, then the output should be 256, because 256 is the nearest such number to 365 which can be represented as 2^n for some whole number value of n.ExampleLet’s write the code for this function −const num = 365; const nearestPowerOfTwo = num => { // dealing only with non-negative numbers if(num < 0){ num *= ... Read More

511 Views
We are required to write a JavaScript function that takes in three numbers (representing the coefficient of quadratic term, coefficient of linear term and the constant respectively in a quadratic quadratic).And we are required to find the roots, (if they are real roots) otherwise we have to return false. Let's write the code for this functionExampleFollowing is the code −const coefficients = [3, 12, 2]; const findRoots = co => { const [a, b, c] = co; const discriminant = (b * b) - 4 * a * c; if(discriminant < 0){ // the ... Read More

6K+ Views
We are required to write a JavaScript function that takes in a string and returns a new string with only the words that appeared for more than once in the original string.For example: If the input string is −const str = "big black bug bit a big black dog on his big black nose";Then the output should be −const output = "big black";ExampleLet’s write the code for this function −const str = "big black bug bit a big black dog on his big black nose"; const findDuplicateWords = str => { const strArr = str.split(" "); const res ... Read More

683 Views
We are required to write a JavaScript function that takes in two 2-D arrays of numbers and returns their matrix multiplication result.Let’s say the following are our two matrices −// 5 x 4 let a = [ [1, 2, 3, 1], [4, 5, 6, 1], [7, 8, 9, 1], [1, 1, 1, 1], [5, 7, 2, 6] ]; // 4 x 6 let b = [ [1, 4, 7, 3, 4, 6], [2, 5, 8, 7, 3, 2], [3, 6, 9, 6, 7, 8], [1, 1, 1, 2, 3, 6] ];ExampleLet’s ... Read More

607 Views
We are required to write a JavaScript function that takes in a string and constructs a new string with all the uppercase characters converted to lowercase and all the lowercase characters converted to uppercase.Let’s write the code for this function −ExampleFollowing is the code −const str = 'The Case OF tHis StrinG Will Be FLiPped'; const isUpperCase = char => char.charCodeAt(0) >= 65 && char.charCodeAt(0) char.charCodeAt(0) >= 97 && char.charCodeAt(0) { let newStr = ''; const margin = 32; for(let i = 0; i < str.length; i++){ const curr = str[i]; ... Read More