mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-06 10:03:30 +02:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27abea4b5b |
Generated
-4
@@ -167,10 +167,6 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "exercises"
|
||||
version = "0.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.4.1"
|
||||
|
||||
+1
-4
@@ -1,10 +1,7 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"rustlings-macros",
|
||||
"dev",
|
||||
]
|
||||
exclude = [
|
||||
"tests/test_exercises",
|
||||
"dev",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
|
||||
@@ -8,7 +8,7 @@ fn is_even(num: i64) -> bool {
|
||||
}
|
||||
|
||||
// TODO: Fix the function signature.
|
||||
fn sale_price(price: i64) -> i64 {
|
||||
fn sale_price(price: i64) -> {
|
||||
if is_even(price) {
|
||||
price - 10
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// TODO: Fix the function body without changing the signature.
|
||||
fn square(num: i32) -> i32 {
|
||||
num * num
|
||||
num * num;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -4,11 +4,6 @@ fn bigger(a: i32, b: i32) -> i32 {
|
||||
// Do not use:
|
||||
// - another function call
|
||||
// - additional variables
|
||||
if a > b {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
fn picky_eater(food: &str) -> &str {
|
||||
if food == "strawberry" {
|
||||
"Yummy!"
|
||||
} else if food == "potato" {
|
||||
"I guess I can eat that."
|
||||
} else {
|
||||
"No thanks!"
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ fn animal_habitat(animal: &str) -> &str {
|
||||
let identifier = if animal == "crab" {
|
||||
1
|
||||
} else if animal == "gopher" {
|
||||
2
|
||||
2.0
|
||||
} else if animal == "snake" {
|
||||
3
|
||||
} else {
|
||||
0
|
||||
"Unknown"
|
||||
};
|
||||
|
||||
// Don't change the expression below!
|
||||
|
||||
@@ -8,8 +8,7 @@ fn main() {
|
||||
|
||||
// TODO: Define a boolean variable with the name `is_evening` before the `if` statement below.
|
||||
// The value of the variable should be the negation (opposite) of `is_morning`.
|
||||
let is_evening = true;
|
||||
|
||||
// let …
|
||||
if is_evening {
|
||||
println!("Good evening!");
|
||||
}
|
||||
|
||||
@@ -11,18 +11,6 @@
|
||||
// TODO: Write a function that calculates the price of an order of apples given
|
||||
// the quantity bought.
|
||||
// fn calculate_price_of_apples(???) -> ??? { ??? }
|
||||
fn calculate_price_of_apples(apples: i32) -> i32 {
|
||||
let mut cost: i32 = 2;
|
||||
|
||||
if apples > 40 {
|
||||
cost = 1;
|
||||
cost *= apples;
|
||||
cost
|
||||
} else {
|
||||
cost *= apples;
|
||||
cost
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
|
||||
Reference in New Issue
Block a user