Solutions to "Just KNIME It!" Challenge 4

I’m Node Golfing this question again. I’m using something that felt natural to me, but was apparently not so obvious to others, so I should mention it:

Declaring variables in the Java Snippet node at the place the editor tells us to actually creates global variables that retain their value between rows. Variables declared within the expression section do not have that property. You can read more about that in @takbb’s wonderful thread here:

That “feature” allows us to skip the lag column, because it allows the Java Snippet “retrograde row access”. It’s quite simple: Store the price value in a variable to compare against it in the next row. To prevent accessing an uninitialised variable, shortcut evaluation in if-tests is leveraged in row 0.

PS’ses:
@goodvirus your lag node drops the first row the way you configured it
@gonhaddock There’s a file with sample data in the challenge post. Your very interesting solution works with the actual data just as fine though :wink:

3 Likes