insert does take planning to design for, but remember its simple definition for verb v, v/ 1 2 3 4 is:
1 v 2 v 3 v 4 which is: 1 v (2 v (3 v 4)) so that wont work here (because y argument to dyadic v gets modified to be the result of rightmost reduction), but dyadic \ I think does: 2 (1-%)/\ 100, 100 + i:2 _0.0204082 0.010101 0.01 0.00990099 0.00980392 2 (1-%)/\ i.10 1 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 0.111111 of 2 (1-~ %~)/\ i.10 _ 1 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 ----- Original Message ----- From: Joe Bogner <[email protected]> To: [email protected] Cc: Sent: Monday, February 17, 2014 6:30:59 AM Subject: [Jprogramming] calculating % change over an array >From the J in 5 minutes thread, I'm starting to build my example In my example, I'm working with stock prices. One of the the outputs is a daily % change over the previous day I want the code to be clean. Is there a cleaner way to express this, or would this be considered fine? I want to calculate % change of y over x Nums=.i.10 pctChange=:3 : '((}. y) % (}: y)) -1' pctChange Nums _ 1 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 pctChange 4 5 3 0.25 _0.4 It seemed like I should have been able to do something with Insert, but I can't figure it out. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
