Created
September 26, 2020 15:47
-
-
Save argodeep/c2367111b48234ec3307dfc325c77b0d to your computer and use it in GitHub Desktop.
Breadcrumb using recursive function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const routes = ['home', 'grids', 'grid1']; | |
| const breadcrumbs = []; | |
| let level = 0; | |
| while(level < routes.length) { | |
| breadcrumbs.push(routeTitleLink(routes.slice(0, level+1))); // calling recursive function for each route. | |
| level++ | |
| } | |
| console.log(breadcrumbs) | |
| function routeTitleLink(route) { | |
| return { | |
| title: route.slice(-1).toString().substr(0,1).toUpperCase() + route.slice(-1).toString().substr(1), | |
| link: route.join('/') | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment