Thursday, December 22, 2016

Writing Challenge - Day 17

Venturing out into the holiday retail wonderland today, I recognized the sadness, emptiness, waste and violence in it all.  Would-be shoppers jockeying to claim prime parking spaces.  Parking garages eager to cash in on making spending your money more convenient.  Car horns blaring angrily and pedestrians making snide remarks about the traffic and noise.  Queue-lining retail displays full of impulse purchase items exclaiming, "buy me, buy me!"  Ostensibly able-bodied shoppers contentedly riding an escalator in a two-floor store that stairs would have served just as well*.  This is how we make a season merry and bright?

*I suspect (or hope, at least) there was also an elevator for ADA compliance.

---

I've been back into playing with code some more this week.  CodeFights was a fun find, and another little thing I did was put together a word count utility on JSFiddle using AngularJS.  Having the word count utility put together essentially helps me avoid keeping OpenOffice Writer open just to assess whether I've hit my goal word count.  Considering that I do most of this writing from a Vista machine that I haven't yet scrapped for Ubuntu, this saves me a lot of memory management lag on stupidly low-resource hardware.  The HTML and JavaScript for my little word count utility are listed below for your code-reading pleasure...and because I'm sandbagging on my word count again today!

The HTML:
<div ng-app ng-controller="WCController">
    <div>Word count: {{ wordCount() }}</div>
    <textarea ng-model="words" rows="20" cols="40"/>
</div>

The JavaScript:
function WCController($scope) {
    $scope.wordCount = function () {
var text = $scope.words;
var s = text ? text.split(/\s+/) : 0; // it splits the text on space/tab/enter
      return s ? s.length : 0;
    };
}

No comments:

Post a Comment