Searching for a way to implement the following code using functional programming techniques.
let membersFound = [];
// Iterate through 50 or more pages until we find 5 members.
while (membersFound.length < 5) {
let member = findMember(/* Invoke Selenium commands to navigate to next page */);
if (member !== undefined) {
membersFound.push(member);
}
}
console.log(membersFound); // Expected: 5 values, Actual: 0
At present, this code leads to an infinite loop due to the asynchronous nature of JavaScript.