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
Web Development Articles
Page 416 of 801
Convert JavaScript array iteration result into a single line text string
Let's say we have a string and an array of keywords to search for: const textString = 'Convert javascript array iteration result into a single line text string. Happy searching!'; const keywords = ['integer', 'javascript', 'dry', 'Happy', 'exam']; We need to write a function that maps the array to a string containing only true and false values, depending on whether each array element is present in the string or not. Solution Using reduce() and join() The most efficient approach uses reduce() to build an array of boolean values, then join() to convert it into ...
Read MoreAppend the current array with the squares of corresponding elements of the array in JavaScript
We have an array of Numbers like this: const arr = [12, 19, 5, 7, 9, 11, 21, 4]; We have to write a function that takes in such an array and returns a new array with all the items of the original array appended by the squares of corresponding elements of the array. For this sample array, the output should be: [12, 19, 5, 7, 9, 11, 21, 4, 144, 361, 25, 49, 81, 121, 441, 16] Method 1: Using reduce() The reduce() method can accumulate the original array ...
Read MoreDebugging JavaScript using Firebug
Debugging is the systematic method of removing defects from code. While JavaScript is a powerful scripting language for web development, it lacks built-in debugging functionalities. Fortunately, Firebug, a web browser-based debugger for Firefox, provides excellent tools for debugging JavaScript code effectively. Firefox Browser with Firebug Web Page Content ...
Read MoreAdding only odd or even numbers JavaScript
We are required to make a function that given an array of numbers and a string that can take any of the two values "odd" or "even", adds the numbers which match that condition. If no values match the condition, 0 should be returned. For example: conditionalSum([1, 2, 3, 4, 5], "even") => 6 conditionalSum([1, 2, 3, 4, 5], "odd") => 9 conditionalSum([13, 88, 12, 44, 99], "even") => 144 conditionalSum([], "odd") => 0 Using Array.reduce() Method We'll use the Array.prototype.reduce() method to iterate through the array and sum numbers based on the condition: ...
Read MoreHow to change tabs on hover with CSS and JavaScript?
In this article, we will discuss how to change tabs on hover with CSS and JavaScript. Hover Tabs are an interactive UI pattern that allows users to switch between different content sections by simply hovering over tab buttons. When you move your cursor over a tab, its associated content is immediately displayed without requiring a click. This creates a smooth, responsive user experience where content changes dynamically as users explore different options. For example, in a product showcase, hovering over different category tabs could instantly display relevant products. How It Works The hover tab system combines ...
Read MoreMake array numbers negative JavaScript
In JavaScript, you can convert all positive numbers in an array to negative while keeping already negative numbers unchanged. This is useful for data transformations where you need to invert positive values. Let's say we have the following array: const arr = [7, 2, 3, 4, 5, 7, 8, 12, -12, 43, 6]; We need to write a function that converts all positive numbers to negative while leaving negative numbers unchanged (like 4 to -4, 6 to -6, but -12 stays -12). Using Array.reduce() const arr = [7, 2, 3, 4, 5, ...
Read MoreVerification if a number is Palindrome in JavaScript
A palindrome number reads the same forwards and backwards. In JavaScript, we can check if a number is palindrome without converting it to a string by mathematically extracting and comparing digits. Palindrome numbers are those numbers which read the same from both backward and forward. For example: 121 343 12321 Algorithm Approach The algorithm works by: Finding a factor to extract the first digit Comparing first and last digits Removing both digits and repeating until all digits are checked Example const isPalindrome = (num) => { ...
Read MoreHow to create a full screen overlay navigation menu with CSS and JavaScript?
In this article, we are going to discuss how to create a full-screen overlay navigation menu with CSS and JavaScript. Overlay in web applications is nothing but transposing one HTML element over another. We can overlay images, pages, text, etc. A full-screen overlay navigation provides an elegant way to display navigation links that cover the entire viewport when activated. There are three ways to create a full-screen overlay navigation bar which are listed below: From the left side From the top side No animation There ...
Read MoreHow to create an off-canvas menu with CSS and JavaScript?
An off-canvas menu is a sidebar navigation that slides in from the side of the screen when activated. This design pattern is popular in responsive web design as it saves screen space while providing easy access to navigation links. Off-canvas menus are particularly useful for mobile devices and websites with numerous navigation items that don't fit in a traditional horizontal navigation bar. They can slide from left-to-right or right-to-left, and often overlay or push the main content aside. HTML Structure First, create the HTML structure with a sidebar navigation and main content area: ...
Read MoreSum of even numbers up to using recursive function in JavaScript
We have to write a recursive function that takes in a number n and returns the sum of all even numbers up to n. A recursive function calls itself with modified parameters until it reaches a base case. For summing even numbers, we'll start from the largest even number ≤ n and work our way down. How It Works The algorithm follows these steps: If the input number is odd, we adjust it to the nearest even number below it Add the current even number to the sum and recursively call with the next smaller ...
Read More