From f46e850b0cdb6f57d0d4362418bdd1abfbac6e28 Mon Sep 17 00:00:00 2001 From: carlosnturing Date: Mon, 16 Dec 2024 11:11:28 -0300 Subject: [PATCH] Update `higher-order-functions.md`: add warning about `$map()`'s returned value in case the array has length one --- docs/higher-order-functions.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/higher-order-functions.md b/docs/higher-order-functions.md index 95ea8bd8..d47c0541 100644 --- a/docs/higher-order-functions.md +++ b/docs/higher-order-functions.md @@ -9,6 +9,13 @@ __Signature:__ `$map(array, function)` Returns an array containing the results of applying the `function` parameter to each value in the `array` parameter. +> :warning: **If your array has exactly one item the returned value won't be an array.** Only that single item will be returned. +> +> In this case, to have the return of `$map()` be a array, please append `[]` to the closing parenthesis of the `$map()` function: +``` +$map([1], $string)[] +``` + The function that is supplied as the second parameter must have the following signature: `function(value [, index [, array]])`