add answer commits completed so far
This commit is contained in:
parent
b1ed7aa800
commit
118e204236
exercises
|
@ -1,8 +1,11 @@
|
||||||
// functions1.rs
|
// functions1.rs
|
||||||
// Make me compile! Execute `rustlings hint functions1` for hints :)
|
// Make me compile! Execute `rustlings hint functions1` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me();
|
call_me();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn call_me() {
|
||||||
|
println!("heres my number 0558974478, call me");
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
// functions2.rs
|
// functions2.rs
|
||||||
// Make me compile! Execute `rustlings hint functions2` for hints :)
|
// Make me compile! Execute `rustlings hint functions2` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me(3);
|
let num = 3;
|
||||||
|
call_me(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_me(num:) {
|
fn call_me(num: i32) {
|
||||||
for i in 0..num {
|
for i in 0..num {
|
||||||
println!("Ring! Call number {}", i + 1);
|
println!("Ring! Call number {}", i + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
// functions3.rs
|
// functions3.rs
|
||||||
// Make me compile! Execute `rustlings hint functions3` for hints :)
|
// Make me compile! Execute `rustlings hint functions3` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
call_me();
|
call_me(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_me(num: i32) {
|
fn call_me(num: i32) {
|
||||||
|
|
|
@ -4,14 +4,13 @@
|
||||||
// This store is having a sale where if the price is an even number, you get
|
// This store is having a sale where if the price is an even number, you get
|
||||||
// 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
|
// 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let original_price = 51;
|
let original_price = 502;
|
||||||
println!("Your sale price is {}", sale_price(original_price));
|
println!("Your sale price is {}", sale_price(original_price));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sale_price(price: i32) -> {
|
fn sale_price(price: i32) -> i32 {
|
||||||
if is_even(price) {
|
if is_even(price) {
|
||||||
price - 10
|
price - 10
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// functions5.rs
|
// functions5.rs
|
||||||
// Make me compile! Execute `rustlings hint functions5` for hints :)
|
// Make me compile! Execute `rustlings hint functions5` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let answer = square(3);
|
let answer = square(3);
|
||||||
|
@ -9,5 +8,5 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn square(num: i32) -> i32 {
|
fn square(num: i32) -> i32 {
|
||||||
num * num;
|
num * num //remove the semicolon to complile
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// if1.rs
|
// if1.rs
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
pub fn bigger(a: i32, b: i32) -> i32 {
|
pub fn bigger(a: i32, b: i32) -> i32 {
|
||||||
// Complete this function to return the bigger number!
|
// Complete this function to return the bigger number!
|
||||||
|
@ -8,7 +7,13 @@ pub fn bigger(a: i32, b: i32) -> i32 {
|
||||||
// - another function call
|
// - another function call
|
||||||
// - additional variables
|
// - additional variables
|
||||||
// Execute `rustlings hint if1` for hints
|
// Execute `rustlings hint if1` for hints
|
||||||
|
if a > b {
|
||||||
|
a
|
||||||
|
} else {
|
||||||
|
b
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Don't mind this for now :)
|
// Don't mind this for now :)
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -4,13 +4,15 @@
|
||||||
// Step 2: Get the bar_for_fuzz and default_to_baz tests passing!
|
// Step 2: Get the bar_for_fuzz and default_to_baz tests passing!
|
||||||
// Execute the command `rustlings hint if2` if you want a hint :)
|
// Execute the command `rustlings hint if2` if you want a hint :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
// DONE
|
||||||
|
|
||||||
pub fn fizz_if_foo(fizzish: &str) -> &str {
|
pub fn fizz_if_foo(fizzish: &str) -> &str {
|
||||||
if fizzish == "fizz" {
|
if fizzish == "fizz" {
|
||||||
"foo"
|
"foo"
|
||||||
|
} else if fizzish == "fuzz" {
|
||||||
|
"bar"
|
||||||
} else {
|
} else {
|
||||||
1
|
"baz"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
// move_semantics1.rs
|
// move_semantics1.rs
|
||||||
// Make me compile! Execute `rustlings hint move_semantics1` for hints :)
|
// Make me compile! Execute `rustlings hint move_semantics1` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
// DONE
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let vec0 = Vec::new();
|
let vec0 = Vec::new();
|
||||||
|
|
||||||
let vec1 = fill_vec(vec0);
|
//solution: add mut to vec1 variable
|
||||||
|
let mut vec1 = fill_vec(vec0);
|
||||||
|
|
||||||
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,18 @@
|
||||||
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
||||||
// the price of an order of apples given the order amount. No hints this time!
|
// the price of an order of apples given the order amount. No hints this time!
|
||||||
|
|
||||||
// I AM NOT DONE
|
// DONE
|
||||||
|
|
||||||
// Put your function here!
|
// Put your function here!
|
||||||
// fn ..... {
|
// fn ..... {
|
||||||
|
fn calculate_apple_price(x: i32) -> i32 {
|
||||||
|
let num = x;
|
||||||
|
if num > 40 {
|
||||||
|
x * 1
|
||||||
|
} else {
|
||||||
|
x * 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't modify this function!
|
// Don't modify this function!
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -17,14 +17,14 @@ fn string(arg: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
???("blue");
|
string_slice("blue");
|
||||||
???("red".to_string());
|
string("red".to_string());
|
||||||
???(String::from("hi"));
|
string(String::from("hi"));
|
||||||
???("rust is fun!".to_owned());
|
string("rust is fun!".to_owned());
|
||||||
???("nice weather".into());
|
string_slice("nice weather".into());
|
||||||
???(format!("Interpolation {}", "Station"));
|
string(format!("Interpolation {}", "Station"));
|
||||||
???(&String::from("abc")[0..1]);
|
string(String::from("abc")[0..1].to_string());
|
||||||
???(" hello there ".trim());
|
string_slice(" hello there ".trim());
|
||||||
???("Happy Monday!".to_string().replace("Mon", "Tues"));
|
string("Happy Monday!".to_string().replace("Mon", "Tues"));
|
||||||
???("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
string("mY sHiFt KeY iS sTiCkY".to_lowercase());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue