Object Oriented Programming Articles

Page 158 of 589

Digit distance of two numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 410 Views

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 More

How to print all students name having percentage more than 70% in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 616 Views

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 More

JavaScript - Find the smallest n digit number or greater

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 440 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 180 Example Following ...

Read More

How to create an image of matrix of pixels in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 15-Mar-2026 1K+ Views

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 More

Determining rightness of a triangle – JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

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 More

Select all elements with "data-" attribute with jQuery and display on Console?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

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 More

Strictly increasing or decreasing array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 497 Views

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 More

Iteration of for loop inside object in JavaScript to fetch records with odd CustomerId?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 321 Views

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 More

Finding persistence of number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 431 Views

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 More

Get value of any attribute from XML data in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

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
Showing 1571–1580 of 5,881 articles
« Prev 1 156 157 158 159 160 589 Next »
Advertisements