Skip to content

Instantly share code, notes, and snippets.

View Vectormike's full-sized avatar
🏠
Working from home

Victor Jonah Vectormike

🏠
Working from home
View GitHub Profile
const getSum = function(num) {
return num + num;
}
getSum(9);
const addNum = getSum;
addNum(9);
function a(x) {
return x * 2;
}
function b(x) {
return x + 1;
}
function c(x) {
return x * 3;
function isLarge(value) {
return value > 10;
}
const dataArray = [10, 11, 12, 3, 4];
const filteredArray = dataArray.filter(isLarge);
console.log(filteredArray); // [11, 12]
function squareRoot(value) {
return Math.sqrt(value)
}
const dataArray = [4, 9, 16];
const mappedArray = dataArray.map(squareRoot);
console.log(mappedArray); // [2, 3, 4]
let data = [1, 2, 3, 4, 4];
data[4] = 5;
console.log(data); // [1, 2, 3, 4, 5]
const names = ["Alex", "Victor", "John", "Linda"]
const newNamesArray = names.slice(1, 3) // ["Victor", "John"]
const employee = {
name: "Victor",
designation: "Writer",
address: {
city: "Lagos"
}
};
Object.freeze(employee);
// 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;
// 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]