This repository contains examples and explanations of recursion in Dart language.
Recursion is a technique of solving a problem by breaking it down into smaller sub-problems that are similar in nature to the original problem. In programming, recursion involves a function calling itself repeatedly until a base condition is met.
Recursion can simplify complex problems that can be broken down into smaller, similar sub-problems. It can also make code more readable and easier to maintain.
To use these examples, you will need to have Dart installed on your machine. You can download and install Dart from the official website https://dart.dev/get-dart, or you can quickly get started by using dartpad.
Once you have Dart installed, you can clone this repository using the following command:
git clone https://github.com/davidnwaneri/recdart.git
This repository contains the following examples of recursion in Dart language:
- Palindrome: A palindrome is a word, phrase, number, or sequence of characters that reads the same backward as forward. For example, "racecar".
bool isPalindrome(String input) {
if (input.length <= 1) return true;
final firstChar = input.split('')[0];
final lastChar = input.split('')[input.length - 1];
if (firstChar == lastChar) {
return isPalindrome(input.substring(1, input.length - 1));
}
return false;
}
// Usage example
print(isPalindrome('racecar') // Output: true
print(isPalindrome('ketchup') // Output: false
If you would like to contribute to this repository, please fork the repository and create a pull request with your changes. We welcome contributions of all kinds, including bug fixes, new examples, and improvements to existing examples.
This repository is licensed under the MIT License. See the LICENSE file for more information.