make all numbers truthy
This commit is contained in:
@@ -225,7 +225,6 @@ class Prelude {
|
|||||||
public static dynamic function truthy(v:Any) {
|
public static dynamic function truthy(v:Any) {
|
||||||
return switch (Type.typeof(v)) {
|
return switch (Type.typeof(v)) {
|
||||||
case TNull: false;
|
case TNull: false;
|
||||||
case TInt | TFloat: (v : Float) > 0;
|
|
||||||
case TBool: (v : Bool);
|
case TBool: (v : Bool);
|
||||||
default:
|
default:
|
||||||
// Empty strings are falsy
|
// Empty strings are falsy
|
||||||
|
@@ -81,8 +81,8 @@
|
|||||||
|
|
||||||
(defun _testIf []
|
(defun _testIf []
|
||||||
(Assert.equals true (if 1 true false))
|
(Assert.equals true (if 1 true false))
|
||||||
(Assert.equals false (if 0 true false))
|
(Assert.equals true (if 0 true false))
|
||||||
(Assert.equals false (if -1 true false))
|
(Assert.equals true (if -1 true false))
|
||||||
(Assert.equals false (if null true false))
|
(Assert.equals false (if null true false))
|
||||||
(Assert.equals true (if true true false))
|
(Assert.equals true (if true true false))
|
||||||
(Assert.equals false (if false true false))
|
(Assert.equals false (if false true false))
|
||||||
@@ -288,7 +288,7 @@
|
|||||||
(for val [1 2 3 4 5 6 7 8]
|
(for val [1 2 3 4 5 6 7 8]
|
||||||
(if (> val 6)
|
(if (> val 6)
|
||||||
(break)
|
(break)
|
||||||
(if (% val 2)
|
(if !(= 0 (% val 2))
|
||||||
(continue)
|
(continue)
|
||||||
val)))]
|
val)))]
|
||||||
(Assert.equals 2 a)
|
(Assert.equals 2 a)
|
||||||
|
Reference in New Issue
Block a user