How can I get the last Matrix block of a certain type? I have a Matrix field with some different block types; images, videos, text, etc. When I loop over the blocks I have some extra code (facebook and twitter sharing, back-button, etc) that should only be output for the last "text" block. 

How can I know, inside the loop, if the current block is the last of its type?
What about comparing the currently looped block ID with the ID of the last block of type "text"?

_entry.html:

{% set lastTextBlock = entry.simpleMatrix.type('text').last() %}
{% set lastTextBlockId = lastTextBlock ? lastTextBlock.id : null %}

{% for block in entry.contentBlocks %}
    {% include '_blocks/' ~ block.type|lower %}
{% endfor %}


_blocks/text.html:

{% if block.id == lastTextBlockId %}
    ...
{% endif %}