🔒 Closed String Shuffler (skips space character)

Status
Not open for further replies.

Katipunero-

Honorary Poster
Code:
void main() {
  print("ice cream".shuffled);
}

extension Shuffle on String {
  String get shuffled {
    final letters = split('')
      ..removeWhere((letter) => letter == ' ')
      ..shuffle();

    return replaceAllMapped(
      RegExp(r'[^ ]'),
      (match) =>
          Iterable.generate(match[0]!.length, (_) => letters.removeLast())
              .join(),
    );
  }
}

You do not have permission to view the full content of this post. Log in or register now.
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 604
    Views
  • 1
    Participants
Last reply from:
Katipunero-

Trending Topics

Online now

Members online
1,190
Guests online
3,026
Total visitors
4,216

Forum statistics

Threads
2,307,957
Posts
29,182,209
Members
1,192,697
Latest member
Redjuice
Back
Top