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

Destructuring assignment #143

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# Destructuring assignment
# 解構賦值

We have an object:
我們有個物件:

```js
let user = {
Expand All @@ -13,18 +13,18 @@ let user = {
};
```

Write the destructuring assignment that reads:
閱讀以下內容,撰寫解構賦值:

- `name` property into the variable `name`.
- `years` property into the variable `age`.
- `isAdmin` property into the variable `isAdmin` (false, if no such property)
- `name` 屬性變成變數 `name`.
- `years` 屬性變成變數 `age`.
- `isAdmin` 屬性變成變數 `isAdmin` (false, 如果沒有屬性)

Here's an example of the values after your assignment:
這是值在你指派之後的範例程式碼片段:

```js
let user = { name: "John", years: 30 };

// your code to the left side:
// 你的程式碼會在左側:
// ... = user

alert( name ); // John
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 5

---

# The maximal salary
# 最高薪水

There is a `salaries` object:
這是一個 `salaries` 物件:

```js
let salaries = {
Expand All @@ -14,9 +14,9 @@ let salaries = {
};
```

Create the function `topSalary(salaries)` that returns the name of the top-paid person.
建立函式 `topSalary(salaries)` ,傳回薪水最高的人名。

- If `salaries` is empty, it should return `null`.
- If there are multiple top-paid persons, return any of them.
- 如果 `salaries` 是空的,那應該傳回 `null`
- 如果薪水最高的人有多個,傳回他們任意一個即可。

P.S. Use `Object.entries` and destructuring to iterate over key/value pairs.
備註:使用 `Object.entries` 並在迭代全部鍵/值組合處解構。
Loading