Esempio n. 1
0
        /// <summary>
        /// Removes an element at the specified `index` from the input `list`
        /// </summary>
        /// <param name="list">The input list</param>
        /// <param name="index">The index of a list to return elements</param>
        /// <returns>A new list with the element removed. If index is negative, remove at the end of the list.</returns>
        /// <remarks>
        /// ```scriban-html
        /// {{ [4, 5, 6, 7, 8] | array.remove_at 2 }}
        /// ```
        /// ```html
        /// [4, 5, 7, 8]
        /// ```
        /// If the `index` is negative, removes at the end of the list (notice that we need to put -1 in parenthesis to avoid confusing the parser with a binary `-` operation):
        /// ```scriban-html
        /// {{ [4, 5, 6, 7, 8] | array.remove_at (-1) }}
        /// ```
        /// ```html
        /// [4, 5, 6, 7]
        /// ```
        /// </remarks>
        public static IList RemoveAt(IList list, int index)
        {
            if (list == null)
            {
                return(new ScriptArray());
            }

            list = new ScriptArray(list);

            // If index is negative, start from the end
            if (index < 0)
            {
                index = list.Count + index;
            }

            if (index >= 0 && index < list.Count)
            {
                list.RemoveAt(index);
            }
            return(list);
        }