I've created a function called checkLength(input, min, max) which takes in a username and password input as shown below.
checkLength(username, 3, 15);
checkLength(password, 8, 25);
However, I'm looking to pass in an inputArray, minArray, maxArray to reduce the repetitiveness using a forEach loop. But it seems like a forEach loop can only take in one array at a time. Any suggestions on how I can improve this?
checkLength2([username,password], [3,8], [8,15])
function checkLength2 (inputArray, minArray, maxArray, i=0) {
inputArray.forEach(input => {
if (input.value < minArray[i]) {
//another error function
i++;
}
});}
[[username, 3, 8], [password, 8, 15]].forEach(args => checkLength(...args));is an approach.I'm looking to pass in an inputArray, minArray, maxArrayand now you have 3 lists that you need to maintain and keep in sync