Docs
This commit is contained in:
parent
78fe9e7b09
commit
c7324a6b19
458 changed files with 93141 additions and 47 deletions
|
@ -2,9 +2,14 @@ extension StringExtensions on String {
|
|||
/// Returns true if given word contains atleast all the characters in [targetChars], and `false` otherwise
|
||||
///
|
||||
/// Very efficient `O(n)` instead of naive `O(n*m)`
|
||||
bool containsAllCharacters({required String targetChars}) {
|
||||
final Set<String> characterSet = Set.from(targetChars.split(''));
|
||||
for (final testChar in split('')) {
|
||||
bool containsAllCharacters({
|
||||
required String targetChars,
|
||||
bool ignoreCase = true,
|
||||
}) {
|
||||
final Set<String> characterSet = ignoreCase
|
||||
? Set.from(targetChars.toLowerCase().split(''))
|
||||
: Set.from(targetChars.split(''));
|
||||
for (final testChar in ignoreCase ? toLowerCase().split('') : split('')) {
|
||||
characterSet.remove(testChar);
|
||||
if (characterSet.isEmpty) return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue