Skip to content

Instantly share code, notes, and snippets.

@johnfmorton
Last active November 6, 2018 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnfmorton/1e489a7d84768fcf7af7bf09867e33e8 to your computer and use it in GitHub Desktop.
Save johnfmorton/1e489a7d84768fcf7af7bf09867e33e8 to your computer and use it in GitHub Desktop.
<style>
body {
background: #282828;
color: #FFFFFF;
}
h1, h2, h3, h4, h5, h6 {
margin: 1em;
}
.fizz {
color: #FACB3E;
}
.buzz {
color: #75e5fa;
}
.fizzbuzz {
color: #FA67EE;
}
</style>
{% macro divisibeByArray(mynumber, myarray) %}{% spaceless %}
{% set myreturn = 0 %}
{% for mydivider in myarray %}
{% if myreturn == 0 and mynumber is divisible by(mydivider) %}
{% set myreturn = myreturn + 1 %}
{% endif %}
{% endfor %}
{% if myreturn == 1%}
{{ myreturn }}
{% endif %}
{% endspaceless %}{% endmacro %}
{% macro fizzBuzz(allIntegers, fizzArray, buzzArray) %}
{% import _self as helpers %}
{% for myentry in allIntegers %}
{% set myclassname1 = helpers.divisibeByArray(myentry, fizzArray) ? 'fizz' : '' %}
{% set myclassname2 = helpers.divisibeByArray(myentry, buzzArray) ? 'buzz' : '' %}
{% set myclassname = myclassname1 ~ myclassname2 %}
{#<h4 class='{{ myclassname }}'>{{ myentry }} is {{ myclassname ? myclassname : 'nothing'}}</h4>#}
<h4 class='{{ myclassname }}'>Entry Title {{ myentry }}</h4>
{% endfor %}
{% endmacro %}
{% import _self as macros %}
{% set entries = [] %}
{% for i in 1..100 %}
{% set entries = entries|merge([i]) %}
{% endfor %}
{{ macros.fizzBuzz(entries, [3, 7], [5, 17])}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment