Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Simplifying the cycle function for toggling #116

Open
justinyaodu opened this issue Aug 9, 2021 · 0 comments
Open

Simplifying the cycle function for toggling #116

justinyaodu opened this issue Aug 9, 2021 · 0 comments

Comments

@justinyaodu
Copy link

I believe the cycle function can be simplified when there are only two elements to toggle between:

arr=(true false)

toggle() {
    printf '%s ' "${arr[${i:=0}]}"
    ((i=1-i)) # ((i=i^1)) also works
}

What do you think?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant