Created
March 8, 2017 15:30
-
-
Save davidino/3ad70256583d928614956692aac01eba to your computer and use it in GitHub Desktop.
trainJs
This file contains 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
function generateBC(url, separator) { | |
var elements = url.split('/') | |
elements.reduce((acc, value, index) => { | |
return index === 0 ? | |
generateTag('/', 'home', false) : | |
generateTag(`/${value}/`, value, index == elements.length -1 ? true: false) | |
},'') | |
} | |
function generateTag(href, name, active) { | |
var tag = 'a' | |
var className = '' | |
if (active) { | |
tag = 'span' | |
className = 'class="active" '; | |
} | |
return `<${tag} ${className}href="${href}">${name.toUpperCase()}</${tag}>`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment