diff --git a/1-js/05-data-types/05-array-methods/8-sort-objects/solution.md b/1-js/05-data-types/05-array-methods/8-sort-objects/solution.md index f5684a6d5..9f1ade707 100644 --- a/1-js/05-data-types/05-array-methods/8-sort-objects/solution.md +++ b/1-js/05-data-types/05-array-methods/8-sort-objects/solution.md @@ -1,5 +1,5 @@ ```js run no-beautify -function sortByName(arr) { +function sortByAge(arr) { arr.sort((a, b) => a.age > b.age ? 1 : -1); } @@ -7,11 +7,12 @@ let john = { name: "John", age: 25 }; let pete = { name: "Pete", age: 30 }; let mary = { name: "Mary", age: 28 }; -let arr = [ john, pete, mary ]; +let arr = [ pete, john, mary ]; -sortByName(arr); +sortByAge(arr); // now sorted is: [john, mary, pete] alert(arr[0].name); // John +alert(arr[1].name); // Mary alert(arr[2].name); // Pete ``` diff --git a/1-js/05-data-types/05-array-methods/8-sort-objects/task.md b/1-js/05-data-types/05-array-methods/8-sort-objects/task.md index fae6bcbe9..9a215c9f4 100644 --- a/1-js/05-data-types/05-array-methods/8-sort-objects/task.md +++ b/1-js/05-data-types/05-array-methods/8-sort-objects/task.md @@ -2,9 +2,9 @@ importance: 5 --- -# Sort objects +# Sort users by age -Write the function `sortByName(users)` that gets an array of objects with the `age` property and sorts them by `age`. +Write the function `sortByAge(users)` that gets an array of objects with the `age` property and sorts them by `age`. For instance: @@ -13,11 +13,12 @@ let john = { name: "John", age: 25 }; let pete = { name: "Pete", age: 30 }; let mary = { name: "Mary", age: 28 }; -let arr = [ john, pete, mary ]; +let arr = [ pete, john, mary ]; -sortByName(arr); +sortByAge(arr); // now: [john, mary, pete] alert(arr[0].name); // John +alert(arr[1].name); // Mary alert(arr[2].name); // Pete ``` diff --git a/2-ui/99-misc/12-mutation-observer/article.md b/10-misc/12-mutation-observer/article.md similarity index 100% rename from 2-ui/99-misc/12-mutation-observer/article.md rename to 10-misc/12-mutation-observer/article.md diff --git a/2-ui/99-misc/index.md b/10-misc/index.md similarity index 100% rename from 2-ui/99-misc/index.md rename to 10-misc/index.md diff --git a/2-ui/1-document/07-modifying-document/article.md b/2-ui/1-document/07-modifying-document/article.md index 22907554f..16aacb456 100644 --- a/2-ui/1-document/07-modifying-document/article.md +++ b/2-ui/1-document/07-modifying-document/article.md @@ -136,7 +136,7 @@ Here's a brief list of methods to insert a node into a parent element (`parentEl ``` To insert `newLi` as the first element, we can do it like this: - + ```js list.insertBefore(newLi, list.firstChild); ``` @@ -335,6 +335,74 @@ An example of copying the message: ``` + +## DocumentFragment [#document-fragment] + +`DocumentFragment` is a special DOM node that serves as a wrapper to pass around groups of nodes. + +We can append other nodes to it, but when we insert it somewhere, then it "disappears", leaving its content inserted instead. + +For example, `getListContent` below generates a fragment with `
  • ` items, that are later inserted into `