How do I use reduce() here? Edit: figured it out!

Edit: This article was pretty helpful! Luhn Algorithm in JavaScript, Python, & Clojure: Part 1 | by A**** ****** | cyberdoggo | Medium

Here’s a link to the exercise Credit Card Checker

I am on the step where I need to get the sum of all the numbers in the array and I’m thinking reduce() is the way to do this but I’m not sure how to use it with combined. Examples online just don’t seem to translate to my situation.

const validateCred = array => {
  newArray =[]
  for (var i = array.length - 2; i >= 0; i -= 2) { 
  let doubleValue = array[i] * 2 
   if (doubleValue > 9) {
     doubleValue -= 9;
  }  newArray.push(doubleValue)

  for (var j = array.length -1; j >= 0; j -=2) {
    let combined = [].concat(newArray, array[j]);
    
  } 
  }
  }


validateCred(mystery1)


1 Like