← Back to challenges

Enharmonic Equivalents

JavaScriptHardstringsformatting

Instructions

In music, notes can be written out in multiple ways (especially for notes on the black keys). Although these notes are spelled out differently, they still are the same note physically.

C# = Db, D# = Eb, F# = Gb, G# = Ab, A# = Bb

Given a musical note, create a function that returns its enharmonic equivalent. The examples below should make this clear.

Examples

getEquivalent("D#") ➞ "Eb"

getEquivalent("Gb") ➞ "F#"

getEquivalent("Bb") ➞"A#"

Notes

  • Note names will always be a capital letter followed by either # or b.
  • Remember that the note after G is A and vice versa.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Don't Roll Doubles!