Skip to content

Instantly share code, notes, and snippets.

@jakazzy
Last active October 19, 2020 04:21
Show Gist options
  • Save jakazzy/e61e998e2335e83726efc68cb26732bf to your computer and use it in GitHub Desktop.
Save jakazzy/e61e998e2335e83726efc68cb26732bf to your computer and use it in GitHub Desktop.
Sample DSA in dart
void main() {
// 1. Loop through a list of numbers and print out the square of the numbers
List ages = [6, 7, 5, 3];
for (int i = 0; i < ages.length; i++) {
print( ages[i] * ages[i]);
}
// 2. Use a for loop to print out all the letters in your name
List name = ['a', 'd', 'w', 'o', 'a'];
for (int i = 0; i < name.length; i++) {
print( name[i]);
}
//3. Use a while loop to perform the same task
List nam = ['a', 'd', 'w', 'o', 'a'];
var num = 0;
while (num < nam.length){
print(nam[num]);
num++;
};
// 4. Checks if a string is a palindrome or not
isPalindrome(str){
var newStr = str.split('').reversed.join('');
return str == newStr;
}
//5. Takes in two lists and checks if the first is a sub-list of the second
subset(list1, list2){
var result = list1.every((val) => list2.contains(val) ? true : false);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment