As I dive into JavaScript functions, I find myself with three almost identical ones:
function filterAll() {
location.hash = "/"
}
function filterCompleted() {
location.hash = "/completed"
}
function filterActive() {
location.hash = "/active"
}
I wonder if there's a way to consolidate these functions into one, where I can specify the desired parameter each time I call it. Here's my attempt at restructuring them:
function filters(filterType) {
if (filterType === 'all') {
location.hash = "/";
} else if (filterType === 'completed') {
location.hash = "/completed";
} else if (filterType === 'active') {
location.hash = "/active";
}
}
filters('all');