Xah Web Dev Blog Archive 2014-05

Array How-To

JavaScript quiz: why doesn't this work?

// JavaScript quiz. Why doesn't this work?

var obj = { "a":3, "b":7, "c":2, "d":9};

var keys = Object.keys(obj);

var sorted_keys = keys.sort(function (a,b) {return obj[a] >= obj[b]});

console.log(sorted_keys);       // [ 'c', 'a', 'b', 'd' ] ??

ANSWER (rot13): orpnhfr gur fbeg zrgubq'f cerqvpngr shapgvba arrqf gb erghea artngvir mreb cbfvgvir, abg gehr snyfr.

Operators (new page)

JS: sum array

// example of writing a sum function
function sum (list) { return list.reduce(function (a,b) {return a+b;} );}

console.log(sum([3,1,2]));          // 6

[see Array.prototype]

[see Functional Programing (old, pre-JS2015)]

now complete. Computer Languages Characters Frequency (with JavaScript + svg charts)

Character, Code Unit, Codepoint (on its own page)

JavaScript DOM “setAttribute” — the pain in functional programing's neck.

CSS: Letter Spacing, Word Spacing

CSS: Font Weight

CSS: Text Decoration: Underline, Overline, Line-Through

What is a Letter in CSS's first-letter Pseudo-element?