# Comparing variables in Homeyscript for duplicates

**URL:** <https://community.homey.app/t/comparing-variables-in-homeyscript-for-duplicates/46266>\
**Category:** Developers\
**Created:** [April 15, 2021, 10:51am UTC](https://community.homey.app/t/comparing-variables-in-homeyscript-for-duplicates/46266 "2021-04-15T10:51:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [April 15, 2021, 10:51am UTC](https://community.homey.app/t/comparing-variables-in-homeyscript-for-duplicates/46266/1 "2021-04-15T10:51:59Z")

</div>

I am trying to compare better logic variables in homeyscript. The reason is to find duplicate variables. My variables are called RadioDay1, RadioDay2 … RadioDay14.

The variables look like this [http://192.168.178.2:5005/woonkamer/favorite/Deep](http://192.168.178.2:5005/woonkamer/favorite/Deep) House Ibiza

Or filled with the text No Radio Station

Or filled with the text Playlist1, Playlist2 or Playlist3

I compare the variables like this;  
Var n = RadioDay1.localeCompare(RadioDay2)  
When n = 0, there is a duplicate variable.

This works ok, but three of the variables have a different input. The input is instead of e.g [http://192.168.178.2:5005/woonkamer/favorite/Deep](http://192.168.178.2:5005/woonkamer/favorite/Deep) House Ibiza filled with Playlist1, Playlist2 and Playlist3.

When i try this;  
Var n = RadioDay1.localeCompare(RadioDay2)  
If(n = 0 && RadioDay2 != ‘No Radio Station’ && RadioDay3. != ‘No RadioStation’ || RadioDay1.includes(‘Playlist’) === RadioDay3.includes(‘Playlist’))

It always find a duplicate. When i remove the part RadioDay1.includes(‘Playlist’) === RadioDay3.includes(‘Playlist’)) it works and only find real duplicates. So the problem occurs when i try to find variables with the content Playlist

Anyone a idea what i am doing wrong?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [April 15, 2021, 10:55am UTC](https://community.homey.app/t/comparing-variables-in-homeyscript-for-duplicates/46266/2 "2021-04-15T10:55:28Z")

</div>

> [@Marcel\_Ubels](#):
>
> Anyone a idea what i am doing wrong?

You’re using `n = 0` (assignment) instead of `n == 0` (comparison).

And possibly you need to group the comparisons using parentheses.

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [April 15, 2021, 11:35am UTC](https://community.homey.app/t/comparing-variables-in-homeyscript-for-duplicates/46266/3 "2021-04-15T11:35:26Z")

</div>

Oh🙀 Yes is is the most common mistake within js. And i made it also🙃Will try it, also with parentheses

Edit: tried this but still doesn’t work;  
Var n = RadioDay1.localeCompare(RadioDay2)  
If((n == 0 && RadioDay2 != ‘No Radio Station’ && RadioDay3. != ‘No RadioStation’ ) || (RadioDay1.includes(‘Playlist’) === RadioDay2.includes(‘Playlist’))

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [April 15, 2021, 11:52am UTC](https://community.homey.app/t/comparing-variables-in-homeyscript-for-duplicates/46266/4 "2021-04-15T11:52:47Z")

</div>

> [@Marcel\_Ubels](#):
>
> RadioDay1.includes(‘Playlist’) === RadioDay3.includes(‘Playlist’)

What should this do? A comparison seems strange here.

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [April 15, 2021, 12:25pm UTC](https://community.homey.app/t/comparing-variables-in-homeyscript-for-duplicates/46266/5 "2021-04-15T12:25:04Z")

</div>

> [@Marcel\_Ubels](#):
>
> RadioDay1.includes(‘Playlist’) === RadioDay3.includes(‘Playlist’)

RadioDay3 was a typing error, should be RadioDay2.

But it doesn’t work.

When RadioDay1 is filled with Playlist3 and RadioDay2 is filled with Playlist1 it should consider that they are duplicates. In the end when there are duplicates the only thing the program does is placing another variable between the duplicates. That way do not get two the same radio stations in a row or two (different) playlists in a row
