g | x | w | all
Bytes Lang Time Link
050AWK241106T201239Zxrs
019Ruby180111T143908ZG B
008Uiua241023T011203Znyxbird
008Japt170711T101848ZShaggy
6625Vyxal230819T133138Zlyxal
008Thunno 2230818T144306ZThe Thon
011Retina170711T184114Zovs
038Javascript171002T063626ZCoert Gr
013J171002T075507ZFrownyFr
070Perl 5170805T042243ZXcali
037Prolog SWI170711T070447ZTessella
026Julia170712T041031ZTanj
014CJam170716T043508ZEsolangi
018Mathematica170712T025628ZNot a tr
048Racket170711T201102ZMajora32
035R170711T175406ZGiuseppe
021Octave170711T165220Zbeaker
026Ruby170711T142010ZKaia Lea
106Java 8170711T073334ZKevin Cr
065Common Lisp170711T073415ZRenzo
007Husk170711T131705ZLeo
021Perse170711T131146Zfaso
045PHP7170711T094348ZEzenhis
010Jelly170711T094257ZErik the
037F#170711T092828Zuser2015
061C#170711T083748ZTheLetha
027PowerShell170711T061720ZTessella
028Haskell170711T072700Zxnor
037Javascript ES6170711T071334ZEndenite
00805AB1E170711T060821Zkalsower
032Haskell170711T050202Znimi
046PHP170711T040018ZScottMcG
041Haskell Lambdabot170711T033635Zბიმო
027Mathematica170711T032737ZGreg Mar
009Pyth170711T032805ZLeaky Nu
008APL170711T032819Zmarinus
037Python 3170711T032303ZLeaky Nu

AWK, 50 bytes

/D/{d=d" D"}/L/{l=l" L"}END{print"[["l" ]["d" ]]"}

Try it online!

Ruby, 20 19 bytes

->l{[k=l-[?D],l-k]}

Try it online!

Uiua, 8 bytes

⊃↘↙⊸⊗@L⍆

Try it!

Takes input as a string (array of characters), and outputs as two strings.

⍆ sort, then ⊃↘↙ split (reversed) ⊸ by the ⊗ indexof L.

Japt, 13 12 10 8 bytes

"DL"£kX

Try it

"DL"£kX     :Implicit input of array U
"DL"         :Literal string
    ¬        :Split
     £       :Map each X
      kX     :  Remove all occurrences of X from U

Vyxal, 53 bitsv2, 6.625 bytes

‛LDƛ?Oẋf

Try it Online!

Ports Thonnu 2

Explained

‛LDƛ?Oẋf­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌­
‛LDƛ      # ‎⁡To each character in the string "LD":
    ?O    # ‎⁢  Count the character in the input
      ẋ   # ‎⁣  And list repeat it that many times
       f  # ‎⁤  flatten that
💎

Created with the help of Luminespire.

Thunno 2, 8 bytes

`LDdẊcx×

Try it online!

Explanation

`LDdẊcx×  # Implicit input                   ->  ["L","D","L","D","D"]
`LD       # Push the string "LD"             ->  ["L","D","L","D","D"]  "LD"
   d      # Split it into characters         ->  ["L","D","L","D","D"]  ["L","D"]
    Ẋ     # Store it in x without popping    ->  ["L","D","L","D","D"]  ["L","D"]
     c    # Count occurrences in the input   ->  [2,3]
      x×  # Multiply by x elementwise        ->  [["L","L"],["D","D","D"]]
          # Implicit output

Retina, 21 11 bytes

-10 bytes thanks to CalculatorFeline

O^`.
LD
L D

Try it online!

Javascript, 38 bytes

q=>['L','D'].map(x=>q.filter(y=>x==y))

J, 13 bytes

<@-."1 0&'DL'

Try it online!

Perl 5, 70 bytes

