Sunday, December 1, 2024

Find the value from array when age is more than 30

 const data = [

  { id: 1, name: 'Alice', age: 25 },

  { id: 2, name: 'Bob', age: 30 },

  { id: 3, name: 'Charlie', age: 35 }

];


const result = data.reduce((x,y) => {

 if(y.age >= 30){

   x.push(y);

 }

 return x;

  },[]

)

console.log(result);


*/


const data = [

  { id: 1, name: 'Alice', age: 25 },

  { id: 2, name: 'Bob', age: 30 },

  { id: 3, name: 'Charlie', age: 35 }

];

const result = data.find((x,y) =>{

  console.log(x);

  console.log(y);

})

console.log(result);

Print * as triangle

 function printLeftAlignedTriangle(height) {

    for (let i = 1; i <= height; i++) {

        let row = '';

        // Add stars

      //  for (let j = 0; j < i; j++) {

           // row += '*';

       // }

       for(let j = height-1; j >= i; j--){

           row += '*';

           //console.log(row);

       }

        console.log(row);

    }

}

printLeftAlignedTriangle(5);

Find the value from array when age is more than 30

 const data = [   { id: 1, name: 'Alice', age: 25 },   { id: 2, name: 'Bob', age: 30 },   { id: 3, name: 'Charlie', ...