Jagged Arrays
Part of the Logic & Flow section of Coddy's JavaScript journey — lesson 11 of 65.
A jagged array is a 2D array-like structure where each row can have a different length. For example:
const classroom = [
["Alice", "Bob"],
["Charlie", "Diana", "Eve"],
["Frank"]
];Here, the first row has 2 elements, the second row has 3, and the third row has 1.
Challenge
EasyCreate a function named sumJagged that receives a jagged array of numbers and returns the total sum of all elements across every row, regardless of row length.
Cheat sheet
A jagged array is a 2D array where each row can have a different length:
const classroom = [
["Alice", "Bob"],
["Charlie", "Diana", "Eve"],
["Frank"]
];The first row has 2 elements, the second row has 3, and the third row has 1.
Try it yourself
function sumJagged(jaggedArray) {
// TODO: Implement logic to sum all elements of the jagged array.
}
// Do not write anything outside functionThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
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 Keys