# Labor shift calculation using array.includes() method

**URL:** <https://discourse.nodered.org/t/labor-shift-calculation-using-array-includes-method/62863>\
**Category:** General\
**Created:** [19 May 2022 18:37 UTC](https://discourse.nodered.org/t/labor-shift-calculation-using-array-includes-method/62863 "2022-05-19T18:37:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [19 May 2022 18:37 UTC](https://discourse.nodered.org/t/labor-shift-calculation-using-array-includes-method/62863/1 "2022-05-19T18:37:10Z")

</div>

I've got a timestamp inject node going through a date-time formatter to only output the hour of day.

I'm trying to calculate the current shift, 1st, 2nd, or 3rd based on the out of day using the array.includes() method but don't have it quite right.

```auto
// Payload is the hour of day in order to perform a shift
// calculation. 

const first = [07, 08, 09, 10, 11, 12, 13, 14];
const second = [15, 16, 17, 18, 19, 20, 21, 22];
const third = [23, 24, 01, 02, 03, 04, 05, 06];

if (first.includes(msg.payload)) {
 shift = 1;
}
if (second.includes(msg.payload)) {
 shift = 2;
}
if (third.includes(msg.payload)) {
 shift = 3;
}
return shift;

```

What am I doing wrong?

Thanks,  
Richard

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 May 2022 18:44 UTC](https://discourse.nodered.org/t/labor-shift-calculation-using-array-includes-method/62863/2 "2022-05-19T18:44:42Z")

</div>

I would say 01, 02, 03, 04, 05, 06, 07, 08, 09 are not valid numbers, so I would ask what is the msg.payload a number or a string.

Then you return shift which is a number, but you have to return a object. So it would be something like `return {payload: shift};`

[edit] If payload is a string i would do something like this

```auto
const payload = Number(msg.payload);
if (payload >= 7 && payload <= 14) {
    msg = {payload: 1};
}else if (payload >= 15 && payload <= 22) {
    msg = {payload: 2};
}else if (payload >= 23 || payload <= 6) {
    msg = {payload: 3};
}else{
    msg = null;
}
return msg;

```

---

<div class="post-metadata">

**Author:** ![hobbes1069](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hobbes1069/32/39892_2.png) [@hobbes1069](https://discourse.nodered.org/u/hobbes1069)\
**Post date:** [19 May 2022 18:49 UTC](https://discourse.nodered.org/t/labor-shift-calculation-using-array-includes-method/62863/3 "2022-05-19T18:49:22Z")

</div>

Awesome. That was it! (in both cases!)

Thanks,  
Richard

---

<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:** [18 July 2022 18:49 UTC](https://discourse.nodered.org/t/labor-shift-calculation-using-array-includes-method/62863/4 "2022-07-18T18:49:33Z")

</div>

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