Skip to content

Instantly share code, notes, and snippets.

@davidino
Created March 8, 2017 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidino/3ad70256583d928614956692aac01eba to your computer and use it in GitHub Desktop.
Save davidino/3ad70256583d928614956692aac01eba to your computer and use it in GitHub Desktop.
trainJs
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