Skip to content

Commit f1b7777

Browse files
authored
Merge branch 'main' into byteswap
2 parents abc0c94 + 95f0e9a commit f1b7777

File tree

18 files changed

+1427
-9
lines changed

18 files changed

+1427
-9
lines changed

CONTRIBUTING.md

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,6 @@ To link your Codecademy user profile to GitHub:
133133
- Typos/bugs
134134
- Plagiarism
135135

136-
## What is the policy for using generative AI?
137-
138-
We will not accept entries that were exclusively generated through an AI tool. We have this policy because:
139-
140-
- AI-generated content is often confidently incorrect, leading to the spread of inaccurate or misleading information.
141-
- We provide authorship credit for submissions, and to submit AI-generated work under one's own name would be a violation of our plagiarism policy.
142-
- Docs is an educational space for people to learn how to write effective technical documentation. Using generative AI, at this point, negatively impacts that desired learning goal.
143-
144136
## How do we update a PR branch?
145137

146138
To keep your PR branch up to date, navigate to the branch on your fork. Then press `Fetch upstream` and `Fetch and merge`.
@@ -158,6 +150,60 @@ git rebase upstream main
158150
git push
159151
```
160152

153+
## Can I use AI tools when contributing?
154+
155+
Yes! You can use AI tools to help create our Docs entries. [Codecademy Docs](https://github.com/Codecademy/docs) is an open-source project designed to help you learn how to contribute to open source, collaborate with the community, and use GitHub. It’s not meant to test whether you can write perfect technical content on your own.
156+
157+
AI can assist you with drafting, rewriting, or structuring content. However, you are responsible for ensuring your work meets Codecademy’s quality and [style standards](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md). AI is a tool to help you, but it doesn't replace the standards we expect.
158+
159+
You're accountable for all AI-assisted content.
160+
161+
You may use AI to generate drafts or refine your writing, but you must personally review and improve all AI-assisted content before submitting. Every entry must follow:
162+
163+
- [The Docs entry template](https://github.com/Codecademy/docs/blob/main/documentation/term-entry-template.md)
164+
- [Our content standards](https://github.com/Codecademy/docs/blob/main/documentation/content-standards.md)
165+
- [Our style guidelines](https://github.com/Codecademy/docs/blob/main/documentation/style-guide.md)
166+
167+
> **Note:** If we detect plagiarism in your entry, you will be banned from contributing to Docs.
168+
169+
## What you need to verify
170+
171+
Even if AI produced the initial version of the entry, you must ensure that:
172+
173+
- The content is accurate, technically correct, and fact-checked.
174+
- All explanations are clear and aligned with Codecademy Docs writing style.
175+
- Code examples compile or run correctly when required.
176+
- The text is not plagiarized or copied from external sources.
177+
- The final entry sounds intentional, not generic, or filled with filler text.
178+
- The formatting follows the Docs template exactly.
179+
180+
AI output often contains vague definitions, hallucinated details, or inconsistent explanations. You must correct and refine these issues before submitting a pull request.
181+
182+
## Quality standards apply to all entries
183+
184+
Regardless of how you created the content, every entry must:
185+
186+
- Use original wording.
187+
- Include accurate definitions and examples.
188+
- Follow the required structure, headings, and formatting.
189+
- Maintain a simple, educational, and neutral tone.
190+
- Avoid unnecessary complexity or overly broad explanations.
191+
- Fit the scope of a Docs reference entry.
192+
193+
> **Note:** If your submission doesn't meet these standards, we'll ask you to revise it.
194+
195+
## What happens during review?
196+
197+
Maintainers (Codecademy’s content team who reviews all contributions) may request edits on any AI-assisted entry if it:
198+
199+
- Does not follow our template.
200+
- Contains unclear, generic, or contradictory information.
201+
- Includes mistakes or technical inaccuracies.
202+
- Appears copied.
203+
- Lacks the clarity expected from Docs entries.
204+
205+
You're expected to respond to feedback and make the requested improvements within 1 week, or your PR will be closed due to inactivity.
206+
161207
Remember, if you ever have any questions at all, we're always here to help in the [Codecademy Forums](https://community.codecademy.com/).
162208

163209
If you find any bugs or errors in the content, feel free to file an issue [here](https://github.com/Codecademy/docs/issues/new?assignees=Name+here&labels=bug&template=bug_reports.yml&title=%5BBug%2FError%5D+Subject%3A+Entry+Name)! 🖖

bin/concept-of-the-week.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
content/kotlin/concepts/strings/strings.md
1+
content/kotlin/concepts/classes/classes.md
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
Title: 'Acosh()'
3+
Description: 'Returns the inverse hyperbolic cosine of a specified number.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Web Development'
7+
Tags:
8+
- 'Functions'
9+
- 'Math'
10+
- 'Methods'
11+
- 'Numbers'
12+
CatalogContent:
13+
- 'learn-c-sharp'
14+
- 'paths/computer-science'
15+
---
16+
17+
The **`Math.Acosh()`** method returns the inverse hyperbolic cosine (also known as hyperbolic arccosine) of a specified number. It computes the value whose hyperbolic cosine equals the given number.
18+
19+
## Syntax
20+
21+
```pseudo
22+
Math.Acosh(number);
23+
```
24+
25+
**Parameters:**
26+
27+
- `number`: A double-precision floating-point value greater than or equal to `1`, for which to compute the inverse hyperbolic cosine.
28+
29+
**Return value:**
30+
31+
- The inverse hyperbolic cosine of the specified number in radians as a `double`.
32+
- `NaN` if the input is less than `1` or `NaN`.
33+
34+
## Example: Basic Usage of `Math.Acosh()`
35+
36+
This example calculates the inverse hyperbolic cosine of a number using `Math.Acosh()` and displays the result in radians:
37+
38+
```cs
39+
using System;
40+
41+
public class Example
42+
{
43+
public static void Main()
44+
{
45+
double number = 1.5;
46+
double result = Math.Acosh(number);
47+
Console.WriteLine($"Math.Acosh({number}) = {result} radians");
48+
}
49+
}
50+
```
51+
52+
This example outputs the following:
53+
54+
```shell
55+
Math.Acosh(1.5) = 0.9624236501192069 radians
56+
```
57+
58+
## Codebyte Example
59+
60+
In this example, the `Math.Acosh()` method is used to calculate the inverse hyperbolic cosine of a specified number in radians and degrees:
61+
62+
```codebyte/csharp
63+
using System;
64+
65+
public class Example {
66+
public static void Main() {
67+
double number = 100.0;
68+
69+
// Calculate Acosh in radians
70+
double resultRadians = Math.Acosh(number);
71+
72+
// Convert radians to degrees
73+
double resultDegrees = resultRadians * (180.0 / Math.PI);
74+
75+
// Display results
76+
Console.WriteLine($"Math.Acosh({number}) = {resultRadians} radians");
77+
Console.WriteLine($"Math.Acosh({number}) = {resultDegrees} degrees");
78+
}
79+
}
80+
```
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
Title: 'Clamp()'
3+
Description: 'Restricts a value to lie within a specified minimum and maximum range.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Arithmetic'
9+
- 'Method'
10+
- 'Numbers'
11+
CatalogContent:
12+
- 'learn-c-sharp'
13+
- 'paths/computer-science'
14+
---
15+
16+
The **`Math.Clamp()`** is a static method that returns the value clamped to the inclusive range of min and max.
17+
18+
> **Note:** The static method `Math.Clamp()` was introduced in .NET Core 2.0.
19+
20+
## Syntax
21+
22+
```pseudo
23+
Math.Clamp(value, min, max);
24+
```
25+
26+
**Parameters:**
27+
28+
- `value`: The value to be clamped.
29+
- `min`: The lower bound of the result.
30+
- `max`: The upper bound of the result.
31+
32+
**Return value:**
33+
34+
Returns the value clamped to the inclusive range of min and max.
35+
36+
> **Note:** If value is less than `min`, it returns `min`; if greater than `max`, it returns `max`; otherwise, it returns `value`.
37+
38+
## Example
39+
40+
The following example demonstrates the `Math.Clamp()` method and writes the result to the console.
41+
42+
```cs
43+
using System;
44+
45+
class Program
46+
{
47+
static void Main()
48+
{
49+
int min = 2;
50+
int max = 8;
51+
52+
int result = Math.Clamp(10, min, max);
53+
Console.WriteLine(result);
54+
}
55+
}
56+
```
57+
58+
The example will result in the following output:
59+
60+
```shell
61+
8
62+
```
63+
64+
## Codebyte Example
65+
66+
In this example, a random list of decimal numbers is generated, and `Math.Clamp()` ensures that all stored values stay within the defined range:
67+
68+
```codebyte/csharp
69+
using System;
70+
71+
class Example
72+
{
73+
static void Main()
74+
{
75+
Random random = new Random();
76+
double[] nums = new double[10];
77+
int min = 1;
78+
int max = 50;
79+
80+
for (int i = 0; i < nums.Length; i++)
81+
{
82+
double range = random.NextDouble() * 70 - 10; // -10 to 60
83+
double limit = Math.Clamp(range, min, max);
84+
nums[i] = limit;
85+
}
86+
87+
foreach (double num in nums)
88+
{
89+
Console.WriteLine(num);
90+
}
91+
}
92+
}
93+
```
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
Title: '.at()'
3+
Description: 'Accesses an element at a specified index in a deque with bounds checking.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Game Development'
7+
Tags:
8+
- 'Containers'
9+
- 'Deques'
10+
- 'Methods'
11+
- 'STL'
12+
CatalogContent:
13+
- 'learn-c-plus-plus'
14+
- 'paths/computer-science'
15+
---
16+
17+
The C++ **`.at()`** [function](https://www.codecademy.com/resources/docs/cpp/functions) accesses the element at a given index in a deque while performing bounds checking. If the index is out of range, the function throws an `std::out_of_range` [exception](https://www.codecademy.com/resources/docs/cpp/exceptions). This makes it a safer alternative to the subscript operator `[]`, which offers no safety checks.
18+
19+
## Syntax
20+
21+
```pseudo
22+
deque.at(pos)
23+
```
24+
25+
**Parameters:**
26+
27+
- `pos`: A zero-based index of the element to access. Must be within the valid range of the deque.
28+
29+
**Return value:**
30+
31+
Returns a reference to the element at the given position.
32+
33+
**Exceptions:**
34+
35+
Throws `std::out_of_range` if `pos` is invalid.
36+
37+
## Example 1: Accessing Elements Safely
38+
39+
In this example, `.at()` retrieves elements from valid positions in the deque:
40+
41+
```cpp
42+
#include <iostream>
43+
#include <deque>
44+
using namespace std;
45+
46+
int main() {
47+
deque<int> numbers = {10, 20, 30, 40};
48+
49+
cout << "Element at index 2: " << numbers.at(2) << endl;
50+
cout << "Element at index 0: " << numbers.at(0) << endl;
51+
52+
return 0;
53+
}
54+
```
55+
56+
The output of this code is:
57+
58+
```shell
59+
Element at index 2: 30
60+
Element at index 0: 10
61+
```
62+
63+
The `.at()` function returns elements at positions 2 and 0 with built-in bounds checking.
64+
65+
## Example 2: Handling Out-of-Range Access
66+
67+
In this example, accessing index 5 triggers an exception because the index is outside the deque's valid range:
68+
69+
```cpp
70+
#include <iostream>
71+
#include <deque>
72+
using namespace std;
73+
74+
int main() {
75+
deque<string> names = {"Ava", "Mira", "Leo"};
76+
77+
try {
78+
cout << names.at(5) << endl;
79+
} catch (const out_of_range& e) {
80+
cout << "Error: " << e.what() << endl;
81+
}
82+
83+
return 0;
84+
}
85+
```
86+
87+
The output of this code is:
88+
89+
```shell
90+
Error: deque::_M_range_check: __n (which is 5)>= this->size() (which is 3)
91+
```
92+
93+
## Codebyte Example
94+
95+
This example demonstrates safe element access and shows how `.at()` behaves when an invalid index is used:
96+
97+
```codebyte/cpp
98+
#include <iostream>
99+
#include <deque>
100+
using namespace std;
101+
102+
int main() {
103+
deque<char> letters = {'A', 'B', 'C', 'D'};
104+
105+
cout << "First element: " << letters.at(0) << endl;
106+
cout << "Third element: " << letters.at(2) << endl;
107+
108+
try {
109+
cout << letters.at(10) << endl;
110+
} catch (const out_of_range& e) {
111+
cout << "Caught exception: " << e.what() << endl;
112+
}
113+
114+
return 0;
115+
}
116+
```
117+
118+
## Frequently Asked Questions
119+
120+
### 1. What is the use of deque in C++?
121+
122+
A deque (double-ended queue) stores elements in a dynamic sequence where insertions and deletions at both the front and back are efficient. It supports random access like a vector but provides faster operations at the beginning of the structure.
123+
124+
### 2. What is a std::deque?
125+
126+
`std::deque` is a standard container that provides a dynamic array-like structure with fast operations at both ends. It is implemented as segmented memory blocks, which allows it to grow without relocating all elements like a vector.
127+
128+
### 3. How to check if deque is empty in C++?
129+
130+
A deque can be checked for emptiness using the `.empty()` method, which returns `true` if it contains no elements and `false` otherwise. This check is constant time and works for all standard containers.

0 commit comments

Comments
 (0)