Max Glenister

Web Dev • 3 min read Plain text

My solution to the JavaScript challenge 07/03/11

Okay so this solution is a bit later than I planned, but a busy working week and lack of motivation toward the end kind of got the better of me. Anyway, here’s my solution to the challenge. I’m sure Tomas will post his up soon.

Quick overview of the challenge:

With just the JavaScript/the jQuery core file (no plugins), create functions > to process some paragraphs of Lorem Ipsum in the following ways

  1. sort words by frequency of occurrence (bonus points for listing totals, > most frequent word, unique words, etc.)
  2. sort words in alphabetical order
  3. sort words by length of word (ascending/descending)
  4. a function to return the text to its original order, and also reverse the > original order
  5. Bonus: add some kind of effect during processing while re-arranging words

You can see the post with the challenge here

Areas I completed:

  1. sorting alphabetically (by words, not by words inside each paragraph)
  2. sorting alphabetically in reverse (as above)
  3. sorting by word length
  4. sorting by word length in reverse
  5. getting the top 5 words by frequency
  6. listening all unique words
  7. function to reset the text to original order
  8. function to reverse all words

How I approached this:

I started this with some really basic functions to apply sorts on arrays, and rebuild arrays, but I came across some problems with copying my original array of the words — where setting a new variable for a copy of the array would just reference the original array, not copy it.

I decided then to complete each of the tasks by writing new prototypes for the array object, so I could make a new array using the data from the original array with transformations, something like:

var newArray = oldArray.someAwesomePrototype();

This made it easy to have reusable functions, which are independent of the data in the array.

Some issues encountered and some neat observations:

This was the first JavaScript/jQuery challenge undertaken by Tomas and myself, and it was pretty challenging (even though it’s just some array processing) — the challenging part I found was resisting sharing ideas and code snippets with Tomas. We’ve worked a lot in the past on things, and I think it’s nicer to throw ideas back and forth between each other.

I found that with not knowing what the other person is doing, it motivated me to want to complete bits of the challenge better/faster.

An interesting point though, we both found that we were stuck on the same point, and decided to discuss our solutions. It came down to us being stuck in exactly the same way, and when we wrote solutions they were pretty similar.

Anyhow, the debrief is complete, on to my whole solution. The code is sort of spaghetti-like at the moment, but I might come back and clean it up later. You can see my solution here: 

Solution to the JavaScript challenge 07/03/11

  • Tinkering · shares #programming
    Android Auto on my HR-⁠V's Android 4.0.4 head unit

    I recently bought a 2018 Honda HR-V as our family car. It has a 7” touchscreen running Android 4.0.4, a version so old it predates Android Auto by about three years. It runs Android Auto now anyway, thanks to a small app I built over the course of a week.

    November 2026 • 7 min read
  • Data & Experiments · shares #programming
    Rebuilding and analysing 4 years of Wordle stats from WhatsApp chat logs

    Yes, I’m still playing Wordle in 2026. According to Wordle, I’ve played 1,559 games, I win 99% of the time, my current streak is 107 days and my longest is 278. Four numbers, and they’re mostly correct. What I don’t get is anything behind them. No per-game history. No way to compare a Tuesday to a Sunday. No sense of whether I’ve actually got better at this over four years. Each day I’ve played, I’ve also shared the result to WhatsApp. Just a habit, not a data strategy, but it turns out that habit quietly built a far more detailed record than Wordle itself ever keeps. One I can finally ask my own questions of. So I looked into rebuilding my own copy of the data.

    July 2026 • 10 min read
  • Data & Experiments · shares #programming
    What's the most popular number in Hacker News titles?

    Two consecutive titles on the HN front page yesterday had a 6 in them. This means nothing. But it’s the sort of nothing that lodges in your brain until you do something about it, so what is the most popular number in Hacker News titles?

    July 2026 • 7 min read

Discussion

No interactions yet

Join the conversation

Reply from your own site with a Webmention (how?).

Webmentions last fetched 17 November 2026, 13:05