How to count words in JavaScript using JQuery

You would split the string and then count the length of the resulting array.

<span class="pln">$</span><span class="pun">(</span><span class="str">'input[type="submit"]'</span><span class="pun">).</span><span class="pln">click</span><span class="pun">(</span> <span class="kwd">function</span><span class="pun">()</span> <span class="pun">{</span>
    <span class="kwd">var</span><span class="pln"> words </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#name'</span><span class="pun">).</span><span class="pln">val</span><span class="pun">().</span><span class="pln">split</span><span class="pun">(</span><span class="str">' '</span><span class="pun">);</span><span class="pln">
    alert</span><span class="pun">(</span><span class="pln">words</span><span class="pun">.</span><span class="pln">length</span><span class="pun">);</span>
<span class="pun">});</span>

Up and Down the Ladder of Abstraction

A Systematic Approach to Interactive Visualization

An arbitrary road could look like almost anything. In order to tame this data space, we choose some aspect of the road which we suspect issignificant — an aspect that reflects some challenge that our algorithm will face. Our algorithm is currently built around a fixed turning rate which determines how sharply the car turns. We might therefore suspect that the sharpness of the bend in the road will play an important role.

 .. Real-world systems may be more complex, but they all share the same general anatomy: an independent variable (such as time), a structure (such as an algorithm), and a dataset (such as an environment).
  • The independent variable is usually time. This is our way of thinking about causality — a system’s state depends on its previous states in time. Even for systems that are normally expressed with multiple independent variables, such as heat diffusion or wave propagation, we typically think of the system as evolving over time.
 .. Unfortunately, development environments generally don’t support this process. Most are actively hostile to it. We live in primitive times.
 .. Perhaps IDE makers will focus on dynamic exploration instead of static analysis, rich visualization instead of line debugging. Perhaps language theorists will stop messing around with arrows and dependent types, and start inventing languages suitable for interactive development and discovery.

“Node.js is one of the worst things to happen to the software industry”

There are a lot of things to like about Node.js, but the primary thing that bothers me about it is the obsession with async. It’s a language/framework designed to make pretty much everything async.

In the real world, almost everything is synchronous, and only occasionally do you really want async behavior. By that I mean, you almost always want A, B, C, D, E, F, G in that order, and only occasionally would you say that you want async(H,I). But with Node, it’s the other way around. You assume things are async, and then specify synchronous behavior.

.. However, there are languages like Haskell, Erlang, and Go that IMO did the right thing by building a synchronous programming model for concurrency

.. The other red flag is the community. Somehow Node.js community managed to accumulate the most immature and childish people. I don’t know what it is / was about it. But there it was.

.. Nodejs seems to me to be like the Perl world was in ’95 or the PHP world in 2000 or the Python world in 2002 or the Java world pretty much forever 😉

.. You’re touching the reason yourself. When 90% of the code you find is crap, it simply means that the language has a low barrier of entry. When languages like ML/Scheme/LISP variants, Haskell, ect. don’t have that much crap, it’s because the barrier of entry is higher.

.. My understanding is that Facebook has migrated most (all?) of its PHP codebase to Hack, which goes to show you: even the company that built a global empire in PHP can recognize it for the shitty, inadequate language that it is.

 .. <devil’s advocate> On the other hand, that shitty inadequate language got them up to their first billion or so users and way past Unicorn stage. If you’re optimising your language choices and talent pool for your second or third billion users when you currently don’t even have enough users to fund the ramen invoices, you’re 100% certainly playing around with “the root of all evil”… 😉
.. Writing JavaScript for the browser and writing it for Node.js are different beasts. It’s “easy” to find JavaScript devs because most people have tinkered with jQuery and think that qualifies them. Furthermore, since the Node.js explosion in 2012, lots of posers have been trying to get into this scene.
.. It seems like an appeal to hiring manager to me. “You’ll have all the developers you need! Look, it’s all javascript and everyone knows javascript!”The problem is assuming language proficiency is the defining characteristic of a developer. We really need to disabuse management of that idea.
    .. I think basic CompSci courses should really have a
    course or two on managing software projects and handling
    the problems of what framework do I use to build my new
    software app

The problem (if it’s a problem, depends on who’s asking) is that undergrad CS courses mainly train you to be a CS graduate student (which in turn train you to be a CS academic), but most students choose to major in CS because they want to become professional programmers (aka Software Engineers).

I’ve done both bachelor and master level CS studies and job-preparation-wise would probably have gotten as much (or more) from a 1-1.5 years (2-3 semesters) vocational training than I did from 8 years of university.

.. > he biggest advantage of Node.js is that you can reuse the same code on the client and server, and thus it’s ideal for creating universal single-page web apps. Being able to reuse the same code on the client and server is a massive advantage that can’t be understated.

This advantage is totally overblown, and in fact I am not sure it even is an advantage. It definitely makes things easier in the short run, but it always comes around to bite you in the ass. The fact is, objects on the server and objects on the client are different things, and while you write less code up-front because the differences aren’t always immediately obvious, you end up writing a lot more code later because you didn’t think about the very important differences. Representing them as the same thing enables shoddy programmers to not think about the context of where their code will be run.

> “There are only two kinds of languages: the ones people complain about and the ones nobody uses.” -Bjarne Stroustrup