Credit Card Checker validate Cards

Hello everyone,
I just finished the extra exercise on the Credit Card Checker project, which is to make those cards identified as invalid valid. Here’s a link to the exercise:
Creditcardchecker Project

My solution works, but I think I did it far too complicated. There must be an easier way I did not see.
My first idea was to get the rest of the sum % 10 from the Luhn algorithm and distribute it to every other digit from the right. That didn’t work. Now I do it in a while loop until it passes the Luhn test. Here’s my code:

const validateCards = (arrays) => {
	const invalidCards = arrays.filter(arr => !validateCred(arr));

  const validCards = invalidCards.map(arr => {
    let rest = luhnCheck(arr);
  	let counter = arr.length-2;
    while(rest > 0) {
      if(arr[counter] < 9) {
        arr[counter] = arr[counter] + 1;
      }
      rest = luhnCheck(arr);
      counter -= 2;
      if(counter <= 0) counter = arr.length-2;
    }
    return arr;
  });
  return validCards;
};

Here’s the complete file:
https://github.com/mirja-t/codecademy-js/blob/main/creditcardchecker.js

Does anyone have an idea how to solve this in a simpler way and less looping?