Test if a series of numbers is a "Jolly Jumper":

A sequence of n > 0 integers where the absolute values of the
differences between successive elements take on all possible values 1 through n - 1.

@param array $items
@return bool
969218
public static function isJollyJumperSeries(array $items = array())
    {
        if (empty($items)) {
            return null;
        }
        if (count($items)==1) {
            return true;
        }
        $diffs = array();
        for ($i=0; $i<count($items)-1; $i++) {
            $diffs[] = abs($items[$i] - $items[$i+1]);
        }
        $diffs = array_filter($diffs);
        $limit = min(max($diffs)+1, count($items));
        $isjj = true;
        for ($i=1; $i<$limit; $i++) {
            if (!in_array($i,$diffs)) {
                $isjj = false;
            }
        }
        return $isjj;
    }
935933
protected function setItemListElementAttribute($items)
    {
        foreach($items as $pos=>$item) {
            $items[$pos] = $this->getNestedContext(ListItem::class, [
                'position' => $pos + 1,
                'item' => $item
            ]);
        }

        return $items;
    }
1173614
protected function isSequence($value)
    {
        if (!Helper::isSequential($value)) {
            return false;
        }

        if ($value === []) {
            return true;
        }

        $i=0;

        $lastItemType = null;

        foreach ($value as $key=>$item) {

            if ($key !== $i) {
                return false;
            }

            $itemType = Type::of($item);

            // TODO: list could be typed by common class or interface
            if ($i !== 0 && $itemType != $lastItemType) {
                return false;
            }

            $lastItemType = $itemType;
            $i++;
        }

        return true;

    }
106724
public static function isNumericallyIndexed(array $values): bool
    {
        if (empty($values)) {
            return true;
        }

        reset($values);

        return is_int(key($values));
    }
1173350
public static function make($items)
    {
        if (is_null($items)) {
            return new static;
        }

        if ($items instanceof Collection) {
            return $items;
        }

        return new static(is_array($items) ? $items : [$items]);
    }
1006114
public function setItems($items)
    {
        $newItems = new ItemBag();
        foreach ($items as $item) {
            $newItems->add(new Item($item->getParameters()));
        }

        return parent::setItems($newItems);
    }
1087054
protected function isArrayable($items)
    {
        return is_array($items) ||
            $items instanceof self ||
            $items instanceof Arrayable ||
            $items instanceof Jsonable ||
            $items instanceof JsonSerializable ||
            $items instanceof Traversable;
    }
355002
public function addChildren(array $items): bool
    {
        if ($this->_item) {
            foreach ($items as $name) {
                $child = $this->manager->getPermission($name);
                if (empty($child) && $this->type == Item::TYPE_ROLE) {
                    $child = $this->manager->getRole($name);
                }
                $this->manager->addChild($this->_item, $child);
            }
        }

        return true;
    }
57214
protected function convertItems($items)
    {
        $convertedItems = new Collection();

        foreach ($items as $item) {
            $convertedItems->add(new ItemContainer($item));
        }

        return $convertedItems;
    }
76901
public function addToArray($items = [])
    {
        if (!is_array($items)) {
            $items = [$items];
        }

        foreach ($items as $item) {
            $this->toArray[] = $item;
        }

        return $this;
    }
903239
public function addItemsIfNotNull(array $items, bool $strict = false, bool $skipThis = true)
    {
        foreach ($items as $key => $value) {
            if ($skipThis && ($key === 'this')) {
                continue;
            }
            $this->addItemIfNotEmpty($key, $value, false, $strict);
        }
        return $this;
    }
786065
public function contains(... $items) : bool
    {
        $values = $this->getValues();
        foreach($items as $item)
        {
            if (!in_array($item, $values, true))
            {
                return false;
            }
        }
        return true;
    }
987899
protected function setInAlbumAttribute($items)
    {
        if ( ! is_array($items))
        {
            return $items;
        }

        //Check if not multidimensional array (for backward compatibility)
        if((count($items) == count($items, COUNT_RECURSIVE)))
        {
            return $this->getNestedContext(MusicAlbum::class, $items);
        }

        //multiple albums
        return array_map(function ($item) {
            return $this->getNestedContext(MusicAlbum::class, $item);
        }, $items);
    }
908533
protected function setColumnCountViaArray($items)
    {
        $counts = array_map(function ($arr) {
            return count($arr);
        }, $items);

        $this->column_count = max($counts);
    }
59980
private static function isSortable($item)
    {
        return is_array($item)
            ||
            (
                is_object($item)
                &&
                Reflection::hasMethod($item, 'getPosition')
                &&
                Reflection::hasMethod($item, 'setPosition')
            );
    }
278104
public static function order($items) {
		if (empty($items)) {
			return array();
		}

		$_items = array_combine(array_keys($items), Hash::extract($items, '{s}.weight'));
		asort($_items);

		foreach (array_keys($_items) as $key) {
			$_items[$key] = $items[$key];
		}

		return $items;
	}
692659
protected function hydrateLineItems($items)
    {
        $result = array();
        if ($items == null) {
            return $result;
        }

        foreach ($items as $i => $item) {
            $result = array_merge(
                $result,
                array(
                    'Item_Name_'     . $i => $item->name,
                    'Item_Desc_'     . $i => $item->description,
                    'Item_Price_'    . $i => $this->formatAmount($item->amount),
                    'Item_Quantity_' . $i => $item->quantity,
                    'Item_SKU_'      . $i => $item->number,
                )
            );
        }

        return $result;
    }