@@ -220,7 +220,6 @@ http://ricostacruz.com/cheatsheets/umdjs.html
220220 var current ;
221221 var scopedLogic ;
222222 var scopedData ;
223- var filtered ;
224223 var initial ;
225224
226225 // easy syntax for unary operators, like {"var" : "x"} instead of strict {"var" : ["x"]}
@@ -314,7 +313,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html
314313 scopedData = jsonLogic . apply ( values [ 0 ] , data ) ;
315314 scopedLogic = values [ 1 ] ;
316315 // All of an empty set is false. Note, some and none have correct fallback after the for loop
317- if ( ! scopedData . length ) {
316+ if ( ! Array . isArray ( scopedData ) || ! scopedData . length ) {
318317 return false ;
319318 }
320319 for ( i = 0 ; i < scopedData . length ; i += 1 ) {
@@ -324,11 +323,31 @@ http://ricostacruz.com/cheatsheets/umdjs.html
324323 }
325324 return true ; // All were truthy
326325 } else if ( op === "none" ) {
327- filtered = jsonLogic . apply ( { filter : values } , data ) ;
328- return filtered . length === 0 ;
326+ scopedData = jsonLogic . apply ( values [ 0 ] , data ) ;
327+ scopedLogic = values [ 1 ] ;
328+
329+ if ( ! Array . isArray ( scopedData ) || ! scopedData . length ) {
330+ return true ;
331+ }
332+ for ( i = 0 ; i < scopedData . length ; i += 1 ) {
333+ if ( jsonLogic . truthy ( jsonLogic . apply ( scopedLogic , scopedData [ i ] ) ) ) {
334+ return false ; // First truthy, short circuit
335+ }
336+ }
337+ return true ; // None were truthy
329338 } else if ( op === "some" ) {
330- filtered = jsonLogic . apply ( { filter : values } , data ) ;
331- return filtered . length > 0 ;
339+ scopedData = jsonLogic . apply ( values [ 0 ] , data ) ;
340+ scopedLogic = values [ 1 ] ;
341+
342+ if ( ! Array . isArray ( scopedData ) || ! scopedData . length ) {
343+ return false ;
344+ }
345+ for ( i = 0 ; i < scopedData . length ; i += 1 ) {
346+ if ( jsonLogic . truthy ( jsonLogic . apply ( scopedLogic , scopedData [ i ] ) ) ) {
347+ return true ; // First truthy, short circuit
348+ }
349+ }
350+ return false ; // None were truthy
332351 }
333352
334353 // Everyone else gets immediate depth-first recursion
@@ -346,7 +365,6 @@ http://ricostacruz.com/cheatsheets/umdjs.html
346365 var sub_ops = String ( op ) . split ( "." ) ;
347366 var operation = operations ;
348367 for ( i = 0 ; i < sub_ops . length ; i ++ ) {
349-
350368 if ( ! operation . hasOwnProperty ( sub_ops [ i ] ) ) {
351369 throw new Error ( "Unrecognized operation " + op +
352370 " (failed at " + sub_ops . slice ( 0 , i + 1 ) . join ( "." ) + ")" ) ;
@@ -377,7 +395,7 @@ http://ricostacruz.com/cheatsheets/umdjs.html
377395 collection . push ( values [ 0 ] ) ;
378396 } else {
379397 // Recursion!
380- values . map ( function ( val ) {
398+ values . forEach ( function ( val ) {
381399 collection . push . apply ( collection , jsonLogic . uses_data ( val ) ) ;
382400 } ) ;
383401 }
0 commit comments