Skip to content

Instantly share code, notes, and snippets.

@not-ivy
Last active January 25, 2020 23:54
Show Gist options
  • Save not-ivy/2575c34a610e82a847e9b09e77a50ece to your computer and use it in GitHub Desktop.
Save not-ivy/2575c34a610e82a847e9b09e77a50ece to your computer and use it in GitHub Desktop.
css-console-log
var rainbow = ["red", "yellow", "pink", "green", "purple", "orange", "blue"];
function rainbowify(string) {
var splitString = string.split("");
var formatString = "";
var colorArguments = [];
for (var i = 0; i < splitString.length; ++i) {
formatString += "%c" + splitString[i];
colorArguments.push("color : " + rainbow[i % rainbow.length]);
}
return [formatString].concat(colorArguments);
}
// output the array
console.log(rainbowify("test string"));
// Invoke console.log with the array as its arguments
console.log.apply(console, rainbowify("test string"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment