Skip to main content
  • Create an array of numbers and take input from user and add into array
  • Keep adding numbers to array untill zero is added
  • Filter for numbers divisible by 10
  • Create an array of square of the numbers
  • Use reduce to calculate factorial of a given number from an array of first n natural numbers (n being te number whose factorial needs to be calculated)
  • 
      // Problemm No 1
      let arr = [1,2,3,4]
      let a = prompt("Enter a number")
      a = Number.parseInt(a)
      arr.push(a)
      console.log(a)
    
      // Problem No 2
      let arr2 = [  3, 4]
      let b = prompt("Enter a number");
      b = Number.parseInt(b)
      while (b!= 0) {
          if (!isNaN(b)) {arr2.push(b)}
          b = prompt("Enter a number")
          b = Number.parseInt(b)
      }
      console.log(arr2)
      // If 0 also should be added
      let c;
      let arr3 = [4,5]
      do {
          c = prompt("Enter a number");
          c = Number.parseInt(c)
          arr3.push(c)
      } while (c!=0)
      console.log(arr3)
    
      // Problem No 3
    
      let d = [10,9,8,90,80,5,50]
      let d_new = d.filter((value)=>{
          return value%10 == 0
      })
      console.log(d_new)
    
      // Problem No 4
      let e  =[ 1,2,3,4]
      let e_new = e.map((value)=> {
          return value*value
      })
      console.log(e_new)
    
      // Problem No 5
      let f = [1,2,3,4]
      let f_new = f.reduce((value1,value2)=>{
          return value1*value2
      })
      console.log(f_new)