Search This Blog

Wednesday, 28 August 2024

Bouncing ball animation with CSS

HTML:
<div class="ball"></div>


CSS:

        .ball {
            width: 25px;
            height: 25px;
            background-color: #61dafb;
            border-radius: 50%;
            position: relative;
            animation: bounce 2s infinite ease-in-out;
        }
        
        @keyframes bounce {
            0%, 100% {
                transform: translateY(0);
            }
            50% {
                transform: translateY(-100px);
            }
        }



Create a perfect circle with CSS

HTML:

 <div class="circle"></div>


CSS:

.circle { 

      width: 250px

      height: 250px

      background-color: #e74c3c

      border-radius: 50%

}

Tuesday, 27 August 2024

Finding Minimum and Maximum Values Using the JavaScript reduce Function

You can find the minimum and maximum values in an array using the JavaScript reduce function by iterating through the array and keeping track of the minimum and maximum values encountered. 

reduce function: Iterates through each element of the array, maintaining an accumulator (acc) which, in this case, is an object that holds both the minimum and maximum values.

Here's how you can do it:

Example:

----------------------------------------------------------------------

const numbers = [3, 5, 1, 8, 2, 10]; 

const result = numbers.reduce((acc, current) =>

  return { 

      min: current < acc.min ? current : acc.min

      max: current > acc.max ? current : acc.max 

 }; 

}, { min: Infinity, max: -Infinity }); 

  console.log(`Min: ${result.min}, Max: ${result.max}`);

----------------------------------------------------------------------