コード例 #1
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);
        }
コード例 #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>
        /// <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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }