Wednesday, July 14, 2010

Creative Theory Machine Buttons



In the category of creative Theory Machine buttons:
  • ifSixWasNine, by Jared Hendricks (a.k.a. "Jimi" ;-)

    alert(ifSixWasNine(6)) ==> 9
    alert(ifSixWasNine(12)) ==> 18

Tuesday, July 13, 2010

The replace() method for Strings

String theory?Image by trailfan via Flickr
The replace() method searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring. It searches the string on which it is called for matches.

If the g flag is set, the method replaces all matches in the string with the replacement string; otherwise it replaces only the first match it finds.

EXAMPLES

//replaces first match
//wasit a rat i saw
var s = 'was it a rat i saw'; alert(s.replace(/[ ]/, ''))

//replaces all matches
//wasitaratisaw
var s = 'was it a rat i saw'; alert(s.replace(/[ ]/g, ''))
Enhanced by Zemanta

Monday, July 12, 2010

On Palindromes

la porte du palindrome / the palindrome doorImage by TisseurDeToile -[*] via Flickr



Example from class:

var s = "Too Hot, to Hoot!!"
var arr = s.split(' ')
var result = ''


//process all words in sentence
for(var i = 0; i < arr.length; ++i)
//result = result + encode(arr[i]) + ' '
arr[i] = encode(arr[i])



Example from Class

var s = "Radar, mom!"
var arr = s.split(' ')
var i = 0


//check words
//not quite there yet..
while(isPalindrome(arr[i]) && i < arr.length){
++i
}

//determine result
if(i == arr.length)
//every word is a pal
else
//not all words are pals
Enhanced by Zemanta

xhtml: logical vs physical tags

Just a random blob with "XHTML" writ...Image via Wikipedia

HTML includes two types of Style Tags:

  • logical (a.k.a. phrase elements)
    tag the information according to its meaning (e.g., abbr, acronym, code, etc.)
  • physical
    tag the exact appearance of the information (i.e. b, i, etc.)
Both <em> and <i> display italics. CSS is the preferred way to style content rather than logical tags. Logical style tags are preferred over physical tags (which is why the latter are deprecated in xhtml).

Rationale: the goal in xhtml is to separate structure elements from style elements, and remove the latter from xhtml. Content should be styled with CSS rather than xhtml. Logical tags describe the structure or semantics of content and are, therefore, preferred over style elements like <b> and <i>.
Enhanced by Zemanta