A tasty byte, when you don’t have onions

It’s spring here in berlin. Finally real spring. Actually we don’t do anything half-assed around these parts — apparently we go from 10 degrees to 20, from rain and slate to a heat wave… and well, thats very me. I am also either black or white, hot or cold, bored or way too busy, stuffed or hungry… most of the time. No, half-assing isn’t in my blood.

I’m also kind of stubborn. And when it comes to algorithms, the second craving is something that won’t go away until it’s satisfied. It doesn’t matter that the weather turned for the better and this program is more fit for winter. No, I won’t rest until I have it running in a repl. Preferably immediately, but logistics do get in the way. Pssh.

I was chatting with my granny on zoom last night, and she said nothing fixes the appetite for a good program quite like a sorting algorithm. So, naturally, when I woke up today I really felt like a little bit of bubble sort, or a solid heap sort. The problem was, naturally that I didn’t have any onions. You can’t do a sorting algorithm without onions, it just doesn’t have any soul. It would also have terrible performance.

So I went for a walk around the balcony and thought for a bit. Granny’s enthusiasm had me totally in on doing a bit of programming today, but it had to be quick and satisfying. not everything needs to be performant. But it needs soul. I knew exactly what to do: Gnome sort with garlic

It needed to be short and sweet, so of course I chose the most sensible language for this, JavaScript.

const foo = [

const gnomeSort = arr => {
   const l = arr.length;
   let i = 1;
   while (i < l) {
       if (i > 0 && arr[i  1] > arr[i]) {
           [arr[i], arr[i  1]] = [arr[i  1], arr[i]];
       } else {
   return arr;


You can also run this with onion of course! It only makes it better. Remember to leave your comments below and let me know how it went!

hi i am making a new post for the indieweb camp