Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(curriculum): description improvement case converter program #54051

Merged
merged 31 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d35ce8d
description improvement
larymak Mar 11, 2024
60dce15
Merge branch 'freeCodeCamp:main' into feat/case-converter-program
larymak Mar 22, 2024
873b86b
suggestion resolved
larymak Mar 25, 2024
c6396b8
case converter description improvement
larymak Mar 28, 2024
b7e83da
description improvement
larymak Mar 28, 2024
b7aefe4
Revert "case converter description improvement"
larymak Mar 28, 2024
c64f2a0
Merge branch 'feat/case-converter-program' of https://github.com/free…
larymak Mar 28, 2024
4980daf
case converter suggestion implemetation
larymak Mar 28, 2024
aec1314
case converter description improvement
larymak Apr 3, 2024
514c747
Merge branch 'main' into feat/case-converter-program
larymak Apr 3, 2024
406a7d6
case converter suggestion improvement
larymak Apr 9, 2024
edccf76
Merge branch 'freeCodeCamp:feat/case-converter-program' into feat/cas…
larymak Apr 9, 2024
531d952
case converter suggestion improvement
larymak Apr 9, 2024
f0b6ab9
Merge branch 'freeCodeCamp:feat/case-converter-program' into feat/cas…
larymak Apr 9, 2024
059e182
case converter suggestion implementation
larymak Apr 16, 2024
065c9cb
case converter suggestion implementation
larymak Apr 17, 2024
ca43574
case converter suggestion implementation
larymak Apr 26, 2024
60f975b
case converter suggestion implementation
larymak May 1, 2024
4947e82
case converter description improvement
larymak May 24, 2024
8d4bc4b
case converter description improvement
larymak May 29, 2024
4e3c0ab
case converter step update
larymak May 29, 2024
93eeddb
case converter suggestion implementation
larymak May 30, 2024
3ae31a1
Merge branch 'main' of https://github.com/freeCodeCamp/freeCodeCamp i…
larymak Jun 5, 2024
c8dee56
Merge branch 'main' of https://github.com/freeCodeCamp/freeCodeCamp i…
larymak Jun 6, 2024
2b10657
Merge branch 'main' of https://github.com/freeCodeCamp/freeCodeCamp i…
larymak Jun 7, 2024
8849253
update tests for step 13
larymak Jun 11, 2024
5b17c95
Merge branch 'main' of https://github.com/freeCodeCamp/freeCodeCamp i…
larymak Jun 11, 2024
9eea6f7
Merge branch 'freeCodeCamp:feat/case-converter-program' into feat/cas…
larymak Jun 11, 2024
9b6887c
case converter suggestion implementation
larymak Jun 11, 2024
e569589
Merge branch 'freeCodeCamp:feat/case-converter-program' into feat/cas…
larymak Jun 11, 2024
8a4c8a0
i18n sync
Dario-DC Jun 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
larymak marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dashedName: step-3

# --description--

With the empty list in place, iterate through the input string and convert it into snake case using a `for` loop.
With the empty list in place, now you can start iterating through the input string and convert it into snake case.

Inside the function, below the list you just created, add a `for` loop to iterate through the `pascal_or_camel_cased_string`. Make sure to name the target variable `char`. For now, add a `pass` statement as a placeholder in the loop body.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ dashedName: step-8

# --description--

By this point, the variable `snake_cased_char_list` holds the list of converted characters. To combine these characters into a single string, you should utilize the `join()` method.
By this point, the variable `snake_cased_char_list` holds the list of converted characters. To combine these characters into a single string, you can utilize the `.join()` method.

The `join` method works by concatenating each element of the list into a string, separated by a designated string, known as the separator.
larymak marked this conversation as resolved.
Show resolved Hide resolved

```py
# join all characters using empty string
result_string = ''.join(characters)
```

larymak marked this conversation as resolved.
Show resolved Hide resolved
Now, right after the `for` loop, use the `join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`.
The above example joins together the elements of the `characters` list into a single string where each element is concatenated together without any separator between them.
larymak marked this conversation as resolved.
Show resolved Hide resolved

Now, right after the `for` loop, use the `.join()` method to join the elements in `snake_cased_char_list` using an empty string as the separator. Assign the result to a new variable named `snake_cased_string`.


# --hints--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ In pascal case, strings begin with a capital letter. After converting all the ch
The easiest way to fix this is by using the `.strip()` string method and passing an underscore to the method as argument. This will remove any leading or trailing underscores from the string. For example:
larymak marked this conversation as resolved.
Show resolved Hide resolved

```py
# String with underscores
original_string = "_example_string_"

# Using .strip() method to remove underscores
clean_string = original_string.strip('_')
```

