-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
46 lines (33 loc) · 958 Bytes
/
map.js
File metadata and controls
46 lines (33 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// .map() = accepts a callback and applies that function
// to each element of an array, then return a new array
/*
const numbers = [1, 2, 3, 4, 5];
const sqaures = numbers.map(square);
const cubes = numbers.map(cube);
console.log(cubes);
function square(element){
return Math.pow(element, 2);
}
function cube(element){
return Math.pow(element, 3);
}
*/
/*
const students = ["Spongebob", "Patrick", "Squidward", "Sandy"];
const studentsUpper = students.map(upperCase);
const studentsLower = students.map(lowerCase);
console.log(studentsUpper);
function upperCase(element){
return element.toUpperCase();
}
function lowerCase(element){
return element.toLowerCase();
}
*/
const dates = ["2024-1-10", "2025-2-20", "2026-3-30"];
const formattedDates = dates.map(formatDates);
console.log(formattedDates);
function formatDates(element){
const parts = element.split("-");
return `${parts[2]}/${parts[1]}/${parts[0]}`;
}