Skip to main content
save 2 bytes by shuffling scale order, removing redundant +
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75

Javascript 281280 282 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[-2,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
[...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]]
.map(i=>(+i+'Di-x+'D EF G A BC'.search(z[1][0])+!!z[1][1]+8-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l



document.getElementById("mysubmit").onclick=function() {
  document.getElementById("out").innerHTML=f(document.getElementById("myinput").value)
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">
<pre id="out"></pre>

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

Javascript 281 282 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[-2,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
[...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]]
.map(i=>(+i+'D EF G A BC'.search(z[1][0])+!!z[1][1]+8-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l



document.getElementById("mysubmit").onclick=function() {
  document.getElementById("out").innerHTML=f(document.getElementById("myinput").value)
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">
<pre id="out"></pre>

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

Javascript 280 282 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[-2,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
[...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]]
.map(i=>(i-x+'D EF G A BC'.search(z[1][0])+!!z[1][1]+8)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l



document.getElementById("mysubmit").onclick=function() {
  document.getElementById("out").innerHTML=f(document.getElementById("myinput").value)
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">
<pre id="out"></pre>

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

save a byte by shuffling scale order
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75

Javascript 282281 282 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[10,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
[...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]]
.map(i=>(+i+'A BC D EF G'.search(z[1][0])+!!z[1][1]+15-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l


document.getElementById("mysubmit").onclick=function() {
  console.log(f(document.getElementById("myinput").value))
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">
f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[-2,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
[...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]]
.map(i=>(+i+'D EF G A BC'.search(z[1][0])+!!z[1][1]+8-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l



document.getElementById("mysubmit").onclick=function() {
  document.getElementById("out").innerHTML=f(document.getElementById("myinput").value)
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">
<pre id="out"></pre>

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

Javascript 282 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[10,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
[...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]]
.map(i=>(+i+'A BC D EF G'.search(z[1][0])+!!z[1][1]+15-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l


document.getElementById("mysubmit").onclick=function() {
  console.log(f(document.getElementById("myinput").value))
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

Javascript 281 282 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[-2,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
[...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]]
.map(i=>(+i+'D EF G A BC'.search(z[1][0])+!!z[1][1]+8-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l



document.getElementById("mysubmit").onclick=function() {
  document.getElementById("out").innerHTML=f(document.getElementById("myinput").value)
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">
<pre id="out"></pre>

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

save a couple of bytes replacing ().split`` with [...]
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75

Javascript 287282 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[10,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
([...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]).split``[z[2]]]
.map(i=>(+i+'A BC D EF G'.search(z[1][0])+!!z[1][1]+15-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l


document.getElementById("mysubmit").onclick=function() {
  console.log(f(document.getElementById("myinput").value))
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

Javascript 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[10,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
('9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]).split``
.map(i=>(+i+'A BC D EF G'.search(z[1][0])+!!z[1][1]+15-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l


document.getElementById("mysubmit").onclick=function() {
  console.log(f(document.getElementById("myinput").value))
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

Javascript 282 287 bytes

(Non-meaningful linebreaks inserted for readability)

f=

a=>' G C E A'+[1,2,3,4,5].map(y=>
(l=`
---------
`)+[10,3,7,0].map(
x=>(z=a.match(/(.#?)(.*)/),
[...'9'+{'':14,7:147,m:40,m7:740,maj7:148,sus4:24,dim:30,dim7:360}[z[2]]]
.map(i=>(+i+'A BC D EF G'.search(z[1][0])+!!z[1][1]+15-x)%12)
.sort((a,b)=>a-b)[0]-y?'| ':'|#'
)).join``+'|').join``+l


document.getElementById("mysubmit").onclick=function() {
  console.log(f(document.getElementById("myinput").value))
}
<input type="text" value="G7" id="myinput">
<input type="submit" id="mysubmit">

Commentary

I've never been so happy at Javascript's weird type conversions. This is probably the first time I've ever wanted 40 + 9 to equal 409 :) It's also really fortunate that integers are acceptable as keys in Objects.

There's nothing too clever going on here. I subtract 3 from each chord note in order to keep the range within 0-9, so that I can temporarily express a chord as a 3-digit number. Luckily, the order of notes isn't important, so we can express 036 as 360.

shave a byte, format
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75
Loading
deleted 2 characters in body
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75
Loading
-1
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75
Loading
added 485 characters in body
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75
Loading
deleted 6 characters in body
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75
Loading
deleted 73 characters in body
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75
Loading
Source Link
Steve Bennett
  • 8.1k
  • 23
  • 75
Loading