I didn't like that one much, it was clever but not pretty, this is much nicer.
var count = ((context.get("counter") || 0) + 1) % 20
msg.payload = count <= 10 ? count : 20 - count
context.set("counter", count);
return msg;
That counts up to 10 which is what was originally asked for, if you actually want up to 11 which is what the solutions have been doing so far then change the 20s to 22 and the 10 to 11.