StructEvery

Description

Determines if all values of a struct satisfy a given condition.

Returns

True if all values match a condition; false, otherwise.

Syntax

StructEvery(struct,callback)

Member function

structObj.Every(callback)

History

New in ColdFusion (2018 release) Update 5: Added this function.

Parameters

Parameter

Required/Optional

Description

struct

Required

Struct in which all values are to be searched.

callback

Required

Function that encapsulates the criteria.

Example

Example 1

<cfscript> 
 mystruct = {a=1,b=2,c=3}; 
 doesValExist=(key,value,struct)=>return value!=1 
 writeoutput(structEvery(mystruct,doesValExist)) // Returns False 
</cfscript>

Output

NO

Example 2

<cfscript>
 structEven={a=2,b=4,c=8,d=10,e=12}
 isEven=(key,value)=>return value%2==0
 writeOutput(StructEvery(structEven,isEven)) // Returns True
</cfscript>

Output

YES

Member function

<cfscript> 
 structEven={a=2,b=4,c=8,d=10,e=12} 
 isEven=(key,value)=>return value%2==0 
 writeOutput(structEven.Every(isEven)) // Returns True 
</cfscript>

Example 3 - Named parameters

<cfscript> 
    mystruct={"key1":"aval","key2":"aval1","key3":"aval2"} 
    result=StructEvery(struct=mystruct,callback=function(key,val){ 
        if (val.startswith("a")) 
              return 1 
        else 
              return 0 
            } 
    ) 
    writeOutput(result) 
</cfscript>

Output

YES

Arrow function

<cfscript> 
 ordstruct=["key1":"abc","key2":"def","key3":"sss"] 
    lambdaFunc= key => key.contains("key") 
    writeoutput(ordstruct.Every(lambdaFunc)) 
</cfscript>

Output

YES

 Adobe

Получайте помощь быстрее и проще

Новый пользователь?

Adobe MAX 2024

Adobe MAX

The Creativity Conference

С 14 по 16 октября очно в Майами-Бич и онлайн

Adobe MAX 2024

Adobe MAX

The Creativity Conference

С 14 по 16 октября очно в Майами-Бич и онлайн