Skip to content

Instantly share code, notes, and snippets.

@brendanmckenzie
Last active August 29, 2015 14:20
Show Gist options
  • Save brendanmckenzie/cc129263c39b1e50bb6a to your computer and use it in GitHub Desktop.
Save brendanmckenzie/cc129263c39b1e50bb6a to your computer and use it in GitHub Desktop.
for (i = 0; i<filterList.length; i++) {
if (i === 0) {
s = filterList[i];
}
else if (i === filterList.length - 1) {
s = s + " and " + filterList[i];
}
else {
s = s + ", " + filterList[i];
}
}
if (filterList.length === 1) {
return filterList[0];
}
else {
[filterList.slice(0, -1).join(', '), filterList.pop()].join(' and ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment