Day 25 – Merging Two Hashes

Being able to pick information out of a hash is nice but what about when you need to update the hash or combine/merge it with another?

ruleset a60x519 {
  meta {
    name "hash-put-test"
    description <<
      hash-put-test
    >>
    author "Mike Grace"
    logging on
  }

  rule testing {
    select when pageview ".*"
    pre {
      first = {
        "wow":"yes",
        "cool":"yes"
      };
      second = {
        "name":"mike",
        "location":"??"
      };

      combined = first.put(second);
    }
    {
      emit <|
        console.log(first);
        console.log(second);
        console.log(combined);
      |>;
    }
  }
}
  • 14-21 generic hashes with dummy data
  • 23 merge the two hashes together using the put operator – returns a new hash
  • 26-30 output the hashes to the console to review the results

App run on example.com with bookmarklet

Get the bookmarklet to try it out yourself!

Gratuitous day 25 Grace face

About these ads
This entry was posted in Kynetx. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s