mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-28 00:00:03 +03:00
Complete primitives exercises
This commit is contained in:
parent
fca2d54cb8
commit
d3ae805794
|
@ -3,8 +3,6 @@
|
|||
// Fill in the rest of the line that has code missing! No hints, there's no
|
||||
// tricks, just get used to typing these :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
// Booleans (`bool`)
|
||||
|
||||
|
@ -13,7 +11,7 @@ fn main() {
|
|||
println!("Good morning!");
|
||||
}
|
||||
|
||||
let // Finish the rest of this line like the example! Or make it be false!
|
||||
let is_evening = false;// Finish the rest of this line like the example! Or make it be false!
|
||||
if is_evening {
|
||||
println!("Good evening!");
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
// Fill in the rest of the line that has code missing! No hints, there's no
|
||||
// tricks, just get used to typing these :)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
// Characters (`char`)
|
||||
|
@ -19,7 +18,7 @@ fn main() {
|
|||
println!("Neither alphabetic nor numeric!");
|
||||
}
|
||||
|
||||
let // Finish this line like the example! What's your favorite character?
|
||||
let your_character = '-'; // Finish this line like the example! What's your favorite character?
|
||||
// Try a letter, try a number, try a special character, try a character
|
||||
// from a different language than your own, try an emoji!
|
||||
if your_character.is_alphabetic() {
|
||||
|
@ -29,4 +28,9 @@ fn main() {
|
|||
} else {
|
||||
println!("Neither alphabetic nor numeric!");
|
||||
}
|
||||
|
||||
// double quotes are for string literals - or type &str
|
||||
// single quotes are for character literals - or type char
|
||||
// you would also use single quoters to denote lifetimes.
|
||||
|
||||
}
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
// Execute `rustlings hint primitive_types3` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let a = ???
|
||||
let a = [1; 100];
|
||||
|
||||
if a.len() >= 100 {
|
||||
println!("Wow, that's a big array!");
|
||||
|
|
|
@ -5,13 +5,11 @@
|
|||
// Execute `rustlings hint primitive_types4` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[test]
|
||||
fn slice_out_of_array() {
|
||||
let a = [1, 2, 3, 4, 5];
|
||||
|
||||
let nice_slice = ???
|
||||
let nice_slice = &a[1..4];
|
||||
|
||||
assert_eq!([2, 3, 4], nice_slice)
|
||||
}
|
||||
|
|
|
@ -5,11 +5,13 @@
|
|||
// Execute `rustlings hint primitive_types5` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
// Tuples are ways to group together values with different types
|
||||
// they have fixed lengths - cannot grow or shrink
|
||||
// considered a sinle compound and it can be destructured
|
||||
// it can be more than 2 values at a time.
|
||||
let cat = ("Furry McFurson", 3.5);
|
||||
let /* your pattern here */ = cat;
|
||||
let (name, age)/* your pattern here */ = cat;
|
||||
|
||||
println!("{} is {} years old.", name, age);
|
||||
}
|
||||
|
|
|
@ -6,13 +6,12 @@
|
|||
// Execute `rustlings hint primitive_types6` or use the `hint` watch subcommand
|
||||
// for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
#[test]
|
||||
fn indexing_tuple() {
|
||||
let numbers = (1, 2, 3);
|
||||
// Replace below ??? with the tuple indexing syntax.
|
||||
let second = ???;
|
||||
let second = numbers.1;
|
||||
|
||||
assert_eq!(2, second,
|
||||
"This is not the 2nd number in the tuple!")
|
||||
|
|
Loading…
Reference in a new issue