DEV Community

Precious Afolabi
Precious Afolabi

Posted on

Weeks 6-8: Advanced Arrays, Problem-Solving Patterns, and Building a Data CLI

Three Weeks of Backend Fundamentals: Arrays, Patterns, and Building a Real Tool

Weeks 6 through 8 were a turning point. Not because the content was the hardest so far, but because it was the first time everything started connecting. Arrays, performance, patterns, Node.js. Here's what those three weeks looked like.

Week 6: Advanced Array Methods + Big O
This week was about using array methods on realistic data, not just [1, 2, 3] examples.
Working with product data meant chaining methods together to answer real questions — total value of in-stock items, most expensive item per category, filtering by rating and price simultaneously.
The one that clicked hardest was reduce for grouping:

const grouped = products.reduce((acc, p) => {
if (!acc[p.category]) acc[p.category] = [];
acc[p.category].push(p);
return acc;
}, {});

Once you understand this pattern, you see it everywhere.
Big O in Plain Terms
The Big O section was kept practical, not academic. The number that stuck:

Processing 1,000 items with O(n) = 1,000 operations. With O(n²) = 1,000,000 operations.

That's not a footnote — that's the difference between a backend that handles load and one that falls over. Nested loops feel harmless on small data. At scale, they're a problem waiting to happen.

Week 7: Problem-Solving Patterns
This was the most valuable week. Two patterns that genuinely show up everywhere:

  1. Frequency Counter Instead of comparing every item against every other item (O(n²)), you count occurrences in an object first, then check against it. Two separate loops instead of nested ones. javascriptfunction isAnagram(str1, str2) { if (str1.length !== str2.length) return false;

const freq = {};
for (let char of str1) freq[char] = (freq[char] || 0) + 1;
for (let char of str2) {
if (!freq[char]) return false;
freq[char]--;
}
return true;
}

O(n) time. You trade a little space to avoid expensive nested loops. Worth it almost every time.

  1. Two Pointers Works on sorted data. One pointer at the start, one at the end, moving inward based on what you find:

function pairSum(arr, target) {
let left = 0;
let right = arr.length - 1;

while (left < right) {
const sum = arr[left] + arr[right];
if (sum === target) return [left, right];
if (sum < target) left++;
else right--;
}
return null;
}

O(n) time, O(1) space. No extra memory. You're using the structure of the sorted array itself to guide the search — which feels almost like a cheat code once it clicks.
What both patterns have in common: there's almost always a smarter approach than brute force. Big O gives you the lens to recognize when you've found it.

Week 8: Building a Data Processing CLI
Week 8 was about applying everything — not more exercises, but an actual working tool.
The project: a command-line sales data analyzer that processes JSON files.
bashnode analyzer.js data.json --sum price
node analyzer.js data.json --filter "region=Lagos"
node analyzer.js data.json --group region
node analyzer.js data.json --stats price

Each command maps to a function. groupBy uses the reduce pattern from Week 6. filterData splits the condition string and applies it. getStats maps, reduces, and spreads all in one go:

async function getStats(data, field) {
const values = data.map(item => item[field]);
return {
min: Math.min(...values),
max: Math.max(...values),
avg: values.reduce((sum, val) => sum + val, 0) / values.length,
total: values.reduce((sum, val) => sum + val, 0)
};
}

The whole thing comes together in a main() function that reads process.argv, loads the file with fs/promises, and routes to the right handler.
Why It Matters Beyond the Exercise
The CLI is simple. But the patterns inside it are exactly what runs in:

REST APIs processing incoming request data
Database query results being transformed before returning
Batch jobs running against thousands of records
Data pipelines aggregating in real time

Load data → filter → transform → aggregate → return. That loop is backend work. The interface changes, the logic doesn't.

The Shift That Happened
Before these weeks, arrays, Big O, and patterns felt like three separate topics in a curriculum.
After building the CLI, they feel like one thing.
Array methods implement the patterns. Big O tells you which pattern to reach for. The patterns combine to solve real problems. Reading about reduce is fine. Using it to group sales by region and generate stats is when you actually understand it.

What's Next
Asynchronous JavaScript — promises, async/await, and finally connecting to external APIs. The backend foundation is there. Time to make it talk to the outside world.

What's the hardest part of learning for you — grasping new concepts, or applying them to build something? Drop it in the comments.

Top comments (0)