Created
February 24, 2015 22:40
-
-
Save getify/365d104210486006ec34 to your computer and use it in GitHub Desktop.
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
function dollabillsyall(strings, ...values) { | |
return strings.reduce( function(s,v,idx){ | |
if (idx > 0) { | |
if (typeof values[idx-1] == "number") { | |
// look, also using interpolated | |
// string literals! | |
s += `$${values[idx-1].toFixed( 2 )}`; | |
} | |
else { | |
s += values[idx-1]; | |
} | |
} | |
return s + v; | |
}, "" ); | |
} | |
var amt1 = 11.99, | |
amt2 = amt1 * 1.08, | |
name = "Kyle"; | |
var text = dollabillsyall | |
`Thanks for your purchase, ${name}! Your | |
product cost was ${amt1}, which with tax | |
comes out to ${amt2}.` | |
console.log( text ); | |
// Thanks for your purchase, Kyle! Your | |
// product cost was $11.99, which with tax | |
// comes out to $12.95. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment