Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit 045af63

Browse files
committed
BestFitFormatMatcher: make algo the right pattern
1 parent 2e31880 commit 045af63

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/12.datetimeformat.js

+12-17
Original file line numberDiff line numberDiff line change
@@ -689,23 +689,18 @@ function BestFitFormatMatcher (options, formats) {
689689
// 4. Let delta be max(min(formatPropIndex - optionsPropIndex, 2), -2).
690690
let delta = Math.max(Math.min(formatPropIndex - optionsPropIndex, 2), -2);
691691

692-
{
693-
// diverging from spec
694-
// When the bestFit argument is true, subtract additional penalty where data types are not the same
695-
if ((formatPropIndex <= 1 && optionsPropIndex >= 2) || (formatPropIndex >= 2 && optionsPropIndex <= 1)) {
696-
// 5. If delta = 2, decrease score by longMorePenalty.
697-
if (delta > 0)
698-
score -= longMorePenalty;
699-
else if (delta < 0)
700-
score -= longLessPenalty;
701-
} else {
702-
// 5. If delta = 2, decrease score by longMorePenalty.
703-
if (delta > 1)
704-
score -= shortMorePenalty;
705-
else if (delta < -1)
706-
score -= shortLessPenalty;
707-
}
708-
}
692+
// 5. If delta = 2, decrease score by longMorePenalty.
693+
if (delta === 2)
694+
score -= longMorePenalty;
695+
// 6. Else if delta = 1, decrease score by shortMorePenalty.
696+
else if (delta === 1)
697+
score -= shortMorePenalty;
698+
// 7. Else if delta = -1, decrease score by shortLessPenalty.
699+
else if (delta === -1)
700+
score -= shortLessPenalty;
701+
// 8. Else if delta = -2, decrease score by longLessPenalty.
702+
else if (delta === -2)
703+
score -= longLessPenalty;
709704
}
710705
}
711706

0 commit comments

Comments
 (0)