Hi,
Is there an easy javascript way to substract two arrays from eachother ??
array 1 = 1,2,3,4,5
array 2 = 1,3,5
result of subtraction = 2,4
Regards,
Hans
Hi,
Is there an easy javascript way to substract two arrays from eachother ??
array 1 = 1,2,3,4,5
array 2 = 1,3,5
result of subtraction = 2,4
Regards,
Hans
Hi Hans.
create a method with the code below
var A = arguments[0];
var B = arguments[1];
var strA = ":" + A.join("::") + ":";
var strB = ":" + B.join(":|:") + ":";
var reg = new RegExp("(" + strB + ")","gi");
var strDiff = strA.replace(reg,"").replace(/^:/,"").replace(/:$/,"");
var arrDiff = strDiff.split("::");
return arrDiff;
then call this method like var arrDiff = yourMethod(arr1, arr2);
Regards Peter
Thanks peter,
Hans
My mod_js_core module implements a number of handy array methods from the Prototype lib, including “without” : http://www.prototypejs.org/api/array/without
If you think that would be handy, take a look: http://code.google.com/p/servoymodjscore/
greg.
agiletortoise:
My mod_js_core module implements a number of handy array methods from the Prototype lib, including “without” : http://www.prototypejs.org/api/array/withoutIf you think that would be handy, take a look: http://code.google.com/p/servoymodjscore/
greg.
Greg - dumb question most likely (you’d expect nothing less from me of course ), but is there an easy way for us to use these extended JS functions in Servoy? Is it as simple as adding the library or does RHINO need to understand them too somehow? Appreciate a ‘laymans’ overview.
The mod_js_core page I pointed to is my Servoy module that adapts Prototype’s JavaScript extensions to Servoy. So, essentially, the work is already done for you. From the mod_js_core main page:
To use mod_js_core, download and import the module into your Servoy workspace, add the module to a solution, and call “globals.mod_js_core_init();” in your solution onOpen method to extend the environment.
Once you’ve called that global method on the module the Rhino runtime has been extended for the duration of the session (smart or web client) and all those methods are available from anywhere in your code.
You can refer to the Prototype API docs for a references (http://www.prototypejs.org/api). Basically anything that’s not browser specific is implemented, so the Ajax/DOM (Form, document, $, etc.) stuff is not there, since it’s not applicable to Servoy, but the extensions to Class, Object, Array, String, Date, etc. are all implemented as well as the Hash object. The array stuff is some of the most useful.
Let me know if you try it out, I’d be happy to answer questions.
Doh… Told you it was a dumb question …
You are a gentleman and a scholar Mr Pierce !
i have my doubts on both points, but thanks anyway.
I guess these modules are 4.x based and are not suitable for 3.5.9 ??
Regards,
Hans
Correct. These extensions require full support of JavaScript functions, which are not available in versions prior to 4.0.