Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

added code snippet 34 #1

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

Merged
Vasu7389 merged 1 commit into Vasu7389:master from imran120198:imran
Apr 28, 2023
Merged
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
30 changes: 30 additions & 0 deletions README.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1018,3 +1018,33 @@ Since a and b reference the same array, both console.log(a) and console.log(b) w
This is different from the previous example where ... spread operator was used, which created a new array with the same values as the original array instead of referencing the same array.

</details>

<details>
<summary>
<h3>34. What is the output of the following code?</h3>

```jsx
var companies = [
{id: "1", name:"Facebook"},
{id: "2", name:"Apple"},
{id: "3", name:"Google"},
]

companies.sort((a,b) => (a.name > b.name ? -1 : 1))
console.log(companies)

```

</summary>

The output of the code will be:

Answer:

```bash
[ {id: "3", name:"Google"} , {id: "1", name:"Facebook"} , {id: "2", name:"Apple"} ]
```

The comparison function takes two parameters, "a" and "b", which represent two elements being compared in the array. If the "name" property of "a" comes before the "name" property of "b" in alphabetical order, then the function returns -1, which means "a" should come before "b" in the sorted array. Otherwise, if the "name" property of "a" comes after the "name" property of "b" in alphabetical order, then the function returns 1, which means "b" should come before "a" in the sorted array.

</details>

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /