feat: move vec exercises into their own folder
This commit is contained in:
parent
8e1f617d34
commit
2f7fd51304
|
@ -1,23 +1,11 @@
|
||||||
# Collections
|
# Hashmaps
|
||||||
|
A *hash map* allows you to associate a value with a particular key.
|
||||||
|
You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map),
|
||||||
|
[*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages.
|
||||||
|
|
||||||
Rust’s standard library includes a number of very useful data
|
This is the other data structure that we've been talking about before, when
|
||||||
structures called collections. Most other data types represent one
|
talking about Vecs.
|
||||||
specific value, but collections can contain multiple values. Unlike
|
|
||||||
the built-in array and tuple types, the data these collections point
|
|
||||||
to is stored on the heap, which means the amount of data does not need
|
|
||||||
to be known at compile time and can grow or shrink as the program
|
|
||||||
runs.
|
|
||||||
|
|
||||||
This exercise will get you familiar with two fundamental data
|
|
||||||
structures that are used very often in Rust programs:
|
|
||||||
|
|
||||||
* A *vector* allows you to store a variable number of values next to
|
|
||||||
each other.
|
|
||||||
* A *hash map* allows you to associate a value with a particular key.
|
|
||||||
You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map),
|
|
||||||
[*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages.
|
|
||||||
|
|
||||||
## Further information
|
## Further information
|
||||||
|
|
||||||
- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html)
|
|
||||||
- [Storing Keys with Associated Values in Hash Maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html)
|
- [Storing Keys with Associated Values in Hash Maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html)
|
||||||
|
|
15
exercises/vecs/README.md
Normal file
15
exercises/vecs/README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# Vectors
|
||||||
|
|
||||||
|
Vectors are one of the most-used Rust data structures. In other programming
|
||||||
|
languages, they'd simply be called Arrays, but since Rust operates on a
|
||||||
|
bit of a lower level, an array in Rust is stored on the stack (meaning it
|
||||||
|
can't grow or shrink, and the size needs to be known at compile time),
|
||||||
|
and a Vector is stored in the heap (where these restrictions do not apply).
|
||||||
|
|
||||||
|
Vectors are a bit of a later chapter in the book, but we think that they're
|
||||||
|
useful enough to talk about them a bit earlier. We shall be talking about
|
||||||
|
the other useful data structure, hash maps, later.
|
||||||
|
|
||||||
|
## Further information
|
||||||
|
|
||||||
|
- [Storing Lists of Values with Vectors](https://doc.rust-lang.org/stable/book/ch08-01-vectors.html)
|
|
@ -1,8 +1,8 @@
|
||||||
// vec1.rs
|
// vecs1.rs
|
||||||
// Your task is to create a `Vec` which holds the exact same elements
|
// Your task is to create a `Vec` which holds the exact same elements
|
||||||
// as in the array `a`.
|
// as in the array `a`.
|
||||||
// Make me compile and pass the test!
|
// Make me compile and pass the test!
|
||||||
// Execute `rustlings hint vec1` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint vecs1` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// vec2.rs
|
// vecs2.rs
|
||||||
// A Vec of even numbers is given. Your task is to complete the loop
|
// A Vec of even numbers is given. Your task is to complete the loop
|
||||||
// so that each number in the Vec is multiplied by 2.
|
// so that each number in the Vec is multiplied by 2.
|
||||||
//
|
//
|
||||||
// Make me pass the test!
|
// Make me pass the test!
|
||||||
//
|
//
|
||||||
// Execute `rustlings hint vec2` or use the `hint` watch subcommand for a hint.
|
// Execute `rustlings hint vecs2` or use the `hint` watch subcommand for a hint.
|
||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
|
@ -242,8 +242,8 @@ Now you have another tool in your toolbox!"""
|
||||||
# VECS
|
# VECS
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "vec1"
|
name = "vecs1"
|
||||||
path = "exercises/collections/vec1.rs"
|
path = "exercises/vecs/vecs1.rs"
|
||||||
mode = "test"
|
mode = "test"
|
||||||
hint = """
|
hint = """
|
||||||
In Rust, there are two ways to define a Vector.
|
In Rust, there are two ways to define a Vector.
|
||||||
|
@ -256,8 +256,8 @@ of the Rust book to learn more.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "vec2"
|
name = "vecs2"
|
||||||
path = "exercises/collections/vec2.rs"
|
path = "exercises/vecs/vecs2.rs"
|
||||||
mode = "test"
|
mode = "test"
|
||||||
hint = """
|
hint = """
|
||||||
Hint 1: `i` is each element from the Vec as they are being iterated. Can you try
|
Hint 1: `i` is each element from the Vec as they are being iterated. Can you try
|
||||||
|
|
Loading…
Reference in a new issue