From a236f732cbecb63116793e2a4e5018511890b894 Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Thu, 24 Sep 2015 10:00:29 -0400 Subject: [PATCH] added a convenience method (jx.utils.join) The function is designed to perform a cartesian product of 2 vectors of the same length. The preconditions must be enforced as always by the calling code @pre : v1.length == v2.length && v1.constructor == v2.constructor && v1.constructor == Array --- utils.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils.js b/utils.js index d92ea73..bc10207 100644 --- a/utils.js +++ b/utils.js @@ -89,6 +89,20 @@ jx.utils.unique = function (list,getKey){ }) } } +jx.utils.join = function(x,y){ + if(x.length != y.length){ + return [] + }else{ + var rec = x ; + for(var i in rec){ + // + //@TODO: Consider the case we are adding to a matrix + // + rec[i] = [x[i],y[i]] + } + return rec ; + } +} /** * Implementation of a few standard design patterns. Their use is user/dependent * For more information on how/when to use a design pattern please use google/wikipedia ;-) @@ -169,3 +183,4 @@ jx.utils.patterns.observer = function(lobservers,init){ * @return array containing casted type */ jx.utils.cast = jx.utils.patterns.visitor ; +