Add a new variable named `clean_snake_cased_string` and assign the result of the `.strip()` method applied to `snake_cased_string` to it.
From the example above, the `strip()` method is applied to `original_string`. This removes any leading and trailing characters specified within the parentheses, in this case, underscores. The result of the would be the string `'example_string'`.

Declare a new variable named `clean_snake_cased_string` and assign the result of the `.strip()` method applied to `snake_cased_string` , passing `'_'` as the argument to the method.
larymak marked this conversation as resolved.
Show resolved Hide resolved

# --hints--

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dashedName: step-12

Inside the `main()` function, replace the `pass` statement, with a call to the `convert_to_snake_case()` function, passing the string `'aLongAndComplexString'` as input.

To display the output, enclose the function call within the `print()` function.
To display the output, pass the function call as the argument to the `print()` function.

# --hints--

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ dashedName: step-17

# --description--

You will need to to convert uppercase characters to lowercase and add an underscore before them.
You will need to convert uppercase characters to lowercase and add an underscore before them. Before proceeding, join all the elements of the list `snake_cased_char_list` into a single string using an empty string `''` as the separator.
larymak marked this conversation as resolved.
Show resolved Hide resolved

Within the empty list, implement an `if` statement to check whether the character is uppercase. If it is, append `'_' + char.lower()` to the list.
The using the return statement, return an empty string `''` joined with `snake_cased_char_list` as the argument, and strip any leading or trailing underscores from the result.
larymak marked this conversation as resolved.
Show resolved Hide resolved
larymak marked this conversation as resolved.
Show resolved Hide resolved

# --hints--

You should add `'_' + char.lower() if char.isupper()` within the square braces of `snake_cased_char_list`.
You should return an empty string `''` joined with `snake_cased_char_list`, and ensure to strip any leading or trailing underscores. Ensure the indentation is correct.
larymak marked this conversation as resolved.
Show resolved Hide resolved

```js
const transformedCode = code.replace(/\r/g, "");
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
const { function_body } = convert_to_snake_case;

assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*("|')_\1\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*\]/);
assert.match(function_body, /return\s*''\.join\(snake_cased_char_list\)\.strip\('_'\)/);
larymak marked this conversation as resolved.
Show resolved Hide resolved
larymak marked this conversation as resolved.
Show resolved Hide resolved
```

# --seed--
Expand All @@ -41,13 +41,10 @@ def convert_to_snake_case(pascal_or_camel_cased_string):

# return clean_snake_cased_string

snake_cased_char_list = []
--fcc-editable-region--
snake_cased_char_list = [

]
--fcc-editable-region--


--fcc-editable-region--

