as a single more general function

a: ;@:(] <@(# # {. );.1~ 1 (0}) -.@=  
)'';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';''


  0 ;@:(] <@(# # {. );.1~ 1 (0}) -.@=  ) 0 33 0 0 22 0 0 11 0 0 0 
0 33 33 33 22 22 22 11 11 11 11



----- Original Message -----
From: 'Pascal Jasmin' via Programming <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Monday, January 5, 2015 11:26 AM
Subject: Re: [Jprogramming] Forward fill w/o looping

dyadic ;. is your usual friend in these cases.  Though Raul has often found 
even more elegant approaches.

a: (-.@=  <;.1 ] )'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' 
┌──────┬─────┬───────┬───────┬─────┐ 
│┌──┬┬┐│┌──┬┐│┌───┬┬┐│┌───┬┬┐│┌──┬┐│ 
││Hi│││││Ho││││hee│││││haw│││││Yo│││ 
│└──┴┴┘│└──┴┘│└───┴┴┘│└───┴┴┘│└──┴┘│ 
└──────┴─────┴───────┴───────┴─────┘

; (# # {. )each a: (-.@=  <;.1 ] 
)'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' 
┌──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐ 
│Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│ 
└──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘

its a bit more complicated with possible leading blank: (this still works 
without leading blank)

; (# # {. ) each a: (] <;.1~ 1 (0}) -.@=  
)'';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';'' 
┌┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐ 
││Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│ 
└┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘




----- Original Message -----
From: Devon McCormick <[email protected]>
To: J-programming forum <[email protected]>
Cc: 
Sent: Monday, January 5, 2015 11:06 AM
Subject: [Jprogramming] Forward fill w/o looping

I just threw together a short J solution that does what I want but it uses
a loop and a conditional.  I'm thinking there's got to be some kind of
loopless prefix sort of solution but am at a loss to come up with it.

My code looks like this:

fillEmptyFwd=: 3 : 0
for_ix. i.<:#y do.
    if. 0=#>y{~>:ix do. y=. (ix{y) (>:ix)}y end.
end.
y
)

An example usage would be this:

   fillEmptyFwd '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';''
++--+--+--+--+--+---+---+---+---+---+---+--+--+
||Hi|Hi|Hi|Ho|Ho|hee|hee|hee|haw|haw|haw|Yo|Yo|
++--+--+--+--+--+---+---+---+---+---+---+--+--+

Any ideas on something less loopy/conditional?

-- 
Devon McCormick, CFA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to