NOWCommunity Live Stream - API Adventures - ArrayUtil()

Поделиться
HTML-код
  • Опубликовано: 8 ноя 2024

Комментарии • 13

  • @irstonantao2375
    @irstonantao2375 4 года назад +1

    This was a very informative session . Thank you ,Chuck.

  • @shammasalhotra9648
    @shammasalhotra9648 4 года назад +1

    Good example of ensurearray...any idea why does it checks from the last value in case of unique? For eg if I use c,h,u,c,k,c then it will show me result of unique as h,u,k,c..

    • @ChuckTomasi
      @ChuckTomasi 4 года назад +1

      I'm not showing ensureArray() does any uniqueness checking. I just did this in scripts background and got back all five elements.
      var a = ['c', 'h', 'u', 'c', 'k'];
      var e = new ArrayUtil().ensureArray(a);
      gs.info(e);

    • @shammasalhotra9648
      @shammasalhotra9648 4 года назад

      Sorry I meant for unique function only...unique function is checking from
      Last value..for e.g if I use c,h,u,c,k,c then it will show me result of unique as h,u,k,c

    • @shammasalhotra9648
      @shammasalhotra9648 4 года назад

      Let me share my screenshot from
      My system with log.

    • @shammasalhotra9648
      @shammasalhotra9648 4 года назад

      See this:
      Var a = [‘c’,’h’,’u’,’c’,’k’,’c’];
      Var e = new ArrayUtil().unique(a);
      gs.info(e);
      Result is h,u,k,c
      It checked and retained c which was last one..does it work like this only?

    • @ChuckTomasi
      @ChuckTomasi 4 года назад +1

      @@shammasalhotra9648 It has to do with the way they set up the nested loops. If you look at the ArrayUtil script include and follow the JavaScript code in the unique function, you can see how/why it's doing what it's doing. It may not have been the way I would have built it, but it works and there it is. If you like, you can always create your own that returns results in the order you prefer. :)

  • @shammasalhotra9648
    @shammasalhotra9648 4 года назад +1

    Why do we use new keyword in case of prototype script include?

    • @ChuckTomasi
      @ChuckTomasi 4 года назад +1

      When using the prototype script includes, they are just a "blueprint" of what you need. the "new" keyword instantiates an object from the class defined.

    • @shammasalhotra9648
      @shammasalhotra9648 4 года назад

      That’s helpful! Thanks!

  • @umairsyed7465
    @umairsyed7465 4 года назад +1

    Hi Chuck, I used ArrayUtil to get unique values it didn't worked couple of weeks before and have not used 'Global' while calling the ArrayUtil as my script include was already written in Global scope

  • @subhashKaushal
    @subhashKaushal 4 года назад

    Javascript do not natively support Associative array. The only option we have is to have an array of objects if we need to maintain a key value pair or to use javascript map for arrays. If we get any function to support variable indexing, that would be a great use of this class.