Skip to content

Commit ec35637

Browse files
committed
refactor(input-otp): change for loop to findIndex
1 parent 72755ce commit ec35637

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

core/src/components/input-otp/input-otp.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -686,19 +686,16 @@ export class InputOTP implements ComponentInterface {
686686
}
687687

688688
/**
689-
* Loops through the input values and returns the index
689+
* Searches through the input values and returns the index
690690
* of the first empty input.
691691
* Returns -1 if all inputs are filled.
692692
*/
693693
private getFirstEmptyIndex() {
694694
const { inputValues, length } = this;
695-
696-
for (let i = 0; i < length; i++) {
697-
if (!inputValues[i] || inputValues[i] === '') {
698-
return i;
699-
}
700-
}
701-
return -1;
695+
// Create an array of the same length as the input OTP
696+
// and fill it with the input values
697+
const values = Array.from({ length }, (_, i) => inputValues[i] || '');
698+
return values.findIndex(value => !value || value === '') ?? -1;
702699
}
703700

704701
/**

0 commit comments

Comments
 (0)