# Tips on streamlining this function

**URL:** https://discourse.nodered.org/t/tips-on-streamlining-this-function/33092
**Category:** General
**Created:** [19 September 2020 18:44 UTC](https://discourse.nodered.org/t/tips-on-streamlining-this-function/33092 "2020-09-19T18:44:24Z")
**Posts on this page:** 3
**Page:** 2

<div class="post-metadata">

### Author: ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)
#### Post date: [21 September 2020 09:17 UTC](https://discourse.nodered.org/t/tips-on-streamlining-this-function/33092/21 "2020-09-21T09:17:38Z")

</div>

> [@TotallyInformation](#):
>
> That is certainly a case of over-streamlining.

As they say, be careful what you wish for! 😄  
Thanks for the help 👍

---

<div class="post-metadata">

### Author: ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)
#### Post date: [21 September 2020 09:47 UTC](https://discourse.nodered.org/t/tips-on-streamlining-this-function/33092/22 "2020-09-21T09:47:44Z")

</div>

> [@877](#):
>
> I feel there is some way to cut it down in a clever way:

When you need to do some json mapping you can always consider using a jsonata expression in a change node.

```auto
[ [ 
    /* Power */
    { "payload" : payload.power ? 1 : 0,
      "pin" : 71 },
    /* Filter */
    { "payload" : payload.filter ? 1 : 0,
      "pin" : 74 },
    /* Heat */ 
     { "payload" : ( payload.heat or payload.heater ) ? 1 : 0,
      "pin" : 75 },   
    /* Celsius */
    { "payload" : payload.celsius ? 1 : 0,
      "pin" : 76 },   
    /* Air */
    { "payload" : payload.air? 1 : 0,
      "pin" : 77 },   
    /* Locked */
    { "payload" : payload.locked ? 1 : 0,
      "pin" : 79 } 
] ]

```

You can validate this using:

- [https://try.jsonata.org/IBisAjDVy](https://try.jsonata.org/IBisAjDVy)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [20 November 2020 09:47 UTC](https://discourse.nodered.org/t/tips-on-streamlining-this-function/33092/23 "2020-11-20T09:47:59Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/tips-on-streamlining-this-function/33092.md?page=1)
