import { GroupedLayoutsInterface, LayoutInterface, } from './index'; import { ObjectUtils, } from './../../helpers/functions/index'; export default class GroupedLayoutModel { public static chooseARandomLayout( layouts: GroupedLayoutsInterface, lastLayoutValue?: LayoutInterface, ) { let property; while (!property || layouts[property].length === 0) { property = ObjectUtils.pickRandomProperty(layouts); } let nextValue: LayoutInterface; while (!nextValue || nextValue === lastLayoutValue) { nextValue = ObjectUtils.randomValueFromArray( layouts[property], ); } lastLayoutValue = nextValue; return nextValue; } }