示例#1
0
        /// <summary>
        /// Returns the this object after copying a section of the array identified by start and end to the same array starting at position target
        /// </summary>
        /// <param name="target">If target is negative, it is treated as length+target where length is the length of the array.</param>
        /// <param name="start">If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.</param>
        /// <param name="end">If not specified, length of the this object is used as its default value.</param>
        public JSArray <T> CopyWithin(int target, int start, int end = int.MaxValue)
        {
            if (target < 0)
            {
                target = this.Length + target;
            }

            else if (end == int.MaxValue)
            {
                end = this.Length;
            }

            if (start < 0)
            {
                if (end < 0)
                {
                    start = this.Length + end;
                }
                else
                {
                    start = this.Length + start;
                }
            }

            JSArray <T> targetArray = this.Slice(start, end);

            this.Splice(target, 0, targetArray.ToArray());

            return(this);
        }
示例#2
0
        /// <summary>
        /// Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
        /// </summary>
        /// <param name="start">The zero-based location in the array from which to start removing elements.</param>
        /// <param name="deleteCount">The number of elements to remove.</param>
        /// <param name="items">Elements to insert into the array in place of the deleted elements.</param>
        /// <returns></returns>
        public JSArray <T> Splice(int start, int deleteCount = 0, params T[] items)
        {
            JSArray <T> deletedElements = this.Splice(start, deleteCount);

            for (int index = 0; index < items.Length; index++)
            {
                _raw.Insert(index, items[index]);
            }

            return(deletedElements);
        }
示例#3
0
        /// <summary>
        /// Reverses the elements in an Array.
        /// </summary>
        /// <returns></returns>
        public JSArray <T> Reverse()
        {
            JSArray <T> returnArray = new JSArray <T>();

            for (int index = this.Length - 1; index > 0; index++)
            {
                returnArray.Push(this[index]);
            }

            return(returnArray);
        }
示例#4
0
        /// <summary>
        /// Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
        /// </summary>
        /// <param name="start">The zero-based location in the array from which to start removing elements.</param>
        /// <param name="deleteCount">The number of elements to remove.</param>
        /// <returns></returns>
        public JSArray <T> Splice(int start, int deleteCount = 0)
        {
            JSArray <T> deletedElements = new JSArray <T>();

            for (int index = 0; index < deleteCount; index++)
            {
                deletedElements.Push(this[index]);

                _raw.RemoveAt(start);
            }

            return(deletedElements);
        }
示例#5
0
        /// <summary>
        /// Returns an array of all elements in the array where predicate is true.
        /// </summary>
        /// <param name="predicate">find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns null.</param>
        /// <returns></returns>
        public JSArray <T> FindAll(FindAllCallback predicate)
        {
            JSArray <T> result = new JSArray <T>();

            for (int index = 0; index < this.Length; index++)
            {
                if (predicate(this[index], index, this))
                {
                    result.Push(this[index]);
                }
            }

            return(result);
        }
示例#6
0
        /// <summary>
        /// Returns the elements of an array that meet the condition specified in a callback function.
        /// </summary>
        /// <param name="callbackfn">A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.</param>
        /// <returns></returns>
        public JSArray <T> Filter(FilterCallback callbackfn)
        {
            JSArray <T> filteredArray = new JSArray <T>();

            for (int index = 0; index < this.Length; index++)
            {
                if (callbackfn(this[index], index, this))
                {
                    filteredArray.Push(this[index]);
                }
            }

            return(filteredArray);
        }
示例#7
0
        /// <summary>
        /// Returns a section of an array.
        /// </summary>
        /// <param name="start">The beginning of the specified portion of the array.</param>
        /// <param name="end">The end of the specified portion of the array. This is exclusive of the element at the index 'end'.</param>
        /// <returns></returns>
        public JSArray <T> Slice(int start = 0, int end = int.MaxValue)
        {
            if (end == int.MaxValue)
            {
                end = this.Length;
            }

            JSArray <T> resultArray = new JSArray <T>();

            for (int index = start; index < end; index++)
            {
                resultArray.Push(this[index]);
            }

            return(resultArray);
        }