← Back to challenges

Seven Segment Display

JavaScriptHardlogicnumbers

Instructions

The table below shows which of the segments a through g are illuminated on the seven segment display for the digits 0 through 9. When the number on the display changes, some of the segments may stay on, some may stay off, and others change state (on to off, or off to on).

Create a function that accepts a string of digits, and for each transition of one digit to the next, returns an array of the segments that change state. Designate the segments that turn on as uppercase and those that turn off as lowercase. Sort the arrays in alphabetical order.

For example:

sevenSegment("805") ➞ [["g"], ["b", "e", "G"]]

In the transition from 8 to 0, the g segment turns off. Others are unchanged. In the transition from 0 to 5, b and e turn off and G turns on. Others are unchanged.

DigitLit Segments
0abcdef
1bc
2abdeg
3abcdg
4bcfg
5acdfg
6acdefg
7abc
8abcdefg
9abcfg

Examples

sevenSegment("02") ➞ [["c", "f", "G"]]

sevenSegment("08555") ➞ [["G"], ["b", "e"], [], []]
// Empty arrays designate no change.

sevenSegment("321") ➞ [["c", "E"], ["a", "C", "d", "e", "g"]]

sevenSegment("123") ➞ [["A", "c", "D", "E", "G"], ["C", "e"]]

sevenSegment("3") ➞ []

sevenSegment("33") ➞ [[]]

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.