Re: Update multiple values in vector at once

2015-04-03 Thread Leon Grapenthin
(defn upd-vec [input-vector ids new-values] (apply assoc input-vector (interleave ids new-values))) (upd-vec [0 0 0 0 0] [1 3] [1.44 1.45]) ;=> [0 1.44 0 1.45 0] On Monday, March 30, 2015 at 8:05:44 PM UTC+2, Alexandr wrote: > > Hello everybody, > > How can I update values in the vector give

Re: Update multiple values in vector at once

2015-03-30 Thread Alexandr
Thanks a lot! On Monday, March 30, 2015 at 8:11:25 PM UTC+2, Michał Marczyk wrote: > > (defn upd-vec [input-vector ids new-values] > (reduce-kv #(assoc %1 %3 (new-values %2)) input-vector ids)) > > (upd-vec [0 0 0 0 0] [1 3] [1.44 1.45]) > ;= [0 1.44 0 1.45 0] > > > On 30 March 2015 at 20:05, Al

Re: Update multiple values in vector at once

2015-03-30 Thread Michał Marczyk
(defn upd-vec [input-vector ids new-values] (reduce-kv #(assoc %1 %3 (new-values %2)) input-vector ids)) (upd-vec [0 0 0 0 0] [1 3] [1.44 1.45]) ;= [0 1.44 0 1.45 0] On 30 March 2015 at 20:05, Alexandr wrote: > Hello everybody, > > How can I update values in the vector given vector of id-s a

Update multiple values in vector at once

2015-03-30 Thread Alexandr
Hello everybody, How can I update values in the vector given vector of id-s and new values? For example (defn upd-vec [input-vector ids new-values] ) (upd-vec [0 0 0 0 0] [1 3] [1.44 1.45]) Output: [0 1.44 0 1.45 0] (1st and 3rd elements are replaced) -- You received this message beca