'use strict';

module.exports = function(a, b) {
	let aOrder, bOrder;

	if (a.order != null) {
		aOrder = parseInt(a.order);
	}

	if (b.order != null) {
		bOrder = parseInt(b.order);
	}

	if (aOrder != null && bOrder == null) {
		return -1;
	} else if (aOrder == null && bOrder != null) {
		return 1;
	} else if (aOrder != null && bOrder != null) {
		if (aOrder < bOrder) {
			return -1;
		} else if (aOrder > bOrder) {
			return 1;
		} else {
			return 0;
		}
	} else {
		if (a.stackIndex < b.stackIndex) {
			return -1;
		} else if (a.stackIndex > b.stackIndex) {
			return 1;
		} else {
			return 0;
		}
	}
}