TAKEWHILE function

Synopsis
This function returns a portion of the source array up until the first element that does not consecutively respect a specified condition.
Variations
TAKEWHILE(SourceArray, Condition)
Returns a portion of the source array while its elements respect the specified condition.
Parameters
SourceArray

Specifies the array to work with.

Supported types: Numeric array; String array; Boolean array; Point array; Object array.
Condition

Specifies the condition that must be respected to continue taking elements.

Supported types: Boolean.
Returns
Returned types: Numeric array; Boolean array; String array; Point array; Object array.
Examples
1.

In the following example, the values of the source array are only taken while they satisfy the condition. As soon as the function encounters a value that does not satisfy the condition, the function returns the array. In this case it returns [-10, -8, -6, -4, -2, 0].

TAKEWHILE([-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10], Item <= 0)
TAKEWHILE(SourceArray, Condition, MaxCount)
Returns a portion of the source array while its elements respect the specified condition, up to a maximum number of elements.
Parameters
SourceArray

Specifies the array to work with.

Supported types: Numeric array; String array; Boolean array; Point array; Object array.
Condition

Specifies the condition that must be respected to continue taking elements.

Supported types: Boolean.
MaxCount

Specifies the maximum number of elements to include in the returned array.

Supported types: Numeric.
Returns
Returned types: Numeric array; Boolean array; String array; Point array; Object array.
Examples
1.

In the following example, the values of the source array are only taken while they satisfy the condition. The function will stop checking elements after reaching the maximum count; so, in this case, it returns [-10, -8, -6].

TAKEWHILE([-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10], Item <= 0, 3)