change range a bit

This commit is contained in:
Khaleel Al-Adhami 2025-01-15 19:16:36 -08:00
parent 19b6fe9efc
commit d0208e678c
2 changed files with 37 additions and 37 deletions

View File

@ -13,11 +13,11 @@
export default function range(start, stop, step) { export default function range(start, stop, step) {
return { return {
[Symbol.iterator]() { [Symbol.iterator]() {
if (stop === undefined) { if ((stop ?? undefined) === undefined) {
stop = start; stop = start;
start = 0; start = 0;
} }
if (step === undefined) { if ((step ?? undefined) === undefined) {
step = 1; step = 1;
} }
@ -40,4 +40,4 @@ export default function range(start, stop, step) {
}; };
}, },
}; };
} }

View File

@ -189,20 +189,18 @@ def string_strip_operation(string: Var[str]):
def string_contains_field_operation( def string_contains_field_operation(
haystack: Var[str], haystack: Var[str],
needle: Var[str], needle: Var[str],
field: VarWithDefault[str] = VarWithDefault(""),
): ):
"""Check if a string contains another string. """Check if a string contains another string.
Args: Args:
haystack: The haystack. haystack: The haystack.
needle: The needle. needle: The needle.
field: The field to check.
Returns: Returns:
The string contains operation. The string contains operation.
""" """
return var_operation_return( return var_operation_return(
js_expression=f"isTrue({field}) ? {haystack}.some(obj => obj[{field}] === {needle}) : {haystack}.some(obj => obj === {needle})", js_expression=f"{haystack}.includes({needle})",
var_type=bool, var_type=bool,
var_data=VarData( var_data=VarData(
imports=_IS_TRUE_IMPORT, imports=_IS_TRUE_IMPORT,
@ -360,7 +358,7 @@ def array_pluck_operation(
The reversed array. The reversed array.
""" """
return var_operation_return( return var_operation_return(
js_expression=f"{array}.map(e=>e?.[{field}])", js_expression=f"Array.prototype.map.apply({array}, [e=>e?.[{field}]])",
var_type=List[Any], var_type=List[Any],
) )
@ -378,7 +376,9 @@ def array_join_operation(
Returns: Returns:
The joined elements. The joined elements.
""" """
return var_operation_return(js_expression=f"{array}.join({sep})", var_type=str) return var_operation_return(
js_expression=f"Array.prototype.join.apply({array},[{sep}])", var_type=str
)
@var_operation @var_operation
@ -631,7 +631,7 @@ def array_range_operation(
The range of numbers. The range of numbers.
""" """
return var_operation_return( return var_operation_return(
js_expression=f"range({e1}, {e2}, {step})", js_expression=f"[...range({e1}, {e2}, {step})]",
var_type=List[int], var_type=List[int],
var_data=VarData( var_data=VarData(
imports=_RANGE_IMPORT, imports=_RANGE_IMPORT,
@ -769,7 +769,7 @@ def map_array_operation(
return (ReflexCallable[[], List[args[0]._var_type]], None) return (ReflexCallable[[], List[args[0]._var_type]], None)
return var_operation_return( return var_operation_return(
js_expression=f"{array}.map({function})", js_expression=f"Array.prototype.map.apply({array}, [{function}])",
type_computer=nary_type_computer( type_computer=nary_type_computer(
ReflexCallable[[List[Any], ReflexCallable], List[Any]], ReflexCallable[[List[Any], ReflexCallable], List[Any]],
ReflexCallable[[ReflexCallable], List[Any]], ReflexCallable[[ReflexCallable], List[Any]],