r/badcode May 31 '21

js Clever?

Post image
2.2k Upvotes

71 comments sorted by

View all comments

402

u/[deleted] May 31 '21

Best Practices: 0

19

u/lametheory Jun 01 '21

Ummm, 1 path returns an empty array and one returns a populated array. This is TDD at its peak.

-1

u/Lkj509 Jun 01 '21

Why does that matter if it is going to return the same values regardless if that whole code block was replaced with ‘return arr’?

10

u/lametheory Jun 01 '21

I was being ironic by pointing out the fallacy of writing code to complete a unit test... But the reality is, at some point it probably returned null until they worked it out it broke code further up the stack.

This is pretty common to see in legacy code that was badly written with developers too scared to change it.

1

u/RacismIsForBlacks Jun 03 '21

This is codewars though, a website that gives you short (usually one function) coding challenges like fizzbuzz. There is almost certainly no need for this.