This file contains 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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var newArray = []; | |
for (var i = 0; i < array.length; i++) { | |
newArray.push(array[i] * 2); | |
} |
This file contains 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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var newArray = []; | |
array.forEach(function (item) { | |
newArray.push(item * 2); | |
}); |
This file contains 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 array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
const newArray = array.map(function (item) { | |
return item * 2; | |
}); |
This file contains 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 array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
const newArray = array.map(item => item * 2); |
This file contains 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
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var newArray = []; | |
for (var i = 0; i < array.length; i++) { | |
if (array[i] % 2 == 0) { | |
newArray.push(array[i] * 2); | |
} | |
} |
This file contains 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 array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
const newArray = array | |
.filter(item => item % 2 == 0) | |
.map(item => item * 2); |
This file contains 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
// the array | |
const array = [ | |
{ value: 1 }, | |
{ value: 2 }, | |
{ value: 3 }, | |
{ value: 4 }, | |
{ value: 5 }, | |
{ value: 6 }, | |
{ value: 7 }, | |
{ value: 8 }, |
This file contains 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 array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
var sum = array.reduce((result, value) => result + value); |
This file contains 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 array = [1, 2, 2, 3, 4, 2, 5, 6, 7, 4, 8, 9, 10]; | |
const distinctArray = array.reduce((final, current) => final.indexOf(current) > -1 ? final : final.concat(current), []); |
This file contains 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
// mocked stuff | |
const stringTemplate = 'I’m sorry, {astronautName}. I’m afraid I can’t do that. This mission is too important for me to allow you to {unwantedThing} it.'; | |
const values = { | |
astronautName: 'Dave', | |
unwantedThing: 'jeopardize' | |
}; | |
// original function | |
function parseTemplate(stringTemplate, values) { |
OlderNewer