$"='","';@L=(L)x y/L//;@D=(D)x y/D//;$_="[[\"@L\"],[\"@D\"]]";s/""//g

Try it online!

Prolog (SWI), 42, 37 bytes

l('L').
w(L,D,W):-partition(l,W,L,D).

Try it online!

Given that W is a list of washing, w/3 will unify L and D into lists of Lights and Darks respectively, by partitioning the washing against a predicate which succeeds if an item is a Light.

[Edit: golfed -5 thanks to Fatalize]

Julia, 26 bytes

g(s)=s[s.=="L"],s[s.=="D"]

CJam, 14 bytes

"LD"qf{1$e=*}`

Input is a list of characters (string), output is a list of lists of characters (list of strings).

Try it online!

Explanation:

"LD"  e# Push the string "LD"                  | "LD"
q     e# Push the input                        | "LD" "LDLLDLDDL"
f{    e# Foreach char in "LD", push input and: | ['L "LDLLDLDDL"
  1$  e#   Copy from 1 back                    | ['L "LDLLDLDDL" 'L
  e=  e#   Count occurences                    | ['L 5
  *   e#   Repeat character                    | ["LLLLL"
}     e# End                                   | ["LLLLL" "DDDD"]
`     e# Stringify:                            | "[\"LLLLL\" \"DDDD\"]"
e# Implicit output: ["LLLLL" "DDDD"]

Mathematica, 22 18 bytes

4 bytes saved by the genius of CalculatorFeline!

Cases@@@{#|L,#|D}&

Try it online, or at the Wolfram sandbox!

Input is a list of the symbols L and D — not strings, just the letters on their own, like in Greg Martin's answer. The syntax #|L is shorthand for Alternatives[#,L], but the @@@ syntax replaces the head Alternatives with Cases, so this code is equivalent to {Cases[#,L],Cases[#,D]}&.

Racket, 48 bytes

(compose list((curry partition)(λ(x)(eq? x'L))))

Just apply this anonymous function to, e.g., '(L D L D D L)

R, 35 bytes

x=scan(,'');list(x[i<-x>'D'],x[!i])

Try it online!

Reads from stdin.

Octave, 21 bytes

@(A){A(a=A>72),A(~a)}

Input is an array of characters, output is a cell array. Recycled from my answer here.

Sample execution on ideone.

Ruby, 26 bytes

->x{x.partition{|e|e==?L}}

Try it online!

Java 8, 110 106 bytes

a->{String[]r={"",""};for(char c:a)r[c/69]+=c;return new char[][]{r[1].toCharArray(),r[0].toCharArray()};}

-4 bytes thanks to @Nevay.

Explanation:

Try it here.

a->{                      // Method with char-array parameter and 2D char-array return-type
  String[]r={"",""};      //  Two Strings in an array
  for(char c:a)           //  Loop over the characters of the input
    r[c/69]+=c;           //   Append either of the two String with the character
                          //   c/69 will result in 0 for 'D' and 1 for 'L'
                          //  End of loop (implicit / single-line body)
  return new char[][]{    //  Return a 2D character-array
    r[1].toCharArray(),   //   With the String for L's converted to a char-array
    r[0].toCharArray()};  //   and String D's converted to a char-array
}                         // End of method

Common Lisp, 66 65 bytes

(defun f(x)`(,(remove"D"x :test'equal),(remove"L"x :test'equal)))

Try it online!

If, instead of strings, we use symbols, then it is much shorter:

Common Lisp, 42 41 40 bytes

(defun f(x)(mapcar'remove'(D L)`(,x,x)))

Try it online!

(f '(D D L L D L D)) ; => ((L L L) (D D D D)) 

Husk, 7 bytes

Mof-"DL

Try it online!

Explanation

Mof-"DL
M   "DL    For each character in ['D','L']:
 of-         keep only those strings that are not empty if that character is removed

Perse, 21 bytes

part(i,fn(x){x=="L"})

I may or may not have implemented the list partition function specifically for this challenge. Takes the input as an array of strings.

PHP7, 52 45 bytes

-7 bytes thanks to @Jörg Hülsermann

foreach($argv as$a)$$a[]=$a;print_r([$L,$D]);

Use with CLI as php -r a.php L L L D D L D

The script goes through the provided arguments and appends them to an array based on its value.

Jelly, 10 bytes

ẎfЀ⁾LDW€€

Try it online!

In Jelly a string is a list of 1-char Python strings, e.g. ['a', 'b', 'c']. That's why you get output such as [[['L'], ['L']], [['D'], ['D'], ['D']]], since 1-char Jelly strings behave the same.

Doesn't work as a full program, hence the ÇŒṘ at the bottom.

F#, 37 bytes

let f s=List.partition(fun a->a="L")s

Try it online!

Takes input as a list of strings, and returns two lists, the first with elements where fun a -> a="L" is true and the other with elements that result in false.

C#, 61 bytes

using System.Linq;a=>new[]{a.Where(c=>c<69),a.Where(c=>c>68)}

Full/Formatted Version:

using System;
using System.Linq;

class P
{
    static void Main()
    {
        Func<char[], System.Collections.Generic.IEnumerable<char>[]> f =
            a => new[] { a.Where(c => c < 69), a.Where(c => c > 68) };

        Console.WriteLine(string.Join(", ", f(new[]{ 'L', 'D', 'L', 'D', 'D' }).SelectMany(a => a.Select(c => c))));

        Console.ReadLine();
    }
}

PowerShell, 27 bytes

($args-eq'L'),($args-eq'D')

Try it online!


Edit: previously $args.where({$_-eq'L'},'sp') for 28 bytes. Could be $args.where({+"0x$_"},'sp') for 27 if not for the rule that L's must come first.

Haskell, 28 bytes

f l=[filter(==[c])l|c<-"LD"]

Try it online!

If the input can be a list of characters, the [] around c can be removed.

Javascript (ES6), 37 bytes

This is based on a (now deleted) Javascript (ES6) answer.

a=>[(b=c=>a.filter(d=>c==d))`L`,b`D`]

Ungolfed version:

function(array) {
  function filter(character){
    return array.filter(function(d) {
      return character == d;
    });
  }
  return [filter("L"), filter("D")];
}

Example code snippet:

f=

a=>[(b=c=>a.filter(d=>c==d))`L`,b`D`]

console.log(f(["L", "D", "L", "D", "D"]))

05AB1E, 8 bytes

'Lù'DÃ)

Try it online!

Haskell, 32 bytes

import Data.List
partition(>"K")

Just a boring library function.

Try it online!

PHP, 46 bytes

Assumed given list is: $arr = ['L','L','D','D','L','D','D','D','D','L'];

foreach($arr as $b){$a[$b][]=$b;};print_r($a);

Haskell (Lambdabot), 41 bytes

reverse.map tail.group.sort.("LD"++).join

Try it online!

Mathematica, 27 bytes

Rest/@Gather[{L,D}~Join~#]&

Pure function taking a list of Ls and Ds (symbols, not characters/strings) as input and returning a list of two lists. For example,

Rest/@Gather[{L,D}~Join~#]& @ {D, L, L, D, L}

returns {{L, L, L}, {D, D}}. Try it online!

Gather by itself is close to what we want, but fails to meet the spec in two ways: it doesn't produce empty lists if the input is missing Ls or Ds, and it doesn't always sort Ls to the left. Replacing the input # with {L,D}~Join~# solves both problems at once: it means there will be at least one L and at least one D, and the Ls will be returned first since an L was encountered first. Rest/@ then removes the initial L and D.

(I tried a solution using Count, but due to currying issues, it didn't seem to be shorter: ±q_:=#~Table~Count[q,#]&/@{L,D} is 31 bytes.)

Pyth, 10 9 bytes

mc@dQ1"LD

Test suite.

APL, 8 bytes

'DL'~⍨¨⊂

Explanation:

Examples:

      ('DL'~⍨¨⊂) 'LDLDD'
┌──┬───┐
│LL│DDD│
└──┴───┘
      ('DL'~⍨¨⊂) 'LLL'
┌───┬┐
│LLL││
└───┴┘
      ('DL'~⍨¨⊂) 'DD'
┌┬──┐
││DD│
└┴──┘
      ('DL'~⍨¨⊂) ''
┌┬┐
│││
└┴┘

Python 3, 37 bytes

lambda a:[[c]*a.count(c)for c in"LD"]

Try it online!