{"ScriptPreparationCode":"var testSubNav = [{\r\n \u0022id\u0022: \u0022id1\u0022,\r\n \u0022text\u0022: \u0022All\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token1\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id2\u0022,\r\n \u0022text\u0022: \u0022By Amazon\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token2\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id3\u0022,\r\n \u0022text\u0022: \u0022News\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token3\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id4\u0022,\r\n \u0022text\u0022: \u0022Sports\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token4\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id5\u0022,\r\n \u0022text\u0022: \u0022TV shows\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token5\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id6\u0022,\r\n \u0022text\u0022: \u0022Movies\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token6\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id7\u0022,\r\n \u0022text\u0022: \u0022Entertainment\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token7\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id8\u0022,\r\n \u0022text\u0022: \u0022Crime\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token8\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id9\u0022,\r\n \u0022text\u0022: \u0022Reality\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token9\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id10\u0022,\r\n \u0022text\u0022: \u0022Family\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token10\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id11\u0022,\r\n \u0022text\u0022: \u0022Comedy\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token11\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id12\u0022,\r\n \u0022text\u0022: \u0022Action\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token12\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id13\u0022,\r\n \u0022text\u0022: \u0022Game shows\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token13\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id14\u0022,\r\n \u0022text\u0022: \u0022Sci-Fi\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token14\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id15\u0022,\r\n \u0022text\u0022: \u0022Food\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token15\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id16\u0022,\r\n \u0022text\u0022: \u0022DIY\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token16\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id17\u0022,\r\n \u0022text\u0022: \u0022Classic TV\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token18\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id18\u0022,\r\n \u0022text\u0022: \u0022Nature \u0026 Explore\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token18\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id19\u0022,\r\n \u0022text\u0022: \u0022Music\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token19\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id20\u0022,\r\n \u0022text\u0022: \u0022Spanish\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token20\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id21\u0022,\r\n \u0022text\u0022: \u0022Other\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token21\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n },\r\n {\r\n \u0022id\u0022: \u0022id22\u0022,\r\n \u0022text\u0022: \u0022Subscribe\u0022,\r\n \u0022action\u0022: {\r\n \u0022serviceToken\u0022: \u0022token22\u0022,\r\n \u0022text\u0022: null,\r\n \u0022pageType\u0022: \u0022home\u0022,\r\n \u0022pageId\u0022: \u0022live\u0022,\r\n \u0022analytics\u0022: {\r\n \u0022refMarker\u0022: \u0022refMarker\u0022\r\n },\r\n \u0022refMarker\u0022: \u0022refMarker\u0022,\r\n \u0022target\u0022: \u0022live\u0022\r\n },\r\n \u0022isSelected\u0022: false\r\n }\r\n]\r\n\r\nfunction isNotNull(value) {\r\n return value !== null;\r\n}\r\n\r\nfunction parsePageSubNav(subNav) {\r\n const subNavItems = subNav\r\n .map(({\r\n id,\r\n text,\r\n action,\r\n isSelected\r\n }) =\u003E {\r\n if (!id || !text) {\r\n return null;\r\n }\r\n return {\r\n id,\r\n text,\r\n action,\r\n isSelected\r\n };\r\n })\r\n .filter(isNotNull);\r\n\r\n // If there are more than MAX_SUB_NAV_ITEMS subnav items scheduled, then they are all dropped\r\n // This is preferred to only keeping the first MAX_SUB_NAV_ITEMS\r\n const filteredSubNavItems = subNavItems;\r\n\r\n if (!filteredSubNavItems.length) {\r\n return {\r\n items: []\r\n };\r\n }\r\n\r\n let selectedItemIndex = filteredSubNavItems.findIndex(item =\u003E item.isSelected);\r\n selectedItemIndex = selectedItemIndex === -1 ? 0 : selectedItemIndex;\r\n\r\n return {\r\n items: filteredSubNavItems.map(i =\u003E ({id: i.id, text: i.text, action: i.action})),\r\n selectedItemIndex\r\n };\r\n};\r\n\r\n\r\nfunction parseSubNav(subNav) {\r\n let skippedItems = 0;\r\n let selectedItemIndex = 0;\r\n\r\n const items = subNav.reduce((acc, subNavItem, index) =\u003E {\r\n const {\r\n id,\r\n text,\r\n action,\r\n isSelected\r\n } = subNavItem;\r\n if (!id || !text) {\r\n skippedItems \u002B= 1;\r\n } else {\r\n acc.push({\r\n id,\r\n text,\r\n action\r\n });\r\n if (isSelected) {\r\n selectedItemIndex = index - skippedItems;\r\n }\r\n }\r\n\r\n return acc;\r\n }, []);\r\n\r\n if (!items.length) {\r\n return {\r\n items: []\r\n };\r\n }\r\n\r\n return {\r\n items,\r\n selectedItemIndex\r\n };\r\n};","TestCases":[{"Name":"map-filter","Code":"parsePageSubNav(testSubNav)","IsDeferred":false},{"Name":"reduce","Code":"parseSubNav(testSubNav)","IsDeferred":false}]}