Skip to main content
added 19 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now for your second case, you can do something like:

 Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
 VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
 VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...

OR more elegantly:

Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
VectorQ[dateQuantityList[[All,1]], DateListQ] && VectorQ[datePriceList[[All,1]], DateListQ] := ...
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now you can do something like:

 Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
 VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
 VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...

OR more elegantly:

Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
VectorQ[dateQuantityList[[All,1]], DateListQ] && VectorQ[datePriceList[[All,1]], DateListQ] := ...
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now for your second case, you can do something like:

Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...

OR more elegantly:

Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
VectorQ[dateQuantityList[[All,1]], DateListQ] && VectorQ[datePriceList[[All,1]], DateListQ] := ...
added 234 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now you can do something like:

 Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
 VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
 VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...

OR more elegantly:

Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
VectorQ[dateQuantityList[[All,1]], DateListQ] && VectorQ[datePriceList[[All,1]], DateListQ] := ...
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now you can do something like:

 Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
 VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
 VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now you can do something like:

 Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
 VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
 VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...

OR more elegantly:

Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
VectorQ[dateQuantityList[[All,1]], DateListQ] && VectorQ[datePriceList[[All,1]], DateListQ] := ...
added 52 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now you can do something like:

 Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
 VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
 VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now you can do something like:

 Convert[dateQuantityList_, datePriceList_] /; 
 VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
 VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...
Convert[quantities_, prices_] /; Length[quantities] == Length[prices] := ...

Since DateList returns a list of Length 6 and the first five elements have Head Integer while the last has Head Real you can write your own DateListQ. Here is a head start:

 DateListQ[lis_List] := Length[lis] == 6 && VectorQ[Most[lis], IntegerQ] && 
 Head[Last[lis]] == Real

But note that this is an example and if you're inputting your DateList by hand and the last element is also an Integer then you can simply use:

DateListQ[lis_List] := Length[lis] == 6 && VectorQ[lis, IntegerQ]

Now you can do something like:

 Convert[dateQuantityList_, datePriceList_] /; Length[dateQuantityList] == Length[datePriceList] &&
 VectorQ[Map[DateListQ, dateQuantityList[[All, 1]], {1}], TrueQ] &&
 VectorQ[Map[DateListQ, datePriceList[[All, 1]], {1}], TrueQ] := ...
added 227 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176
Loading
added 227 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176
Loading
added 321 characters in body
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176
Loading
Source Link
RunnyKine
  • 33.3k
  • 3
  • 110
  • 176
Loading