Created
October 5, 2014 23:36
-
-
Save mjkaufer/8b88ff48cb6ef5ea6ca6 to your computer and use it in GitHub Desktop.
Converts lists to prettier lists. I.e. `data1, data2, data3, ` to `data1, data2, and data3`
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
var data = ""; | |
for(var i = 0; i < 10; i++){//this is to give default values to the data set, to emulate what it would look like | |
data+=i + ", "; | |
} | |
data = data.replace(/\, $/g,"");//take out trailing comma | |
data = data.replace(/,([^,]*)$/, ", and$1");//adds a pretty "and" to the end | |
console.log(data); | |
//voila | |
//before | |
//"0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " | |
//after | |
//"0, 1, 2, 3, 4, 5, 6, 7, 8, and 9" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment