Javasvcript technique 3



Math.random();        //  [0.0 <= x < 1.0] decimal
Math.floor(3.14156);  //  3.0000
Math.ceil(3.14156);     //  4.0000


Math.floor(2224565.5616);  //  2224565
Math.ceil(2224565.5616);    // 2224566


Math.floor(Math.random() * (Max - Min + 1)) + Min; // random num [min < x < max]



Regular Expression


str = "hello world! welcome to programmong."
pattern = /program/gi;    // g is global all occurance , i is ignore case 
str.match(pattern); //    ret  2


Match white space

 \r  enter return
\n  new line
\t  tab
\f  form feed 
" "  space
pattern =  /\s+/g ;  //multi occurance // white space


Match Invert white space


 \R  not enter return
\N   !new line
\T  !tab
\F  !form feed 

str = "hello world!"
pattern = /\S/g;    // g is global all occurance 
str.match(pattern); //    ret  11

Share this

Related Posts

Previous
Next Post »