← Back to challenges

Invert Colors

JavaScriptHarddata_structuresalgebra

Instructions

Create a function that inverts the rgb values of a given tuple.

Examples

colorInvert([255, 255, 255]) ➞ [0, 0, 0]
// (255, 255, 255) is the color white.
// The opposite is (0, 0, 0), which is black.

colorInvert([0, 0, 0]) ➞ [255, 255, 255]

colorInvert([165, 170, 221]) ➞ [90, 85, 34]

Notes

255 is the max value of a single color channel.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Convert All Array Items to String