Results 1 to 3 of 3

Thread: [JavaScript] Useful Methods

  1. #1

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    [JavaScript] Useful Methods

    Here are some useful JavaScript extensions:
    Code:
    eval("(2 13(a,s,t,r,S,T,F){a.i=2(m,i){8(i=i||0;i<3.5;i++)9(3[i]11m)6 i;6-1};a.n=2(f,i){f=f||r;8(i=0;i<3.5;i++)9(f(3[i]))6 T;6 F};a.l=2(f,i){f=f||r;8(i=0;i<3.5;i++)9(!f(3[i]))6 F;6 T};a.w=2(f,i,R,h){h=3;f=f||r;R=[];8(i=0;i<h.5;i++)9(f(h[i]))R.push(h[i]);6 R};s.i=''.indexOf;s.s=2(x,i){9(t(x)11S)6 x.5<=3.5&&3.4(0,x.5)11x;7 8(i=0;i<x.5;i++)9(3.s(x[i]))6 T};s.e=2(x,i){9(t(x)11S)6 x.5<=3.5&&3.4(3.5-x.5,3.5)11x;7 8(i=0;i<x.5;i++)9(3.e(x[i]))6 T};s.t=2(c,i,h,f){h=3;9(!c)6 h.t([\"\\n\",\"\\t\",\" \"]);7 9(t(c)11S){10(h.s(c))h=h.4(c.5);10(h.e(c))h=h.4(0,h.5-c.5)}7{f=T;10(f){f=F;8(i=0;i<c.5;i++){9(h.s(c[i]))h=h.4(c[i].5);7 9(h.e(c[i]))h=h.4(0,h.5-c[i].5);7 continue;f=T;break}}}6 h};})(Array.12,String.12,2(x){6 typeof x},2(x){6 x},'string',true,false);".replace(/\d+/g,function(x){return'0 1 function this substring length return else for if while === prototype minitech'.split(' ')[x]}))
    It contains Array indexOf (i), all (l), any (n), where (w) functions and String startsWith (s), endsWith (e), indexOf (i) and trim (t) functions.

    This code was manually minified right from the start (it was incredibly hard to write) so please don't steal it! Size: 886 bytes.
    Last edited by minitech; Sep 25th, 2011 at 11:30 AM.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [JavaScript] Useful Methods

    Do you mind explaining how to use it ?

    You always post great entries in the CodeBank. But newbies like me would find it much difficult for testing it.

    So, my suggestion is, provide some examples on how to use it.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: [JavaScript] Useful Methods

    Place the line from #1 in your code, and use the functions:

    • Array all:
      Code:
      [1, 2, 3, 4, 5].l(function(x) { return x <= 5; })
      returns true because all of them are less than 5.
    • Array any:
      Code:
      [1, 2, 3, 4, 5].n(function(x) { return x >= 6; })
      returns false because no element is more than or equal to 6.
    • Array where:
      Code:
      [1, 2, 3, 4, 5].w(function(x) { return x % 2 === 0; })
      returns [2, 4]; the only numbers in the array that are odd.
    • String startsWith:
      Code:
      "Hello world".s("Hello")
      returns true because "Hello world" starts with "Hello".
    • String endsWith is along the same lines as startsWith, and it's named "e".
    • String indexOf is the default functionality with the shorter name of "i".
    • String trim trims characters from both sides:
      Code:
      "tttFit".t('t')
      returns "Fi" because 't's have been trimmed off both sides. If passed no argument, null or a blank string, it trims spaces.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width