function updateSections()

in public/components/toolbar-sections-dropdown/toolbar-sections-dropdown.js [50:69]


            function updateSections (selectedSections) {
                var sections = $scope.sections.map((section) => {
                    section.selected = selectedSections.indexOf(section.id) !== -1;
                    return section;
                }).sort((a, b) => {
                    if (!a.selected && b.selected) { // Selected at the top
                        return 1;
                    } else if (a.selected && !b.selected) { // Unselected below
                        return -1;
                    } else {
                        return a.name > b.name ? 1 : -1; // Both in Alphabetic order
                    }
                });

                // Pin 'Proffessional Networks' to the bottom of the list
                var isPN = (s) => { return (s.name.indexOf("(PN)") > -1) && !s.selected; }
                var pnSections = sections.filter(isPN);

                return sections.filter((s) => {return !isPN(s);}).concat(pnSections);
            }