Javascript Playground
Bonus advantage to this style of programming: easy to test. Building an automated test of the functions using values similar to those below and you would always know where the inevitable bug isn't.
- Is -5 nonzero: {{playCtrl.nonzero(-5)}}
- Is 0 nonzero: {{playCtrl.nonzero(0)}}
- Is 5 nonzero: {{playCtrl.nonzero(5)}}
-
Is x less than -20, or greater than 5 and less than 10?
- -40: {{playCtrl.inSomeRange(-40)}}
- -6: {{playCtrl.inSomeRange(-6)}}
- 7: {{playCtrl.inSomeRange(7)}}
- 11: {{playCtrl.inSomeRange(11)}}
- Default Data: {{playCtrl.data}}
- Filtered Data: {{playCtrl.data | filter:playCtrl.rangeFilter}}
- Test when() with truth: {{playCtrl.whenTruth}}
- Test when() with false: {{playCtrl.whenFalse}}
- Test unless() with truth: {{playCtrl.unlessTruth}}
- Test unless() with false: {{playCtrl.unlessFalse}}
- Test branch() with truth: {{playCtrl.branchTruth}}
- Test branch() with false: {{playCtrl.branchFalse}}