DEV Community

Discussion on: Problem-solving techniques to avoid yelling at your computer

Collapse
 
justmedev profile image
justmedev

The article by itself isn't bad, the example is.
You took an example and solved it by slowly reducing it into multiple smaller steps. This, by itself is fine. But you managed to end up with a less readable and over engineered example.

You could simply do:

const rows = 5;
let out = '';
for (let i = 0; i < rows; i++) {
  out += `${'#'.repeat(rows - i)}\n`;
}

console.log(out);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
colocodes profile image
Damian Demasi • Edited

That's a great improvement over the final code! 👍

I think the example's objective is to demonstrate the reasoning behind the solution of a problem, and not the most efficient way of writing code. The example is also not using any other method apart from the for loop and the console.log() method. In your case, the inner for loop gets replaced by the repeat method, which adds an extra step of complexity and deviates from the initial objective of the example.

I think your solution could be presented as an extra step in the problem resolution: "improve and make the solution more efficient".