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..
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);
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
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?
@@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. :)
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.
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
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.
This was a very informative session . Thank you ,Chuck.
Thank you!
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..
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);
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
Let me share my screenshot from
My system with log.
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?
@@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. :)
Why do we use new keyword in case of prototype script include?
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.
That’s helpful! Thanks!
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
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.