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
-
Economics & Finance
Object Oriented Programming Articles
Page 158 of 589
Digit distance of two numbers - JavaScript
We are required to write a JavaScript function that takes in two numbers and returns their digit distance. What is Digit Distance? The digit distance of two numbers is the absolute sum of the difference between their corresponding digits from left to right. For example, if the numbers are: 345 678 Then the digit distance calculation will be: |3-6| + |4-7| + |5-8| = 3 + 3 + 3 = 9 Implementation Here's how to calculate digit distance in JavaScript: const num1 = 345; const num2 ...
Read MoreHow to print all students name having percentage more than 70% in JavaScript?
You can filter and display students with percentage more than 70% using various JavaScript approaches. This is useful for grade-based filtering and reporting. Following are the records of each student: const studentDetails = [ { studentName: "John", percentage: 78 }, { studentName: "Sam", percentage: 68 }, ...
Read MoreJavaScript - Find the smallest n digit number or greater
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 180 Example Following ...
Read MoreHow to create an image of matrix of pixels in R?
A matrix can be converted into a pixel's image representation in R. This visualization technique displays matrix values as colored pixels, where each matrix element corresponds to a pixel with intensity or color based on its value. We can create pixel matrix images using R's image() function with the useRaster argument for optimized rendering. Syntax image(x, y, z, zlim, xlim, ylim, col, add, xaxs, yaxs, xlab, ylab, breaks, oldstyle, useRaster, ...) Basic Matrix Image Creation Let's start with a simple 10x10 matrix of random values: M
Read MoreDetermining rightness of a triangle – JavaScript
We are required to write a JavaScript function that takes in three numbers say a, b and c representing the length of three sides of a triangle. The function should return true if those three sides represent a right-angle triangle, false otherwise. Right Angle Triangle A triangle is a right-angle triangle if one of the three angles in the triangle is 90 degrees. And one angle in the triangle is 90 degrees when the square of the longest side is equal to the sum of squares of the other two sides. This is known as the Pythagorean ...
Read MoreSelect all elements with "data-" attribute with jQuery and display on Console?
To select all elements with "data-" attributes in jQuery, you can use the [data-*] selector or document.querySelectorAll(). This tutorial shows both approaches for selecting elements and displaying their data attribute values in the console. Method 1: Using jQuery Selector jQuery provides a simple way to select elements with data attributes using the [data-*] selector: Select Data Attributes with jQuery Paragraph with data attribute Heading ...
Read MoreStrictly increasing or decreasing array - JavaScript
In Mathematics, a strictly increasing function is one where values always increase, while a strictly decreasing function has values that always decrease. In JavaScript, we can check if an array follows either pattern. We need to write a function that takes an array of numbers and returns true if it's either strictly increasing or strictly decreasing, otherwise returns false. Understanding the Logic The key insight is to check if consecutive elements maintain the same slope (all increasing or all decreasing). We use a helper function sameSlope that compares three consecutive numbers to ensure they follow the same ...
Read MoreIteration of for loop inside object in JavaScript to fetch records with odd CustomerId?
In JavaScript, you can iterate through an array of objects using a for loop and filter records based on specific conditions. Here's how to fetch records with odd CustomerId values. Array of Objects Structure Let's start with an array containing customer objects: var customerDetails = [ { customerId: 101, customerName: "John" }, { customerId: 102, ...
Read MoreFinding persistence of number in JavaScript
The additive persistence of a number is the count of times you must repeatedly sum its digits until you get a single digit. This is a common programming problem that demonstrates recursion and digit manipulation. Understanding Additive Persistence For any positive integer, we replace it with the sum of its digits repeatedly until we reach a single digit (0-9). The number of iterations required is the additive persistence. For example, with 1679583: 1679583 → 1+6+7+9+5+8+3 = 39 (Pass 1) 39 → 3+9 = 12 ...
Read MoreGet value of any attribute from XML data in JavaScript?
To get the value of any attribute from XML data in JavaScript, you can use jQuery's attr() method or native JavaScript methods like getAttribute(). This is useful when working with XML strings or DOM elements that contain XML data. Using jQuery's attr() Method The attr() method allows you to extract attribute values from XML elements wrapped in jQuery objects: XML Attribute Example ...
Read More