Add "7" to Chords
You're organizing a jazz band, and in jazz music, many chords often have a "7" added to them (like "C7" or "G7"). However, some of the chords in your sheet music are missing the "7". Your task is to go through the list of chords and add a "7" to the end of each chord that doesn't already end with "7".
Instructions:
-
Write a function named
addSevenToChords
that takes an array of chords as input. -
The function should return a new array where the number "7" is concatenated to the end of every chord that does not already end with "7".
-
If a chord already ends with "7", it should remain unchanged.
Note: Only use the map
, filter
, or reduce
methods, or a combination of these methods, to solve the problem. Do not use loops to iterate or perform the operation.
Example 1
Input: addSevenToChords(["E", "F#", "G7", "A#"]);
Output: ["E7", "F#7", "G7", "A#7"]
Example 2
Input: addSevenToChords(["Cmaj7", "D", "Em7", "F"]);
Output: ["Cmaj7", "D7", "Em7", "F7"]
Example 3
Input: addSevenToChords([]);
Output: []
Are you stuck on this problem?
Get detailed, step-by-step solution and improve your JavaScript skills.
- Detailed Explanation: Each solution comes with a comprehensive explanation, helping you understand the logic and concepts thoroughly.
- Learn to Write Better Code: Even if you have written the code, discover ways to improve it and adopt best practices.
- Save Time: Don’t waste hours struggling—get the solution and learn efficiently.
- Lifetime Access: Get access to lifetime solutions for all problems available
" I struggled with this problem for hours, but the solution provided here was clear and easy to follow. It helped me understand where I went wrong and improved my coding skills significantly." - Jane D.
If you're not satisfied, I offer a 7-day money-back guarantee.