Recap - The Chain Master
Part of the Logic & Flow section of Coddy's JavaScript journey — lesson 59 of 65.
Challenge
EasyCreate a function called chainMaster that takes an array of numbers as an argument. The function should use chained array methods to perform the following operations:
- Keep only numbers that are divisible by 3
- Multiply each remaining number by 2
- Sort the resulting array in descending order
- Return an object with the following properties:
transformedArray: The final array after all operationssum: The sum of all numbers in the final arrayaverage: The average of all numbers in the final array, rounded to two decimal places
Use appropriate array methods (filter, map, sort, reduce) in your solution.
Try it yourself
function chainMaster(numbers) {
// Write your code here
return {
transformedArray: result,
sum: sum,
average: average
};
}
All lessons in Logic & Flow
1Strings In Depth
String FundamentalsIterate Over StringsTemplate LiteralsString MethodsRecap - String Weaver4JSON Part 2
Iterate Over JSONNested JSONJSON Optional ChainingShallow And Deep CopyRecap - Bicycle ShopRecap - Solar System10Manage Festival System
Project OverviewAdd Movies & Venues2Multi-dimensional Arrays
2D Arrays BasicsAccessing 2D Array ElementsNested Loops with 2D ArraysRecap - 2D ArraysMatrix Addition & SubstractionJagged Arrays3D Arrays And BeyondCommon 2D Array PatternsRecap - All About Arrays5Sets Part 1
What Is A Set?Iterating Over SetsAdding An ElementRemoving An ElementChecking If An Element ExistsSize And Is EmptyCopy And ClearRecap - Basic Of Sets8Arrays Interesting Topics
Array DestructuringSpread Syntax in ArraysSparse ArraysRecap - Arrays Workshop3JSON Part 1
What is a JSON?Check If Key ExistsObject MethodsThe Spread Operator Part 1The Spread Operator Part 2Remove KeysRecap - JSON Manipulate Keys6Sets Part 2
Math - Union Of SetsMath - Intersection Of SetsMath - Difference Of SetsMath - Symmetric DifferenceSubsets And SuperSetsRecap - Group Friends9Advanced Array methods
The Join & Split MethodsThe Map Method The Filter MethodThe Reduce MethodChaining Array MethodsForEach And Map Are Same?The Sort MethodThe Find & FindIndex MethodRecap - The Chain Master