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

Merged array utility method and conditional statements flutter #716

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
24 changes: 14 additions & 10 deletions Android_Development/Flutter/Introduction_To_Dart/exercises.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# πŸ’» Exercises

## :star: Array Utility Methods :
1. Explain briefly about the working of the Array Utility Methods forEach(), map() and reduce(). Use these methods to solve the following questions.\
a) Given an array **numbers** = [2,3,5,6,8,9], print the square of these numbers.\
b) Given an array **principal_amount** = [100,500,2000,700,950], return a new array, filled with the simple interest of each of the element in principal_amount array for a **time period** of **2 years** and a **rate of interest** of **15%**.\
Expand All @@ -10,8 +10,10 @@ The forEach() method, traverses over every element of the given iterable and per
The map() method is similar to forEach(), but it actually returns an iterable, whereas forEach() returns a void type.\
The reduce() method is used to obtain a cumulative single value from a given collection.
\
```
a)
```
```dart
void main(){
var numbers = [2,3,5,6,8,9];
var op = numbers.forEach((number)=>print(number*number));
Expand All @@ -26,7 +28,7 @@ a)
81
```
b)
```
```dart
void main(){
var principal_amount = [100,500,2000,700,950];
var op = principal_amount.map((p)=>p*2*15/100);
Expand All @@ -37,7 +39,7 @@ a)
(30, 150, 600, 210, 285)
```
c)
```
```dart
void main(){
var studentHeigths = [171,185,163,154,173];
var op = studentHeigths.reduce((current,next)=>current+next);
Expand All @@ -50,7 +52,7 @@ a)
2. Given an array of building heights **bHeights** = [828,501,1002,321,978,200], sort the array and print the building heights in descending order.\
\
**Answer:**
```
```dart
void main(){
var bHeights = [828,501,1002,321,978,200];
bHeights.sort((h1,h2)=>h2-h1);
Expand All @@ -68,34 +70,36 @@ a)
3. Given an array of shortlisted candidates for a program **candidates** = ["James","Joseph","Jessica","John","Jonas"], check if a student called John is present in it.\
\
**Answer:**
```
```dart
void main(){
var candidates = ["James","Joseph","Jessica","John","Jonas"];
print(candidates.contains("John"));
}

Output:
true
```



## Conditional Statements :
## :star: Conditional Statements :
### 1. If Condition

- Print "Excellent work" if the student scores A grade


```dart
```dart
void main() {
String grade = "A";
if (grade == "A") {
print("Excellent work");
}
}
```
```
```
```
Output:
Excellent work
```
```

### 2. If Else Condition

Expand Down