# Ternary Comparison Assignment Operators

**URL:** <https://es.discourse.group/t/ternary-comparison-assignment-operators/943>\
**Category:** 💡 Ideas\
**Created:** [August 23, 2021, 9:53am UTC](https://es.discourse.group/t/ternary-comparison-assignment-operators/943 "2021-08-23T09:53:55Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![graphemecluster](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/graphemecluster/32/957_2.png) [@graphemecluster](https://es.discourse.group/u/graphemecluster)\
**Post date:** [December 4, 2021, 5:59pm UTC](https://es.discourse.group/t/ternary-comparison-assignment-operators/943/5 "2021-12-04T17:59:50Z")

</div>

You should definitely keep the index instead of a literal for what you called a cycle list:

```javascript
class CycleList {
	constructor(array) {
		this.array = array;
		this.value = 0;
	}
	get curr() {
		return this.array[this.value %% this.array.length];
	}
	get next() {
		return this.array[++this.value %% this.array.length];
	}
	get prev() {
		return this.array[--this.value %% this.array.length];
	}
	step(offset) {
		return this.array[(this.value += offset) %% this.array.length];
	}
	*[Symbol.iterator]() {
		while (true) {
			yield this.next;
		}
	}
}
const list = new CycleList(["ascending", "descending", "unspecified"]);
list.curr; // "ascending"
list.next; // "descending"
list.step(-2); // "unspecified"

```

Notice that it uses the proposed [Modulo Operator %%](https://es.discourse.group/t/modulo-operator/126).

---

_[View the full topic](https://es.discourse.group/t/ternary-comparison-assignment-operators/943)._
