Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98cde6f

Browse files
committed
Add slice exercise from @ruipserra!!! 💫✨
Connects to rust-lang#29
1 parent eed8106 commit 98cde6f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Get a slice out of Array a where the ??? is so that the `if` statement
2+
// returns true. Scroll down for hints!!
3+
4+
fn main() {
5+
let a = [1, 2, 3, 4, 5];
6+
7+
let nice_slice = ???
8+
9+
if nice_slice == [2, 3, 4] {
10+
println!("Nice slice!");
11+
} else {
12+
println!("Not quite what I was expecting... I see: {:?}", nice_slice);
13+
}
14+
}
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
// Take a look at the Primitive Types -> Slices section of the book:
41+
// http://doc.rust-lang.org/stable/book/primitive-types.html#slices
42+
// and use the starting and ending indices of the items in the Array
43+
// that you want to end up in the slice.
44+
45+
// If you're curious why the right hand of the `==` comparison does not
46+
// have an ampersand for a reference since the left hand side is a
47+
// reference, take a look at the Deref coercions chapter:
48+
// http://doc.rust-lang.org/stable/book/deref-coercions.html

0 commit comments

Comments
 (0)