This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const elements = [1, 2, 3, 4]; | |
| const appendedElements = [...elements, 5]; // [1, 2, 3, 4, 5] | |
| const prependedElements = [0, ...appendedElements]; // [0, 1, 2, 3, 4, 5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const elements = [1, 2, 3, 4, 5]; | |
| // remove last element | |
| const lastElementRemoved = elements.slice(0, 4); // [1, 2, 3, 4] | |
| // remove first element | |
| const firstElementRemoved = elements.slice(1); // [2, 3, 4, 5] | |
| // remove first and last element (chaining) | |
| const firstAndLastElementRemoved = elements.slice(0, 4).slice(1) // [2, 3, 4] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const elements = [1, 2, 3, 4, 5]; | |
| const indexToRemove = 2; // starts from 0, so it targets the third element | |
| const nextElements = [ | |
| ...elements.slice(0, indexToRemove), | |
| ...elements.slice(indexToRemove + 1) | |
| ]; // [1, 2, 4, 5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const users = [ | |
| { | |
| name: "Jane", | |
| balance: 100.00 | |
| }, | |
| { | |
| name: "John", | |
| balance: 55.25 | |
| } | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const users = [ | |
| { | |
| name: "Jane", | |
| balance: 100, | |
| }, | |
| { | |
| name: "John", | |
| balance: 75, | |
| }, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const users = [ | |
| { | |
| name: "Jane", | |
| balance: 100, | |
| }, | |
| { | |
| name: "John", | |
| balance: 75, | |
| }, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const elements = [1, 2, 3, 1, 4, 5, 2, 6, 6]; | |
| const isUnique = (value, index, array) => array.indexOf(value) === index; | |
| const nextElements = elements.filter(isUnique); // [1, 2, 3, 4, 5, 6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const elements = [1, 2, 3, 4, 5]; | |
| const nextElements = elements.reduce( | |
| (previousValue, currentValue) => previousValue + currentValue, | |
| 0 | |
| ); // 15 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const elements = [1, 2, 3, 4, 5]; | |
| const sum = (a, b) => a + b; | |
| const nextElements = elements.reduce(sum, 0); // 15 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const users = [ | |
| { | |
| name: "Jane", | |
| balance: 100, | |
| }, | |
| { | |
| name: "John", | |
| balance: 75, | |
| }, | |
| { |