One More Time Challenge


I won a coding challenge!

was surprised to learn my code won in the “Efficiency” category of the “One More Time” coding Challenge hosted by the amazing people of HowToSFMC.

The goal was simple: recreate the lyrics of the classic Daft Punk song using only Server-Side JavaScript in Salesforce Marketing Cloud which turned out to be a really interesting task (and had me obsessing about such things like the count of commas in the lyrics). Some blunders were made, but the code I submitted turned out to have the shortest length which allowed me to win in my category.

The winning solution

<script runat="server">w="Celebration Celebrate celebrate Music's dancing feeling tonight right, Don't Need, We're can't dance don't gonna right we're yeah, Come Hey! Just Mmm, free just know late more need stop time wait yeah I'm One You all and got on, the too you Oh We do it me no so".split(' ');s="⣰⣰♫⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔♫⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔♫⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔♫⣰⢚⢞⢒♫⢺⢯♫⣰♫⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔♫⣰⢚⢞⢒♫⢺⢯♫⢘⢬⢷⢔♫⣰♫⢥⢹⢨⢰⢧⢕♫⢐⢖♫⢑♫⢘⢮⢸⢩♫⢥⢿♫⢻⢝⢬♫⢲⢛⢬♫⢚⢞⢒♫⣰⣰⣰⢐♫⢲⢨⢠⢞⢼⢽⢗⢖♫⢣⢤⢕♫⢓⢵⢾⢕⢷⢫♫⢙⢯♫⢢⢶⢳⢟♫⢚⢞⢒♫⣰⢑⢴⢜⣀⢦♫⢓⢵⢾⢕⣀⢦♫⢑⢴⢜⣀⢦⣷⣷⣷⣷⣷♫⣷⣷⣷⣷♫⣰⢓⢵⢾⢕⣀⢦♫⢚⢞⢒⣷⣷♫⣷⣷⣷⣷".replace(/⣷/g,'♫⣰⢓⢵⢾⢕⣀⢦♫⢚⢞⢒♫⢑⢴⢜⣀⢦').replace(/⣰/g,'⢱⢪⢭♫');for(c=0;c&lt;s.length;c++){i=s.charCodeAt(c)-10384;if(i&gt;=0){t=w[i]+' '}if(s[c]=='♫'){t='&lt;br&gt;'}Platform.Response.Write(t)}&lt;/script>

A More Readable Version

If we unwrap the code, add the some formatting and more understandable names for variables, we get something like this:

<script runat="server">
var words = "Celebration Celebrate celebrate Music's dancing feeling tonight right, Don't Need, We're can't dance don't gonna right we're yeah, Come Hey! Just Mmm, free just know late more need stop time wait yeah I'm One You all and got on, the too you Oh We do it me no so".split(' ');
var structure = "⣰⣰♫⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔♫⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔♫⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔♫⣰⢚⢞⢒♫⢺⢯♫⣰♫⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔♫⣰⢚⢞⢒♫⢺⢯♫⢘⢬⢷⢔♫⣰♫⢥⢹⢨⢰⢧⢕♫⢐⢖♫⢑♫⢘⢮⢸⢩♫⢥⢿♫⢻⢝⢬♫⢲⢛⢬♫⢚⢞⢒♫⣰⣰⣰⢐♫⢲⢨⢠⢞⢼⢽⢗⢖♫⢣⢤⢕♫⢓⢵⢾⢕⢷⢫♫⢙⢯♫⢢⢶⢳⢟♫⢚⢞⢒♫⣰⢑⢴⢜⣀⢦♫⢓⢵⢾⢕⣀⢦♫⢑⢴⢜⣀⢦⣷⣷⣷⣷⣷♫⣷⣷⣷⣷♫⣰⢓⢵⢾⢕⣀⢦♫⢚⢞⢒⣷⣷♫⣷⣷⣷⣷".replace(/⣷/g,'♫⣰⢓⢵⢾⢕⣀⢦♫⢚⢞⢒♫⢑⢴⢜⣀⢦').replace(/⣰/g,'⢱⢪⢭♫');
 
for(c = 0; c < structure.length; c++){
    var index = structure.charCodeAt(c) - 10384;
    if(index >= 0){
        var text = words[index] + ' '
        }
    if(structure[c] == '♫'){
        var text='<br>'
        }
    Platform.Response.Write(text)
    }
</script>

How does this really work?

If you are curious about this, you can read further:

  • My article on HowToSFMC where I explain how you can implement it and how it works
  • Songbreaker – this is a script that I developed to be able to encode the lyrics of “One More Time” to characters like this ⢱⢪⢭ and save a lot of space in the solution (this is a client-side JavaScript solution)

Could the code be any shorter?

This solution below cuts the character count even further from 693 to 664, but I came up with it after the original submission.

<script runat="server">w="Celebration Celebrate celebrate Music's dancing feeling tonight right, Don't Need, We're can't dance don't gonna right we're yeah, Come Hey! Just Mmm, free just know late more need stop time wait yeah I'm One You all and got on, the too you Oh We do it me no so".split(' ');s="⣰⣰♫⠿♫⠿♫⠿♫⣰⢚⢞⢒♫⢺⢯♫⣰♫⠿♫⣰⢚⢞⢒♫⢺⢯♫⢘⢬⢷⢔♫⣰♫⢥⢹⢨⢰⢧⢕♫⢐⢖♫⢑♫⢘⢮⢸⢩♫⢥⢿♫⢻⢝⢬♫⢲⢛⢬♫⢚⢞⢒♫⣰⣰⣰⢐♫⢲⢨⢠⢞⢼⢽⢗⢖♫⢣⢤⢕♫⢓⢵⢾⢕⢷⢫♫⢙⢯♫⢢⢶⢳⢟♫⢚⢞⢒♫⣰⢑⢴⢜⣀⢦♫⢓⢵⢾⢕⣀⢦♫⢑⢴⢜⣀⢦⣷⣷⣷⣷⣷♫⣷⣷⣷⣷♫⣰⢓⢵⢾⢕⣀⢦♫⢚⢞⢒⣷⣷♫⣷⣷⣷⣷".replace(/⠿/g,"⣰⢚⢞⢒♫⢺⢡⢳⢟♫⢘⢬⢷⢔").replace(/⣷/g,'♫⣰⢓⢵⢾⢕⣀⢦♫⢚⢞⢒♫⢑⢴⢜⣀⢦').replace(/⣰/g,'⢱⢪⢭♫');for(c=0;c<s.length;c++){if(s[c]=='♫'){t='<br>'}else{t=w[s.charCodeAt(c)-10384]+' '}Platform.Response.Write(t)}</script>