Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. // These apply before words are pig latined
  2. var palindrome=w=>w.length<2||(w=w.replace(/[^A-Za-z]/ig,''))[0]===w[n=w.length-1]&&palindrome(w.slice(1,n))
  3. var short_text = (w,len) => w.length <= (len||3);
  4. var rand_word = () => Math.random() > .9;
  5. var has_vowel = w=>!w.search(/[aeiou]+/)
  6. var len_is_prime = w=>w.replace(/./g,'1').search(/^1?$|^(11+?)\1+$/)==-1 // Jazzzzz handssssss
  7. var style_arrs = [[palindrome, 'color:red'], // 1 - Is the word a palindrome
  8. [len_is_prime,'background-color:blue'], // 2 - Is the length of the word a prime number
  9. [short_text, 'font-family:courier'], // 3 - Is the length of the word less than 3
  10. [true, (w=>'font-size:'+(w.length*2)+'px')], // 4 - Sets the font size to twice the words length
  11. [rand_word,'font-weight:bold'], // 5 - Bolds random words
  12. [has_vowel,'color:green'], // 6 - Turns words with consecutive vowels green
  13. [true,(w=>'font-style:'+rand_in(['normal','italic','oblique']))]] // 7 - Applys random font styles
  14.  
  15. // I'm so sorry
  16. var pig_latin = w => w.replace(/[^a-z]/gi,'').replace(/^([^aeiou]*)([aeiou].*)$/,"$2$1ay"); // 8 - anslatesTray ordway otay igpay atinlay
  17. var altCaps = w=>w.length>1?w[0].toUpperCase()+w[1].toLowerCase()+altCaps(w.slice(2)):w // 9 - MaKeS TeXt LoOk LiKe ThIs
  18. var backwards_sometimes = w => Math.random() < .1 ? w.split('').reverse().join('') : w // 10 - Occasionally turns txet backward
  19.  
  20. // Map the functions
  21. var add_styles = (a,s) => a.length?[(w=[s,a].map(n=>n.shift()))[0]?'<span style=\"'+w[0].map(x=>x?x+';':'').join('')+'\">'+w[1]+'</span>':'',...add_styles(a,s)]:'';
  22. var styles = add_styles(text_arr.map(pig_latin).map(altCaps).map(backwards_sometimes), text_arr.map(w=>style_arrs.map(f=>f[0]==true?f[1](w):f[0](w)&&f[1])))
  23. text_elem.innerHTML = styles.join(' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement