Skip to main content

New js functions

/**
 * This function checks if a given string is a palindrome.
 * A palindrome is a word, phrase, or sequence that reads the same forward as backward.
 *
 * @param {string} str - The input string to check.
 * @returns {boolean} - True if the string is a palindrome, false otherwise.
 */
function isPalindrome(str) {
  // Remove non-alphanumeric characters and convert to lowercase
  const cleanStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();

  // Compare the string with its reversed version
  return cleanStr === cleanStr.split('').reverse().join('');
}

Front-end implementation of watermark function in react js

import React, { useRef, useEffect } from 'react';

function Watermark({ text, opacity = 0.1, color = 'rgba(0, 0, 0, 0.2)' }) {
  const canvasRef = useRef(null);

  useEffect(() => {
    const canvas = canvasRef.current;
    const context = canvas.getContext('2d');

    const drawWatermark = () => {
      canvas.width = window.innerWidth;
      canvas.height = window.innerHeight;

      context.fillStyle = color;
      context.globalAlpha = opacity;
      context.font = '20px Arial'; // Adjust font size and style as needed
      context.textAlign = '

Advanced Typescript: contravariance, covariance, bidirectional covariance, and invariance

In TypeScript, variance concepts (covariance, contravariance, and invariance) refer to how the relationship between types changes when they are used in different contexts, particularly with generic types. Understanding these concepts is essential when working with complex generic systems, as they influence how types can be assigned to each other in different scenarios. Let's break down each one: