Created
January 23, 2023 23:26
-
-
Save ashraf267/829eed874a9f348ed92076eeb3de7099 to your computer and use it in GitHub Desktop.
This dart code checks if a given word ends with 'ing' (return true) or not (return false)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// todo | |
print("Hello World!"); | |
HighEngine firstWord = HighEngine(word: 'engine'); | |
print(firstWord.word); | |
print(firstWord.checkWord()); | |
// sandbox | |
String firstName = "Deji"; | |
print("${(firstName.length + 2) - 1}"); | |
print(firstName.split('')); | |
for (int i = 0; i < 5; i++) { | |
print(i); | |
} | |
} | |
// 'ing' | |
class HighEngine { | |
String word; | |
HighEngine({required this.word}); | |
bool checkWord() { | |
bool output = false; // default val | |
// this method checks if the given word end with 'ing' or not | |
// convert the given word to an array | |
List wordArr = word.split(''); | |
// loop through the wordArr from the back; start search from the end of string | |
for (int i = 0; i < wordArr.length; i++) { | |
// do something | |
// print("${(wordArr.length - 1) - i}"); | |
// print(wordArr[(wordArr.length - 1) - i]); // prints the wordArr from the end | |
// check if the first char is g else stop | |
if (wordArr[(wordArr.length - 1) - i] == 'g') { | |
// true - first level of three passed | |
i += 1; | |
// check if the second char is n else stop | |
if (wordArr[(wordArr.length - 1) - i] == 'n') { | |
// true - second level of three passed | |
i += 1; | |
// check if the third char is i else stop | |
if (wordArr[(wordArr.length - 1) - i] == 'i') { | |
// true - last level passed | |
output = true; | |
} else { | |
// false | |
// jump out, pls | |
break; | |
} | |
} else { | |
// false | |
// okay fine, jump out | |
break; | |
} | |
} else { | |
// false | |
// japa x3 | |
break; | |
} | |
} | |
return (output); | |
// demo return | |
// return (true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment