File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Sprint-3/revise/implement Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ function cardValidator ( num ) {
2+ const numStr = num . toString ( ) ; // Convert to string for iteration
3+ if ( numStr . length !== 16 || ! / ^ [ 0 - 9 ] + $ / . test ( numStr ) || numStr [ numStr . length - 1 ] % 2 === 1 ) {
4+ return false ; // Check length is 16 numbers long, if it only contains digits and if the last digits is even
5+ }
6+
7+ let firstDigit = numStr [ 0 ] ; // Track the first digit
8+ for ( let i = 1 ; i < numStr . length ; i ++ ) {
9+ if ( numStr [ i ] !== firstDigit ) {
10+ return true ; // Found at least two different digits
11+ }
12+ }
13+
14+ return false ; // All digits are the same
15+ }
16+
17+ console . log ( cardValidator ( 1111111111111111 ) ) ; // Output: false
18+ console . log ( cardValidator ( 1234567890123456 ) ) ; // Output: true
19+ console . log ( cardValidator ( 2222222222222222 ) ) ; // Output: false
20+ console . log ( cardValidator ( 3333333333333334 ) ) ; // Output: true
21+
You can’t perform that action at this time.
0 commit comments