You have some pure functions to write, your functions should take parameters and return a result!
Method | Description |
---|---|
.map() | creates a new array by performing a callback function on each array element |
.filter() | creates a new array with array elements that pass a certain condition |
.reduce() | takes all of the elements in an array and "reduces" them to a single value |
Time to practice the different Array iterators!
Write a function that:
- Takes an array of names as a parameter.
- It needs return a new array with each of the first letters of the names capitalized
// EXAMPLE INPUT -> ["charlie", "rob"];
// EXPECTED OUTPUT -> ["Charlie", "Rob"]
Write a function that:
- Takes an array of letters as a parameter.
- It needs return a new array with only consonants, the vowels need to be removed.
// EXAMPLE INPUT -> ["c", "r", "a"];
// EXPECTED OUTPUT -> ["c", "r"]
Write a function that:
- Takes an array of numbers as a parameter
- It needs to return the mean average
- Total the numbers and divide by the amount of numbers in the array
// EXAMPLE INPUT -> [25, 50, 175, 50];
// EXPECTED OUTPUT -> 75
Write a function that:
- Takes an array of words
- Returns a new array of words
- Figure out the difference with the examples below and use an array iterator method to implement it.
// EXAMPLE INPUT -> ["spray", "limit", "disco", "exuberant", "destruction", "present"];
// EXPECTED OUTPUT -> ["exuberant", "destruction", "present"]
Write a function that:
- Takes an array of words
- Returns a new array of words
- Figure out the difference with the examples below and use an array iterator method to implement it.
// EXAMPLE INPUT -> ["please camel", "join casing", "these disco", "with shoes"];
// EXPECTED OUTPUT -> ["pleaseCamel", "joinCasing", "theseDisco", "withShoes"]
Write a function that:
- Takes an array of scrabble tile objects
- Returns a score
- Figure out the difference with the examples below and use an array iterator method to implement it.
// EXAMPLE INPUT -> [{ letter: "a", value: 1}, { letter: "k", value: 5}, { letter: "c", value: 3}];
// EXPECTED OUTPUT -> 9
Write a function that:
- Takes an array of mile values as a parameter.
- It needs to convert them from miles to kilometers
- It needs to total them
- It needs to return an object with two keys
totalKM
: The total of the mile values in kmconvertedKM
: The array of converted mile values
// EXAMPLE INPUT -> = [10, 5];
// EXPECTED OUTPUT -> { convertedKM:[16.0934, 8.04672], totalKM: 24.14012 }
Write a function that:
- Takes an array of food objects and a food type either junk or healthy
- It needs to return a new array of objects filtered on whether they are the given food type.
// EXAMPLE INPUT -> [
// { img: "π", name: "pizza", foodType: "junk" },
// { img: "π", name: "burger", foodType: "junk" },
// { img: "π", name: "fries", foodType: "junk" },
// { img: "π", name: "hot dog", foodType: "junk" },
// { img: "π₯", name: "salad", foodType: "healthy" },
// { img: "π₯", name: "pita", foodType: "healthy" },
// { img: "π₯ͺ", name: "sandwich", foodType: "healthy" },
// { img: "π―", name: "burrito", foodType: "healthy" },
// { img: "π₯£", name: "soup", foodType: "healthy" },
// ];
// EXPECTED OUTPUT -> JUNK -> [
// { img: "π", name: "pizza", foodType: "junk" },
// { img: "π", name: "burger", foodType: "junk" },
// { img: "π", name: "fries", foodType: "junk" },
// { img: "π", name: "hot dog", foodType: "junk" },
// ]
// EXPECTED OUTPUT -> HEALTHY -> [
// { img: "π₯", name: "salad", foodType: "healthy" },
// { img: "π₯", name: "pita", foodType: "healthy" },
// { img: "π₯ͺ", name: "sandwich", foodType: "healthy" },
// { img: "π―", name: "burrito", foodType: "healthy" },
// { img: "π₯£", name: "soup", foodType: "healthy" },
// ]
Write a function that:
- Takes an array of hero objects
- It needs to return a new array of new hero objects where:
- The
name
key is changed tohero
- It should have a new key added called
id
, the value should be based on its index. - It should have a new key added called
power
, the value should be a random number between 1 - 10.
- The
// EXAMPLE INPUT -> [
// { name: "Spider-Man" },
// { name: "Thor" },
// { name: "Black Panther" },
// { name: "Captain Marvel" },
// { name: "Silver Surfer" },
// ];
// EXPECTED OUTPUT -> [
// { id: 0, hero: "Spider-Man", power: 1 },
// { id: 1, hero: "Thor", power: 9 },
// { id: 2, hero: "Black Panther", power: 10 },
// { id: 3, hero: "Captain Marvel", power: 8 },
// { id: 4, hero: "Silver Surfer", power: 2 },
// ];