Results for “Arrays & embedded state”
Small, practical examples. Search by task or narrow things down below.
Use named states for a controller
Arduino / C: An enum makes state transitions easier to read than unexplained numbers.
Arduino / C✓ Tested
Advance an index around a fixed collection
Arduino / C: Modulo wraps a bounded nonnegative index to zero.
Arduino / C✓ Tested
Dispatch a command through function pointers
Arduino / C: A small function table can map validated command indices to actions.
Arduino / C✓ Tested
Find a sample range in one pass
Arduino / C: Initialize extrema from the first element of a nonempty array.
Arduino / C✓ Tested
Find a value in a small lookup table
Arduino / C: A linear scan is simple and predictable for a small fixed array.
Arduino / C✓ Tested
Group related readings in a struct
Arduino / C: A struct keeps a sample’s fields together without dynamic allocation.
Arduino / C✓ Tested
Keep a counter from wrapping at its maximum
Arduino / C: Increment only when the value is below its limit.
Arduino / C✓ Tested
Reject insertion when a fixed queue is full
Arduino / C: Track a count separately from circular read and write positions.
Arduino / C✓ Tested
Sort a small array in place
Arduino / C: Insertion sort needs no additional array and is suitable for small datasets.
Arduino / C✓ Tested
Store samples in a fixed-size ring buffer
Arduino / C: The write position wraps while the storage size stays constant.
Arduino / C✓ Tested
Allow embedded scripts without granting same-origin access
HTML: Grant only allow-scripts so the sandboxed document retains an opaque origin.
HTML✓ Tested
Append to an array without mutating state
Append to an array without mutating state with a small React component and explicit browser behavior.
React✓ Tested