# Solutions to "Just KNIME It!" Challenge 4

**URL:** <https://forum.knime.com/t/solutions-to-just-knime-it-challenge-4/39872>\
**Category:** Just KNIME It!\
**Tags:** justknimeit\
**Created:** [February 16, 2022, 2:11pm UTC](https://forum.knime.com/t/solutions-to-just-knime-it-challenge-4/39872 "2022-02-16T14:11:09Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Thyme](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thyme/32/34550_2.png) [@Thyme](https://forum.knime.com/u/Thyme)\
**Post date:** [February 16, 2022, 4:30pm UTC](https://forum.knime.com/t/solutions-to-just-knime-it-challenge-4/39872/7 "2022-02-16T16:30:45Z")

</div>

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:

> [@Java snippets have long memories!...](https://forum.knime.com/t/java-snippets-have-long-memories/33125):
>
> Hi all, Before you get reading what is maybe a tl;dr… I should say this isn’t asking a question or raising a problem, but is just a discussion/interest point related to java snippets! wink For some of you, what I am writing here won’t come as a surprise, but I thought it worth writing as it might avoid the mistake I made, and it also can potentially be quite useful. While playing with Java snippets I was surprised to stumble on some interesting behaviour. I had “incorrectly” initialised th…

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.

 ![JKI_004](https://forum-cdn.knime.com/uploads/default/original/3X/c/4/c4ed14c64da03b5bf3164db42c58e22da4c6e7e3.png)

> **[JKI\_004 – thyme](https://hub.knime.com/thyme/spaces/Public/Just%20KNIME%20It!/JKI_004~kZj4XLD_3JkYGPA9/current-state)**
>
> There has been no description set for this workflow's metadata.

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 😉

---

_[View the full topic](https://forum.knime.com/t/solutions-to-just-knime-it-challenge-4/39872)._
