Object Oriented Programming Articles

Found 5,881 articles

How to check Minlength and Maxlength validation of a property in C# using Fluent Validation?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 3K+ Views

FluentValidation is a popular .NET validation library that provides an easy way to validate model properties. The MinLength and MaxLength validators ensure that string properties meet specific length requirements, making them essential for input validation scenarios. Syntax Following is the syntax for using MaximumLength validator − RuleFor(x => x.PropertyName).MaximumLength(maxValue); Following is the syntax for using MinimumLength validator − RuleFor(x => x.PropertyName).MinimumLength(minValue); MaxLength Validator The MaximumLength validator ensures that the length of a string property does not exceed the specified maximum value. This validator is only valid on string properties. ...

Read More

How to create JLabel to hold multiline of text using HTML in Java?

Samual Sam
Samual Sam
Updated on 16-Mar-2026 1K+ Views

In Java Swing, the JLabel component by default displays only single-line text. To create a JLabel that can hold multiple lines of text, we need to use HTML formatting within the label text. This allows us to use HTML tags like for line breaks and other HTML formatting elements. Syntax Following is the syntax to create a multiline JLabel using HTML − JLabel label = new JLabel("Line1Line2"); For more complex formatting with alignment − JLabel label = new JLabel("Line1Line2", JLabel.LEFT); How It Works When a JLabel's text starts ...

Read More

How to do case insensitive string comparison of strings in JavaScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will learn how to do a case-insensitive string comparison of strings in JavaScript. Case insensitive comparison means strings should be considered equal regardless of whether they are written in lowercase or uppercase letters. This technique is commonly used in search functionality, where "TutorialsPoint" and "tutorialspoint" should be treated as identical. There are four main methods to perform case-insensitive string comparisons: toUpperCase() toLowerCase() localeCompare() RegExp() Using the toUpperCase() Method The toUpperCase() method converts all alphabetic ...

Read More

Implementing block search in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 350 Views

Block Search is a searching algorithm for sorted arrays that improves upon linear search by jumping ahead in fixed steps rather than checking every element. It combines the efficiency of skipping elements with linear search for the final location. How Block Search Works The algorithm divides the array into blocks of size √n and performs these steps: Jump through blocks of size √n until finding a block where the target might exist Perform linear search within that specific block Return the index if found, or -1 if not found Block Search ...

Read More

Inverting a binary tree in JavaScript

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 891 Views

Inverting a binary tree means creating a mirror image where all left and right child nodes are swapped recursively. This is a classic tree manipulation problem that demonstrates recursion and tree traversal concepts. What is a Binary Tree? A binary tree is a hierarchical data structure where each node has at most two children: left and right. The topmost node is called the root, and nodes with no children are called leaves. 4 2 7 ...

Read More

JavaScript array sorting by level

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

In this article, we will learn array sorting by level in JavaScript, creating a hierarchical tree structure from a flat array is a common challenge when dealing with relational data. This is a common task when dealing with hierarchical data, such as organizational charts, category trees, or file systems, where relationships like parent-child need to be represented. Problem Statement We have an array of objects representing nodes with _id, level, and parentId properties. Our goal is to transform this array into a tree structure where nodes are nested as children under their respective parents. The elements with the ...

Read More

Calculate Subtraction of diagonals-summations in a two-dimensional matrix using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 282 Views

Suppose we have a square matrix represented by a 2-D array in JavaScript like this: const arr = [ [1, 3, 5], [3, 5, 7], [2, 4, 2] ]; console.log(arr); [ [ 1, 3, 5 ], [ 3, 5, 7 ], [ 2, 4, 2 ] ] We need to write a JavaScript function that calculates the absolute difference between the sum of elements on the two diagonals of the matrix. Understanding the Diagonals In a square matrix, there are two diagonals: ...

Read More

How to validate if an element in an array is repeated? - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 343 Views

We are required to write a JavaScript function that takes in two arguments: An Array, say arr, of literals that may contain some repeating elements. A number, say limit. The function should validate that no element of the array is repeated more than limit number of times. If any element is repeated more than the limit the function should return false, true otherwise. Using Object to Count Occurrences The most efficient approach is to use an object to count each element's occurrences, then check if any count exceeds ...

Read More

Compare and fill arrays - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 269 Views

We are required to write a function that compares two arrays and creates a third array filling that array with all the elements of the second array and filling null for all those elements that are present in the first array but misses out in the second array. For example − If the two arrays are − const arr1 = ['f', 'g', 'h']; const arr2 = ['f', 'h']; Then the output should be − const output = ['f', null, 'h']; Algorithm Approach The solution uses an offset variable to ...

Read More

How to select the middle of an array? - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 676 Views

We are required to write a JavaScript function that takes in an array of numbers and returns the middlemost element(s) of the array. For arrays with odd length, there's one middle element. For arrays with even length, there are two middle elements. For example, if the array is: const arr = [1, 2, 3, 4, 5, 6, 7]; Then the output should be [4] (the middle element at index 3). Using Array Prototype Method We can extend the Array prototype to add a middle() method that returns the middle element(s): ...

Read More
Showing 1–10 of 5,881 articles
« Prev 1 2 3 4 5 589 Next »
Advertisements