Xah Web Dev Blog Archive 2014-05

JS: 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.

JS: 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 JS: Array.prototype

〔►see JS: Functional Programing

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

JS: String Code Unit vs Code Point (on its own page)

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

CSS: Letter Spacing, Word Spacing

CSS: Font Weight, Bold

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

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

CSS: Match first-letter and first-line

Like what you read? Buy JavaScript in Depth