Invert Colors

Published by Deep Xavier in

Create a function that inverts the rgb values in an array.

Examples

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

invertColor([12, 13, 200]) ➞ [243, 242, 55]

invertColor([12, 17, 197]) ➞ [243, 238, 58]

invertColor([243, 242, 235]) ➞ [12, 13, 20]

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

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

Notes

255 is the max value of a single color channel.

Watch a quick demo on how Edabit works.