Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create palindrome.dart #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions strings/palindrome.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
void main(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a function outside main which checks for palindrome.

print('Enter Words or number');
// User enter a string or a number
String? original = 'hannah';

// then we will reverse the input
String? reverse = original.split('').reversed.join('');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid printing

// then we will compare
if(original == reverse)
{
print('Its A Palindrome');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very new to this. What are tests? I will be updating everything as you requested

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can check out other files. to see how tests are implemented.

You can also read up from the official docs:
https://pub.dev/packages/test

}else{
print('Its A Not Palindrome');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we optimise this? can we have an algorithm with lesser space complexity?

Also reduce the use of inbuilt functions like reversed. split and join. The Algorithm will be quite inefficient.


}