For the past few weeks, I've been learning Python through the book Python Crash Course at my friend Charles Roper's recommendation. In Python, you can view The Zen of Python by adding import this to your program. It's a set of guiding principles for Python's design. One such principle is that simple is better than complex, which is what I'd like you to think about today.

If I asked you to write a function (in JavaScript) that adds together some numbers and returns the result, how would you approach it?

Here's one way you could approach it using the reduce() method:

function sum (...nums) {
return nums.reduce((sum, num) => sum + num);
}

sum(1, 2, 3, 4, 5); // 15

This works, but is it immediately obvious what the code does?

Here's another way to approach the challenge:

function sum (...nums) {
let sum = 0;

for (const num of nums) {
sum += num;
}

return sum;
}

sum(1, 2, 3, 4, 5); // 15

There's a lot less "magic" going on here. We start with zero, add each number, then return the result. It's obvious what the code does.

Simple is better than complex.