Question #242HardFlutter Basics

If the input data = “Flutter apps are so beautiful” , output data = “rettulf sppa era os lufituaeb” write a code for this input and the expected result is output data ?

#flutter

Answer

String Reversal

Problem: Reverse each word but keep word order. Input: "Flutter apps are so beautiful" Output: "rettulf sppa era os lufituaeb"


Solution

dart
String reverseWords(String input) {
  return input
      .split(' ')
      .map((word) => word.split('').reversed.join())
      .join(' ');
}

void main() {
  String input = "Flutter apps are so beautiful";
  print(reverseWords(input));
  // Output: rettulf sppa era os lufituaeb
}

Extension Method

dart
extension StringExt on String {
  String reverseEachWord() {
    return split(' ').map((w) => w.split('').reversed.join()).join(' ');
  }
}

void main() {
  print("Flutter apps".reverseEachWord()); // rettulf sppa
}

Tip: Use RegExp for complex transformations.