From f943014e25adcc97d36f1193fb342be8af4215c1 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 10 Feb 2021 04:45:58 +0000 Subject: [PATCH] safeguarding --- subjects/capitalizing/README.md | 12 ++++++------ subjects/hashing/README.md | 24 ++++++++++++++---------- subjects/string_permutation/README.md | 13 +++++++++++-- subjects/to_url/README.md | 4 +++- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/subjects/capitalizing/README.md b/subjects/capitalizing/README.md index 34ad3196..ec0afadd 100644 --- a/subjects/capitalizing/README.md +++ b/subjects/capitalizing/README.md @@ -2,11 +2,11 @@ ### Instructions -Complete the `capitalize_first` function that turns the first letter of a string uppercase. +Complete the `capitalize_first` **function** which turns the first letter of a string to uppercase. -Complete the `title_case` function that turns the first letter of each word in a string uppercase. +Complete the `title_case` **function** which turns the first letter of each word in a string to uppercase. -Complete the `change_case` function that turns the uppercase letters of a string into lowercase and the lowercase letters into uppercase. +Complete the `change_case` **function** which turns the uppercase letters of a string into lowercase and the lowercase letters into uppercase. ### Expected Functions @@ -23,10 +23,10 @@ pub fn change_case(input: &str) -> String { ### Usage -Here is a program to test your function. +Here is a program to test your functions. ```rust -use capitalizing::capitalizing; +use capitalizing::*capitalizing*; fn main() { println!("{}", capitalize_first("joe is missing")); @@ -37,7 +37,7 @@ fn main() { And its output -```console +```consoole student@ubuntu:~/[[ROOT]]/test$ cargo run Joe is missing Jill Is Leaving A diff --git a/subjects/hashing/README.md b/subjects/hashing/README.md index a82d9732..7bcb3106 100644 --- a/subjects/hashing/README.md +++ b/subjects/hashing/README.md @@ -2,25 +2,29 @@ ### Instructions -Given a list of integers (Vec) write three functions +Given a list of integers (Vec) write three **functions**. -Write a function called `mean` that calculates the `mean` (the average value) of all the values in the list +Write a **function** called `mean` that calculates the `mean` (the average value) of all the values in the list. -Write a function called `median` that calculates the `median` (for a sorted list is the value in the middle) +Write a **function** called `median` that calculates the `median` (for a sorted list, it is the value in the middle). -Write a function called `mode` that calculates the mode (the value -that appears more often) +Write a **function** called `mode` that calculates the mode (the value +that appears more often). + +### Notions + +[hash maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) ### Expected Functions ```rust -fn mean(list: &Vec) -> f64 { +pub fn mean(list: &Vec) -> f64 { } -fn median(list: &Vec) -> i32 { +pub fn median(list: &Vec) -> i32 { } -fn mode(list: &Vec) -> i32 { +pub fn mode(list: &Vec) -> i32 { } ``` @@ -29,7 +33,7 @@ fn mode(list: &Vec) -> i32 { Here is a program to test your function. ```rust -use hashing; +use hashing::*; fn main() { println!("Hello, world!"); @@ -40,7 +44,7 @@ fn main() { } ``` -And its output +And its output; ```console student@ubuntu:~/[[ROOT]]/test$ cargo run diff --git a/subjects/string_permutation/README.md b/subjects/string_permutation/README.md index d33f0222..0fda4ea5 100644 --- a/subjects/string_permutation/README.md +++ b/subjects/string_permutation/README.md @@ -2,12 +2,19 @@ ### Instructions -Define the function `is_permutation` that returns true if the string `s1` is a permutation of `s2`, otherwise it returns false `s1` is a permutation of `s2` if all the elements in `s1` appear the same number of times in `s2` and all the characters in `s1` appear in `s2` even if in different order) +Define the **function** `is_permutation` that returns true if: + +- the string `s1` is a permutation of `s2`, otherwise it returns false. +- `s1` is a permutation of `s2` if all the elements in `s1` appear the same number of times in `s2` and all the characters in `s1` appear in `s2` even if they are in different order. + +### Notions + +[hash maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) ### Expected Function ```rust -fn is_permutation(s1: &str, s2: &str) -> bool { +pub fn is_permutation(s1: &str, s2: &str) -> bool { } ``` @@ -16,6 +23,8 @@ fn is_permutation(s1: &str, s2: &str) -> bool { Here is a program to test your function. ```rust +use string_permutation::*; + fn main() { let word = "thought"; let word1 = "thougth"; diff --git a/subjects/to_url/README.md b/subjects/to_url/README.md index f328153d..828cae37 100644 --- a/subjects/to_url/README.md +++ b/subjects/to_url/README.md @@ -2,7 +2,7 @@ ### Instructions -Define a function called `to_url` that takes a string and substitutes every white-space with '%20' +Define a **function** called `to_url` that takes a string and substitutes every white-space with '%20'. ### Expected Function @@ -16,6 +16,8 @@ pub fn to_url(s: &str) -> String { Here is a program to test your function. ```rust +use to_url::*; + fn main() { let s = "Hello, world!"; println!("{} to be use as an url is {}", s, to_url(s));