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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Smart concatenation of strings in JavaScript
We need to write a JavaScript function that concatenates two strings with a smart approach. If the last character of the first string matches the first character of the second string, we omit one of those duplicate characters to avoid redundancy. Problem Statement When concatenating strings like "Food" and "dog", a simple join would give "Fooddog". However, since both strings share the character 'd' at the junction, smart concatenation removes the duplicate to produce "Foodog". Example Here's how to implement smart string concatenation: const str1 = 'Food'; const str2 = 'dog'; const concatenateStrings ...
Read MoreGrouping array of array on the basis of elements in JavaScript
When working with arrays of arrays in JavaScript, you might need to group elements based on specific criteria. This article demonstrates how to group the second elements of subarrays that share the same first element. Problem Statement Suppose we have an array of arrays where each subarray contains exactly two elements: const arr = [[1, 45], [1, 34], [1, 49], [2, 34], [4, 78], [2, 67], [4, 65]]; console.log("Input array:", arr); Input array: [ [ 1, 45 ], [ 1, 34 ], [ 1, 49 ], [ 2, 34 ], [ 4, 78 ...
Read MoreHow to get id from tr tag and display it in a new td with JavaScript?
When working with HTML tables, you often need to extract the ID from table rows and display them within the table itself. This tutorial shows how to get the ID from tags and add them as new table cells using JavaScript. Sample Table Structure Consider the following table with ID attributes on each row: StudentName StudentCountryName ...
Read MorePrefix calculator using stack in JavaScript
A Reverse Polish Notation (RPN) calculator processes operators after their operands, using a stack data structure. This implementation evaluates mathematical expressions efficiently without parentheses. How RPN Works In RPN, operators follow their operands. For example, "3 4 +" means "3 + 4". The algorithm uses a stack: Push operands onto the stack When encountering an operator, pop two operands, perform the operation, and push the result back The final stack contains the result Step-by-Step Process Consider the input array: const arr = [1, 5, '+', 6, 3, '-', '/', 7, '*']; ...
Read MoreSmallest prime number just greater than the specified number in JavaScript
We are required to write a JavaScript function that takes in a positive integer as the first and the only argument. The function should find one such smallest prime number which is just greater than the number specified as argument. For example − If the input is − const num = 18; Then the output should be: const output = 19; Understanding Prime Numbers A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. To check if a ...
Read MoreFinding the date at which money deposited equals a specific amount in JavaScript
When calculating compound interest over time, you may need to determine the exact date when your deposited money will reach a target amount. This problem involves daily compounding at a given annual interest rate. Problem Statement Given an initial deposit amount, a target amount, and an annual interest rate, we need to find the date when the deposited money (with daily compounding) will equal or exceed the target amount. The calculation starts from January 1st, 2021, with interest compounded daily at a rate of p percent divided by 360 days. Solution Approach The solution uses a ...
Read MoreHow to create dynamic values and objects in JavaScript?
Dynamic values are values assigned to variables whose names are determined at runtime rather than being hard-coded. In JavaScript, we can use dynamic property names in objects, allowing us to create flexible object structures where property names can be changed without modifying the object definition directly. Dynamic objects are particularly useful when you need to create properties based on variables, user input, or computed values. The key technique involves using square brackets [ ] syntax to define property names dynamically. Syntax Following is the syntax to create dynamic values and objects: const key = 'PropertyName'; ...
Read MoreFabricJS – How to set Polygon objects properties using function instead of constructor?
We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. Syntax set(key: String, value: String | Boolean | Number | Object | Function) Parameters key − This parameter accepts a String which specifies the property we ...
Read MoreHow to align images on a card with a dynamic title in Javascript?
Aligning images on a card with dynamic titles in JavaScript involves using CSS for layout and JavaScript for dynamic content updates. This creates responsive, interactive card components commonly used in modern web applications. Approach Create a card container using a div or section element with appropriate CSS classes. Add a header element for the dynamic title with a unique class or ID for styling and JavaScript targeting. Include an image element within the card container using the img tag or background image. Use CSS Flexbox properties like display: flex, justify-content, and align-items to control alignment. Apply responsive ...
Read MoreRemoving first k characters from string in JavaScript
We are required to write a JavaScript function that takes in a string and a number, say k and returns another string with first k characters removed from the string. For example: If the original string is − const str = "this is a string" and, n = 4 then the output should be − const output = " is a string" Method 1: Using substr() Method The substr() method extracts characters from a string starting at a specified position. const str = 'this ...
Read More