Created
April 3, 2019 16:01
-
-
Save simoales/86f94d7c6e0b336ebfc66dd7fdd13594 to your computer and use it in GitHub Desktop.
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() { | |
String name = 'Simone'; | |
String result = reverse(name); | |
print (result); | |
String mySongs = sing(); | |
print (mySongs); | |
String myName = 'Simone'; | |
String yourName = 'Luke Skywalker'; | |
myName = yourName; | |
myName = 'Paul'; | |
print (yourName); | |
Person paul = Person(); | |
Person mary = Person(name:'Mary', surname: 'Brown'); | |
paul.name = 'Paul'; | |
paul.surname = 'Green'; | |
print (paul.name); | |
paul = mary; | |
print (paul.name); | |
paul.name = 'Paul'; | |
print (mary.name); | |
} | |
double calculateArea(double width, double height) { | |
double area = width * height; | |
return area; | |
} | |
//for and strings | |
String reverse(String old) { | |
int length = old.length; | |
print (length); | |
String res = ''; | |
for (int i = length-1; i>=0; i--) { | |
print('i: ' + i.toString()); | |
res += old.substring(i,i + 1); | |
} | |
return res; | |
} | |
//while and generics | |
String sing() { | |
var songs = List<String>(); | |
var songString = ''; | |
songs.add('We will Rock You'); | |
songs.add('Another Brick in the Wall'); | |
songs.add('Sultans of Swing'); | |
int i=0; | |
while (i < songs.length) { | |
songString += '${songs[i]} - '; | |
i++; | |
} | |
return songString; | |
} | |
//arrow syntax | |
bool convertToBool(int value) => (value == 0)?false:true; | |
bool convertToBoolLong(int value) { | |
if (value == 0) { | |
return false; | |
} | |
else { | |
return true; | |
} | |
} | |
//class, and constructor with optional parameters | |
class Person { | |
String name, surname; | |
Person({this.name, this.surname}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment