Skip to main content
saved 6 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 8680 bytes

-6 thanks to @tsh

Inspired by Neil's method.

Expects ([a, b]).

f=(a,b)=>b>a?f(b,a):c=>(/t[hd][dt],h/.test(a+b[b,a]=c.sort())?"spade":a)+" and "+(/[dt]dd,[dh]/.test(a+bc)?"club":b)

Try it online!Try it online!

Commented

f = (a, b)c =>      // a = 1st string, b// c[] = 2ndinput stringarray
b >( a ?            // if b is greater than a:
  f(b/[dt], a)     h/     // if a swapis a"heart" and b
:         is
  .test(       // else:
  (    either "heart" or "diamond",
    [b, a] =   //
  where a and /t[hd]/b are sorted such
     // c.sort() // ifthat a is "heart" and> b is either:
    .test(a + b) ? //   "heart" or "diamond":
    //
  "spade"  "spade"    //     use "spade" as the left output
    :              //   else:
      a            //     use a
  ) +              //
  " and " +        //   append " and "
  (                //
    /[dt]dd,[dh]/        //   if ab is either "diamond" or "heart"
and a is
  .test(a + bc) ? //  // andeither b"diamond" isor "diamond""heart":
      "club"       //     use "club" as the right output
    :              //   else:
      b            //     use b
  )                //

JavaScript (ES6), 86 bytes

Inspired by Neil's method.

f=(a,b)=>b>a?f(b,a):(/t[hd]/.test(a+b)?"spade":a)+" and "+(/[dt]d/.test(a+b)?"club":b)

Try it online!

Commented

f = (a, b) =>      // a = 1st string, b = 2nd string
b > a ?            // if b is greater than a:
  f(b, a)          //   swap a and b
:                  // else:
  (                //
     /t[hd]/        //   if a is "heart" and b is either
    .test(a + b) ? //   "heart" or "diamond":
      "spade"      //     use "spade" as the left output
    :              //   else:
      a            //     use a
  ) +              //
  " and " +        //   append " and "
  (                //
    /[dt]d/        //   if a is either "diamond" or "heart"
    .test(a + b) ? //   and b is "diamond":
      "club"       //     use "club" as the right output
    :              //   else:
      b            //     use b
  )                //

JavaScript (ES6), 80 bytes

-6 thanks to @tsh

Inspired by Neil's method.

Expects ([a, b]).

c=>(/[dt],h/.test([b,a]=c.sort())?"spade":a)+" and "+(/d,[dh]/.test(c)?"club":b)

Try it online!

Commented

c =>           // c[] = input array
(              //
  /[dt],h/     // if a is "heart" and b is
  .test(       // either "heart" or "diamond",
    [b, a] =   // where a and b are sorted such
      c.sort() // that a > b:
  ) ?          //
    "spade"    //   use "spade" as the left output
  :            // else:
    a          //   use a
) +            //
" and " +      // append " and "
(              //
  /d,[dh]/     // if b is "diamond" and a is
  .test(c) ?   // either "diamond" or "heart":
    "club"     //   use "club" as the right output
  :            // else:
    b          //   use b
)              //
added a commented version
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 86 bytes

Inspired by Neil's method.

f=(a,b)=>b>a?f(b,a):(/t[hd]/.test(a+b)?"spade":a)+" and "+(/[dt]d/.test(a+b)?"club":b)

Try it online!

Commented

f = (a, b) =>      // a = 1st string, b = 2nd string
b > a ?            // if b is greater than a:
  f(b, a)          //   swap a and b
:                  // else:
  (                //
    /t[hd]/        //   if a is "heart" and b is either
    .test(a + b) ? //   "heart" or "diamond":
      "spade"      //     use "spade" as the left output
    :              //   else:
      a            //     use a
  ) +              //
  " and " +        //   append " and "
  (                //
    /[dt]d/        //   if a is either "diamond" or "heart"
    .test(a + b) ? //   and b is "diamond":
      "club"       //     use "club" as the right output
    :              //   else:
      b            //     use b
  )                //

JavaScript (ES6), 86 bytes

Inspired by Neil's method.

f=(a,b)=>b>a?f(b,a):(/t[hd]/.test(a+b)?"spade":a)+" and "+(/[dt]d/.test(a+b)?"club":b)

Try it online!

JavaScript (ES6), 86 bytes

Inspired by Neil's method.

f=(a,b)=>b>a?f(b,a):(/t[hd]/.test(a+b)?"spade":a)+" and "+(/[dt]d/.test(a+b)?"club":b)

Try it online!

Commented

f = (a, b) =>      // a = 1st string, b = 2nd string
b > a ?            // if b is greater than a:
  f(b, a)          //   swap a and b
:                  // else:
  (                //
    /t[hd]/        //   if a is "heart" and b is either
    .test(a + b) ? //   "heart" or "diamond":
      "spade"      //     use "spade" as the left output
    :              //   else:
      a            //     use a
  ) +              //
  " and " +        //   append " and "
  (                //
    /[dt]d/        //   if a is either "diamond" or "heart"
    .test(a + b) ? //   and b is "diamond":
      "club"       //     use "club" as the right output
    :              //   else:
      b            //     use b
  )                //
saved 4 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (ES6), 9086 bytes

Inspired by Neil's method.

Expects (a)(b).

a=>b=>f=(b>a?[aa,b]=[bb)=>b>a?f(b,a]a):0,(/t[hd]/.test(a+b)?"spade":a)+" and "+(/[dt]d/.test(a+b)?"club":b)

Try it online!Try it online!

JavaScript (ES6), 90 bytes

Inspired by Neil's method.

Expects (a)(b).

a=>b=>(b>a?[a,b]=[b,a]:0,/t[hd]/.test(a+b)?"spade":a)+" and "+(/[dt]d/.test(a+b)?"club":b)

Try it online!

JavaScript (ES6), 86 bytes

Inspired by Neil's method.

f=(a,b)=>b>a?f(b,a):(/t[hd]/.test(a+b)?"spade":a)+" and "+(/[dt]d/.test(a+b)?"club":b)

Try it online!

saved 9 bytes
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading