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

[Term Entry] Swift dictionary.mapValues() #5212

Conversation

Great-Visions-Code
Copy link
Contributor

Description

  • Add .mapValues() term entry for Swift

Issue Solved

Type of Change

  • Adding a new entry

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • I have linked any issues that are relevant to this PR in the Issues Solved section.

@cigar-galaxy82 cigar-galaxy82 self-assigned this Sep 12, 2024
@cigar-galaxy82 cigar-galaxy82 added swift Swift entries new entry New entry or entries status: under review Issue or PR is currently being reviewed labels Sep 23, 2024
- 'paths/build-ios-apps-with-swiftui'
---

In Swift, the `mapValues()` method is used to transform the values of a dictionary while keeping the keys unchanged. This method is part of the `Dictionary` structure and is useful for modifying or mapping only the values without altering the keys.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In Swift, the `mapValues()` method is used to transform the values of a dictionary while keeping the keys unchanged. This method is part of the `Dictionary` structure and is useful for modifying or mapping only the values without altering the keys.
In Swift, the **`mapValues()`** method is used to transform the values of a dictionary while keeping the keys unchanged. This method is part of the [Dictionary](https://www.codecademy.com/resources/docs/swift/dictionaries) structure and is useful for modifying or mapping only the values without altering the keys.


## Syntax

```swift
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```swift
```pseudo

Comment on lines 28 to 30
The result of `mapValues()` is a new dictionary with the same keys, but the values are transformed based on the provided closure.

> **Note:** `mapValues()` does not modify the original dictionary; instead, it returns a new dictionary with the transformed values.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The result of `mapValues()` is a new dictionary with the same keys, but the values are transformed based on the provided closure.
> **Note:** `mapValues()` does not modify the original dictionary; instead, it returns a new dictionary with the transformed values.
> **Note:** `mapValues()` does not modify the original dictionary but returns a new dictionary with the same keys and values that are transformed based on the provided closure.

Comment on lines 24 to 26
- `dictionaryName`: The instance of a `Dictionary` whose values you want to transform.
- The `mapValues` method returns a new dictionary with the same keys, but with the values transformed based on the provided closure.
- `transformation`: A closure that defines how each value in the dictionary should be transformed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `dictionaryName`: The instance of a `Dictionary` whose values you want to transform.
- The `mapValues` method returns a new dictionary with the same keys, but with the values transformed based on the provided closure.
- `transformation`: A closure that defines how each value in the dictionary should be transformed.
- `dictionaryName`: The instance of a `Dictionary` whose values are transformed.
- `mapValues`: The method returns a new dictionary with the same keys, but with the values transformed based on the provided closure.
- `transformation`: A closure that defines how each value in the dictionary should be transformed.

- The `mapValues` method returns a new dictionary with the same keys, but with the values transformed based on the provided closure.
- `transformation`: A closure that defines how each value in the dictionary should be transformed.

The result of `mapValues()` is a new dictionary with the same keys, but the values are transformed based on the provided closure.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The result of `mapValues()` is a new dictionary with the same keys, but the values are transformed based on the provided closure.
The `mapValues()` function return a new dictionary with the same keys, but the values are transformed based on the provided closure.


## Example

In the following example, the `mapValues()` method is used to increase each student's grade by 10 points in the `studentGrades` dictionary:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the following example, the `mapValues()` method is used to increase each student's grade by 10 points in the `studentGrades` dictionary:
In the following example, the `mapValues()` method is used to increase each student's grade by `10` points while keeping the keys unchanged in the `studentGrades` dictionary:

@cigar-galaxy82
Copy link
Collaborator

Hi @Great-Visions-Code thank you for contributing to Codecademy docs, I have suggested a few changes please modify them.

@cigar-galaxy82
Copy link
Collaborator

Hi, @Great-Visions-Code thank you for contributing to Codecademy docs, I have suggested a few changes please modify them.

@Great-Visions-Code
Copy link
Contributor Author

@cigar-galaxy82 I have made the suggested changes. Please let me know if anything else is needed. Thank you,

minor changes
Copy link
Collaborator

@mamtawardhani mamtawardhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing @Great-Visions-Code 😄

The entry is ready to be merged! 🚀

@mamtawardhani mamtawardhani removed the status: under review Issue or PR is currently being reviewed label Oct 7, 2024
@mamtawardhani mamtawardhani merged commit 629e94b into Codecademy:main Oct 7, 2024
6 checks passed
Copy link

github-actions bot commented Oct 7, 2024

👋 @Great-Visions-Code
You have contributed to Codecademy Docs, and we would like to know more about you and your experience.
Please take a minute to fill out this four question survey to help us better understand Docs contributions and how we can improve the experience for you and our learners.
Thank you for your help!

🎉 Your contribution(s) can be seen here:

https://www.codecademy.com/resources/docs/swift/dictionaries/mapValues

Please note it may take a little while for changes to become visible.
If you're appearing as anonymous and want to be credited, see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Term Entry] Swift dictionaries mapValues()
3 participants