apriori.js
apriori.js copied to clipboard
benefit dictionary lookup instead of foreach
Heyy
Thanks for this amazing code.
I am using it and thought let's look at performance profiler, most execution time is in two nested for-each loops. You can benefit dictionary lookup here.
Result: Much gain !
Note: I don't know anything about packaging JavaScript apps, bower or even how you are testing stuff. I assume you change accordingly if you agree.
Thanks again (I am using this somewhere in my repos).
in
ArrayUtils.isSubSetArrayOf = function(targetArray, superSetArray) {
var isSubSetArray = true;
targetArray.forEach(function(item) {
if (isSubSetArray && superSetArray.indexOf(item) === -1)
isSubSetArray = false;
});
return isSubSetArray;
};
You may also consider sorting before checking if all elements of targetArray are in superSetArray.
My intuition says it would be faster.
Kindly see the solution here: https://stackoverflow.com/a/8628118/9164621
edit:
I tested the solution using sorting, it turned out very greedy. I think sort of Strings in Javascript is very greedy.
@bacloud14 Hi, thanks for your interest in this library! It seems your improvement should be valid and should be applied. However, this project is so old that we need to start repairing the build config 😅 (getting rid of Grunt, and so on - probably).
Although I don't have the bandwidth to work on this project now, once we manage to fix the build settings and verify your change works, I'm happy to merge your improvement and ship a new version!
ok, many thanks for your attention.