-1

function multiplyer(...arr){
    let res=[],product=1;
    
    for(var j=arr.length-1;j>=0;j--){
      
      res.unshift(arr[j].map(item=>item*product))
      product*=10
    }
    return res;
  }
  console.log(multiplyer([[2,3][3,5]]))
  

I was expecting something like [[20,30][3,5]] but I think I have a problem with accessing the 2d array's elements. Results come as [ [ NaN ] ]

Latecoder
  • 79
  • 5

1 Answers1

1

For one issue, [ [ 2, 3 ][ 3, 5 ] ] needs an extra comma to make it a 2d array: [ [ 2, 3 ], [ 3, 5 ] ]

And another issue is an unnesseary spread operator (...) in the function definition messes up the function.

function multiplyer(arr) {
  let res = [],
    product = 1;

  for (var j = arr.length - 1; j >= 0; j--) {
    res.unshift(arr[j].map(item => item * product))
    product *= 10;
  }
  return res;
}
console.log(multiplyer([
  [2, 3],
  [3, 5]
]))
Samathingamajig
  • 11,839
  • 3
  • 12
  • 34