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 getSum = function(num) { | |
return num + num; | |
} | |
getSum(9); |
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 addNum = getSum; | |
addNum(9); |
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
function a(x) { | |
return x * 2; | |
} | |
function b(x) { | |
return x + 1; | |
} | |
function c(x) { | |
return x * 3; |
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
function isLarge(value) { | |
return value > 10; | |
} | |
const dataArray = [10, 11, 12, 3, 4]; | |
const filteredArray = dataArray.filter(isLarge); | |
console.log(filteredArray); // [11, 12] |
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
function squareRoot(value) { | |
return Math.sqrt(value) | |
} | |
const dataArray = [4, 9, 16]; | |
const mappedArray = dataArray.map(squareRoot); | |
console.log(mappedArray); // [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
let data = [1, 2, 3, 4, 4]; | |
data[4] = 5; | |
console.log(data); // [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 names = ["Alex", "Victor", "John", "Linda"] | |
const newNamesArray = names.slice(1, 3) // ["Victor", "John"] |
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 employee = { | |
name: "Victor", | |
designation: "Writer", | |
address: { | |
city: "Lagos" | |
} | |
}; | |
Object.freeze(employee); |
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
// Function to filter an array; return greater than 5 numbers | |
const filterArray = (array) => { | |
let filteredArray = []; | |
for(let i = 0; i < array.length; i++) { | |
if(array[i] > 5) { | |
filteredArray.push(array[i]); | |
} | |
} | |
return filteredArray; |
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
// Filter method to give us a new array | |
const filterArray = array => array.filter(x => x > 5); | |
const array = [1, 2, 3, 4, 5, 6, 7, 8]; | |
console.log(filterArray(array)); // [6, 7, 8] |