def main():
print(convert_to_snake_case('aLongAndComplexString'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ dashedName: step-18

# --description--

larymak marked this conversation as resolved.
Show resolved Hide resolved
When you start a list comprehension with an `if` statement, Python filters elements based on the condition provided, which means an `else` clause is required to handle the case when the condition is not met.
A list comprehension is a concise way to create lists in Python. It consists of an expression followed by a `for` clause or more `for` or `if` clauses allowing iteration over elements from an iterable and optional transformations or condition.

In this case, an `else` clause is needed to ensure that if the condition specified in the `if` statement is not met, `char` is appended to the list as is.
In this step, you will need to convert the empty list `snake_cased_char_list` into a list where each character from `pascal_or_camel_cased_string` is preceded by an underscore and converted to lowercase.

Add an `else` clause that appends `char` to the list.
Inside the empty list `snake_cased_char_list`, transform each `char` into lowercase and add an underscore before it. Add a `for` loop to iterate over each `char` in `pascal_or_camel_cased_string`.

# --hints--

You should add `else char` after `'_' + char.lower() if char.isupper()` within the square braces of `snake_cased_char_list`.
You should add `for char in pascal_or_camel_cased_string` after `'_' + char.lower()` within the square braces of `snake_cased_char_list`.

```js
const transformedCode = code.replace(/\r/g, "");
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
const { function_body } = convert_to_snake_case;

assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*("|')_\1\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*else\s+char\s*\]/);
assert.match(function_body, /'_'\s*\+\s*char\.lower\(\s*\)\s+for\s+char\s+in\s+pascal_or_camel_cased_string/);
larymak marked this conversation as resolved.
Show resolved Hide resolved
```

# --seed--
Expand All @@ -44,13 +44,9 @@ def convert_to_snake_case(pascal_or_camel_cased_string):
# return clean_snake_cased_string

--fcc-editable-region--
snake_cased_char_list = [
'_' + char.lower() if char.isupper()

]
snake_cased_char_list = []
--fcc-editable-region--


return ''.join(snake_cased_char_list).strip('_')
larymak marked this conversation as resolved.
Show resolved Hide resolved
larymak marked this conversation as resolved.
Show resolved Hide resolved

def main():
print(convert_to_snake_case('aLongAndComplexString'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@ dashedName: step-19

# --description--

larymak marked this conversation as resolved.
Show resolved Hide resolved
The final piece of the puzzle is the input string itself. The list comprehension needs to know about the object it'll iterate upon.
List comprehensions are more than just transformation, they can also filter elements based on conditions using `if` statements. You can add an `if` statement within a list comprehension to filter elements based on a given condition.

In this case, it will iterate upon all the characters of the string, and this can be achieved by making use of a `for` loop.
In the previous step, you generated a list of characters from `pascal_or_camel_cased_string`, with each character converted to lowercase and preceded by an underscore. Now, you need to filter out characters that are not uppercase.

After the `else` clause, add a `for` loop to iterate over the `char` variable in the `pascal_or_camel_cased_string` string.
Inside the list comprehension after the `for` clause, add an `if` statement to check if `char` is uppercase.

# --hints--

You should add `for char in pascal_or_camel_cased_string` after `else char` within the square braces of `snake_cased_char_list`.
You should add `if` statement after the `for` clause within the square braces of `snake_cased_char_list` to check if `char` is uppercase.

```js
({
test: () => {
const transformedCode = code.replace(/\r/g, "");
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
const { function_body } = convert_to_snake_case;
const transformedCode = code.replace(/\r/g, "");
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
const { function_body } = convert_to_snake_case;

assert.match(function_body, / +snake_cased_char_list\s*=\s*\[\s*'_'\s*\+\s*char\.lower\(\s*\)\s+if\s+char\.isupper\(\s*\)\s*else\s*char\s*for\s+char\s+in\s+pascal_or_camel_cased_string\s*\]/);
}
})
assert.match(function_body, /if\s*char\.isupper\(\)/);
larymak marked this conversation as resolved.
Show resolved Hide resolved
```

# --seed--
Expand All @@ -48,14 +44,9 @@ def convert_to_snake_case(pascal_or_camel_cased_string):
# return clean_snake_cased_string

--fcc-editable-region--
snake_cased_char_list = [
'_' + char.lower() if char.isupper()
else char

]
snake_cased_char_list = ['_' + char.lower() for char in pascal_or_camel_cased_string]
larymak marked this conversation as resolved.
Show resolved Hide resolved
--fcc-editable-region--


return ''.join(snake_cased_char_list).strip('_')

def main():
print(convert_to_snake_case('aLongAndComplexString'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@ dashedName: step-20

# --description--

larymak marked this conversation as resolved.
Show resolved Hide resolved
You will still need to join the list elements into a string, strip off any dangling underscores and return the string. Even though you can do that like you did earlier, here is a shorter alternative.
List comprehensions not only have the ability to filter elements based on conditions but also perform different transformations depending on the condition. This can be achieved by the use of an `if/else` statement within a list comprehension.

```py
return ''.join(snake_cased_char_list).strip('_')
```
Previously, you filtered out lowercase characters by adding an `if` statement to check if `char` is uppercase. Now, you will extend the comprehension to handle both cases.

Add this line on the same level as the `snake_cased_char_list` variable and inside the `convert_to_snake_case()` function.
Inside the list comprehension, add an `else` clause to ensure that if `char` is not uppercase, it remains unchanged.

# --hints--

You should return `''.join(snake_cased_char_list).strip('_')` at the end of `convert_to_snake_case()` function.
You should add an `else` clause after the `if char.isupper()` statement that ensures `char` is unchanged if it's not uppercase.

```js
({
test: () => {
const transformedCode = code.replace(/\r/g, "");
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
const { function_body } = convert_to_snake_case;
const transformedCode = code.replace(/\r/g, "");
const convert_to_snake_case = __helpers.python.getDef("\n" + transformedCode, "convert_to_snake_case");
const { function_body } = convert_to_snake_case;

assert.match(function_body, / +return\s+('|")\1\.join\(\s*snake_cased_char_list\s*\)\.strip\(\s*("|')_\2\s*\)/);
}
})
assert.match(function_body, /else\s*char/);
```

# --seed--
Expand All @@ -50,15 +44,9 @@ def convert_to_snake_case(pascal_or_camel_cased_string):
# return clean_snake_cased_string

--fcc-editable-region--
snake_cased_char_list = [
'_' + char.lower() if char.isupper()
else char
for char in pascal_or_camel_cased_string
]

snake_cased_char_list = ['_' + char.lower() if char.isupper() for char in pascal_or_camel_cased_string]
larymak marked this conversation as resolved.
Show resolved Hide resolved
--fcc-editable-region--


return ''.join(snake_cased_char_list).strip('_')

def main():
print(convert_to_snake_case('aLongAndComplexString'))
Expand Down
Loading