[Question]
  [
Your task is to sort an array containing the strings "quarter", "dime", "nickel", and "penny" any number of times in no specific order and sort them so that they are in this order: `quarter dime nickel penny` (in other words, greatest to least monetary value). 
---
## Rules
1. Your program must take an array as input containing the names of U.S coins and sort them from greatest to least by monetary value.
	* For those who are not from the U.S or don't use change, the values of U.S coins, from greatest to least, are:
		+ Quarter: 25 cents
		+ Dime: 10 cents
		+ Nickel: 5 cents
		+ Penny: 1 cent
2. You may sort this array in any way you wish, as long as the output is ordered by the monetary values shown above.
3. Input can be taken in any way, be it command-line arguments or STDIN.
4. An input array would be all lowercase strings, something like this:
	* `quarter dime nickel nickel quarter dime penny penny`
5. The actual format of input and output is up to you.
---
## Test Cases
```
"penny nickel dime quarter" 
-> "quarter dime nickel penny"
"nickel penny penny quarter quarter quarter dime dime dime dime"
-> "quarter quarter quarter dime dime dime dime nickel penny penny"
"quarter dime nickel nickel quarter dime penny penny"
-> "quarter quarter dime dime nickel nickel penny penny"
```
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so standard rules & loopholes apply.
  
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~5~~ 3 bytes
```
ñg9
```
[Test it online!](http://ethproductions.github.io/japt/?v=1.4.4&code=8Wc5&input=WydxdWFydGVyJyAnZGltZScgJ25pY2tlbCcgJ25pY2tlbCcgJ3F1YXJ0ZXInICdkaW1lJyAncGVubnknICdwZW5ueSdd)
### Explanation
I, too, have added a sorting function to my language in the last few weeks :-) `ñ` takes in an array and a function and sorts the array as if each item had been mapped through that function.
The `g` function on a string takes in a number `n` and returns the `n`th char in the string, wrapping if `n` is negative or past the end of the string. The strings can thus be aligned as follows:
```
quarterqu**a**rter...
dimedimed**i**medi...
nickelnic**k**elni...
pennypenn**y**penn...
```
The 9th char (0-indexed) of each string has been highlighted in bold. These are in the correct order, so all we have to do is `ñg9`. (Though now that I look back on it, `ñg5` would work as well...)
[Answer]
# [V](https://github.com/DJMcMayhem/V), 7 bytes
```
ú/¨qu©¿
```
[Try it online!](https://tio.run/nexus/v#@394l/6hFYWlh1Ye2v//f15mcnZqDldBal5eJZQsLE0sKkktwqBTMnNT0QgA "V – TIO Nexus")
This uses the spiffy new *sort* command I added to V around a week ago (`ú`). Sweet timing!
The way this works is by sorting every line by default sorting (ASCII values) but ignoring the first match of a certain regex. In this case, the regex is `(qu)?`, although it has some gross non-ASCII stuff to avoid using backslashes. If you ignore the first two letters of "quarter", it starts with 'a', and then all of the coins are already in alphabetical order.
# Non-competing version, 4 bytes
```
ú!/.
```
This feature was already implemented, but I hadn't tested it extensively yet so it had a bug that I only realized because of this challenge. There is no TIO link because TIO is slightly behind.
This works by reverse sorting every line but ignoring the first character on each line.
[Answer]
# Python, 36 bytes
```
lambda a:a.sort(key=lambda x:x[-5:])
```
Unnamed function that sorts the list in-place by the key function given.
The slices of each coin name are then, `arter`, `dime`, `ickel`, and `penny` - which are in alphabetical (or more importantly, ordinal) order.
[Answer]
# Bash + coreutils, 18
```
tr q b|sort|tr b q
```
* Transliterate q to b
* Sort
* Transliterate b back to q
[Try it online](https://tio.run/nexus/bash#@19SpFCokFRTnF9UUgNkJykU/v9fWJpYVJJaxJWSmZvKlZeZnJ2aA6NQpApS8/IqISQA).
[Answer]
# [Python 3](https://docs.python.org/3/), ~~42~~ ~~41~~ 38 bytes
An unnamed lambda function which takes input as a list of strings, sorts in place.
[*(Outgolfed by Jonathan Allan)*](https://codegolf.stackexchange.com/a/109057/60919)
```
lambda x:x.sort(key=lambda s:(s*2)[5])
```
**[Try it online!](https://tio.run/nexus/python3#S1OwVYj5n5OYm5SSqFBhVaFXnF9UopGdWmkLFSu20ijWMtKMNo3V/F8MVKyUl5mcnZqjUJCal1cJJQtLE4tKUosw6JTM3FQ0QkmvuCAns0RDkytNo1iTq6AoM68EyPgPAA "Python 3 – TIO Nexus")**
Other solutions I messed around with:
```
lambda x:x.sort(key=lambda s:s*(s<'q'))
lambda x:x.sort(key=lambda s:(s+'pi')[5])
lambda x:x.sort(key=lambda s:ord(s[3])%16)
```
[Answer]
# [PowerShell](https://github.com/PowerShell/PowerShell), 21 bytes
```
$args|sort{($_*3)[9]}
```
[Try it online!](https://tio.run/nexus/powershell#@6@SWJReXFOcX1RSraESr2WsGW0ZW/v///@8zOTs1ByFgtS8vEooWViaWFSSWoRBp2TmpqIRAA "PowerShell – TIO Nexus")
### Explanation
Shamelessly stole the algorithm in [ETHproductions's answer](https://codegolf.stackexchange.com/a/109047/30402) (basically). I multiply each string by 3, then sort based on the 9th character of the resulting string.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
6ịµÞ
```
**[Try it online!](https://tio.run/nexus/jelly#@2/2cHf3oa2H5/0/3B75/3@0emFpYlFJapG6jnpKZm4qkMrLTM5OzUFmYCgpSM3Lq4TTsQA)** (the footer, `ÇY`, joins the resulting list with line feeds for a prettier print out.)
### How?
```
6ịµÞ - Main link: list of strings
  µ  - monadic chain separation
   Þ - sort the list of strings by the monadic function:
6ị   - the sixth index - Jelly indexing is modular and 1-based
```
The Nth index of a list in Jelly is the Nth item starting at the left, counting from 1, and looping back to the start when need be. (The 0th is at the right, the -1th one left of that and so on too).
So the sixth character of `['d','i','m','e']` is `'i'` since six is congruent to two modulo four.
The sixth character of the four coins in order are quart`e`r, d`i`me, nicke`l`, `p`enny
. These are in alphabetical (or more importantly, ordinal) order.
---
Another way to achieve the same thing would be to sort by the rotated strings with `ṙ5µÞ`, where `ṙ` rotates to the right, making the strings `erquart`, `imed`, `lnicke`, and `penny`.
[Answer]
# [Python](https://docs.python.org/2/), 32 bytes
```
lambda s:s.sort(key="npr".strip)
```
[Try it online!](https://tio.run/nexus/python2#ZYwhDoAwDAA9r2imNsMDSPgJZkBJGkYpbRG8fiBQYO7M5RboYaglb@OcwTprbVePK159YNHQmitJqvZkgWlasYAg8/XyOLM66s8zbfjB85JCHlOzREuNKLGD1Rs "Python 2 – TIO Nexus") Sorts the list in place. 
The idea is to use a sorting key function without a `lambda`. A good candidate was `x.strip`, which takes the string `x` and removes its the left and right edges all characters in the input. For example, `"abcdef".strip("faces") == "bcd"`.
The method `"npr".strip` takes:
```
quarter ->  np
dime    ->  npr
nickel  ->  pr
penny   ->  r
```
which are lexicographically sorted. I found the string `npr` by brute force. `npu` and `npt` also work, and there are none shorter.
[Answer]
# Bash (+coreutils) 11 bytes
**Golfed**
```
sort -rk1.2
```
**How It Works**
Reverse sort, with the "sort key" from the second character of the first field (word) till the end of line, i.e.:
```
uarter
ime
ickel
enny
```
**Test**
```
>echo penny nickel dime quarter|tr ' ' '\n'|sort -rk1.2
quarter
dime
nickel
penny
```
[Try It Online !](http://www.tutorialspoint.com/execute_bash_online.php?PID=0Bw_CjBb95KQMVWE1MW9JXzVFajg)
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 8 bytes
```
q~{5=}$p
```
[Try it online!](https://tio.run/nexus/cjam#@19YV21qW6tS8P9/tFJeZnJ2ao6SglJBal5eJRJdWJpYVJJahIOVkpmbip2KBQA "CJam – TIO Nexus")
**Explanation**
```
q~        Get and eval all input (array of coin names)
  {5=}$   Sort the array by the 5th index of each element (array indices loop in CJam)
       p  Print the result
```
[Answer]
## Pyke, ~~9~~ ~~7~~ 5 bytes
```
.#5R@
```
[Try it here!](http://pyke.catbus.co.uk/?code=.%235R%40&input=%5B%22penny%22%2C+%22nickel%22%2C+%22dime%22%2C+%22quarter%22%5D&warnings=0)
```
.#5R@ - sort_by:
  5R@ -  i[5]
```
[Answer]
# Retina, 10
* 6 10 bytes saved thanks to @ETHproductions
```
q
b
O`
b
q
```
* Substitute `q` to `b`
* Sort
* Substitute `b` back to `q`
[Try it online](https://tio.run/nexus/retina#@1/IlcTlnwAkCv//LyxNLCpJLeJKycxN5crLTM5OzYFRKFIFqXl5lRASAA).
[Answer]
# [V](https://github.com/DJMcMayhem/V), ~~8~~ 7 bytes
*1 byte saved thanks to @DJMcMayhem*
```
Úçq/:m0
```
[Try it online!]
See @DJMcMayhem's [answer](https://codegolf.stackexchange.com/questions/109043/count-my-change/109046#109046) in V (~~1~~ 0 bytes shorter than mine)
[Try it online!](https://tio.run/nexus/v#@3941uHlhfpWuQb//xeWJhaVpBZxpWTmpnLlZSZnp@bAKBSpgtS8vEoICQA "V – TIO Nexus")
```
Ú                    " sort all lines "
 ç                   " globally "
  q/                 "  where there a q is matched, "
    :m0              "  move it to the top of the buffer "
```
Here is an older solution at 1 byte larger, but I really like it.
### [V](https://github.com/DJMcMayhem/V), 8 bytes
```
Ú/q
dGHP
```
[Try it online!]
[Try it online!](https://tio.run/nexus/v#@394ln4hV4q7R8D//4WliUUlqUVcKZm5qVx5mcnZqTkwCkWqIDUvrxJCAgA "V – TIO Nexus")
### Explanation
```
Ú        " sorts the lines
```
Now the buffer will be in this format:
```
dimes
nickels
pennies
quarters
```
The only thing left to do now is to move the quarters to the top.
```
/q      " search for a q "
dG      " delete everything from the first quarter to the end of buffer "
HP      " and paste it at the top of the buffer
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 3 bytes
```
ñé5
```
[Try it online!](https://tio.run/nexus/japt#@3944@GVpv//R6sXliYWlaQWqSuoF6Tm5VUC6ZTM3FQglZeZnJ2ag8xAKIUqgemA0RgqYwE "Japt – TIO Nexus")
---
## A couple other 3-byte solutions:
```
üÅw
```
[Try it online!](https://tio.run/##y0osKPn///Cew63l//9HqxeWJhaVpBapK6gXpOblVQLplMzcVCCVl5mcnZqDzEAohSqB6YDRGCpjAQ)
---
```
ü é
```
[Try it onlin!](https://tio.run/##y0osKPn///AehcMr//@PVi8sTSwqSS1SV1AvSM3LqwTSKZm5qUAqLzM5OzUHmYFQClUC0wGjMVTGAgA)
[Answer]
# T-SQL, ~~41~~ ~~36~~ 34 bytes
```
select*from @ order by right(a,5)
```
### Explanation
Assume the input is pre-loaded in a table variable named `@`, with a single column named `a`, where each value is one coin to be sorted.
The `select * from @` part is boiler-plate 'get all values to return'. The real magic happens in the `order by` clause.
Using the same strategy as [Johnathan Allan](https://codegolf.stackexchange.com/a/109057/26408), I sort by the last five characters (SQL will return the entire string if it's too short): `arter`, `dime`, `ickel`, `penny`.
[Answer]
## JavaScript (ES6), ~~35~~ 33 bytes
```
a=>a.sort(([,...a],[,...b])=>b>a)
```
### Test cases
```
let f =
a=>a.sort(([,...a],[,...b])=>b>a)
console.log(f(['penny','nickel','dime','quarter']).join` `);
console.log(f(['nickel','penny','penny','quarter','quarter','quarter','dime','dime','dime','dime']).join` `);
console.log(f(['quarter','dime','nickel','nickel','quarter','dime','penny','penny']).join` `);
```
[Answer]
# Befunge, 158 bytes
```
~:0`v0v4<~_
9:%8_^>8*`^1p9\+1g
$:!#@_1-0" ynnep">:#,_>
1-0" lekcin">:#,_>$:!#^_
" emid">:#,_>$:!#^_1-0
>:#,_$1>-:!#^_0" retrauq"
*84g9< ^*84g91-*84g94-*84g96-
```
[Try it online!](http://befunge.tryitonline.net/#code=fjowYHYwdjQ8fl8KOTolOF9ePjgqYF4xcDlcKzFnCiQ6ISNAXzEtMCIgeW5uZXAiPjojLF8+CjEtMCIgbGVrY2luIj46IyxfPiQ6ISNeXwoiIGVtaWQiPjojLF8+JDohI15fMS0wCj46IyxfJDE+LTohI15fMCIgcmV0cmF1cSIKKjg0Zzk8IF4qODRnOTEtKjg0Zzk0LSo4NGc5Ni0&input=bmlja2VsIHBlbm55IHBlbm55IHF1YXJ0ZXIgcXVhcnRlciBxdWFydGVyIGRpbWUgZGltZSBkaW1lIGRpbWU)
String processing and sorting are not the sorts of things you'd typically want to attempt in Befunge, but this solution is taking advantage of [John Kasunich's](https://codegolf.stackexchange.com/users/65168/john-kasunich) observation that we don't actually need to sort anything. We just count the number of occurrences of each coin (which can easily be determined from the first character), and then output that many of each coin name in the appropriate order.
It's still not at all competitive with other languages in terms of size, but this approach is at least better than it would have been if we'd tried to handle the challenge as a string sorting exercise.
[Answer]
# Pyth, 3 bytes
```
@D5
```
[Demonstration](https://pyth.herokuapp.com/?code=%40D5&input=%5B%27quarter%27%2C+%27dime%27%2C+%27nickel%27%2C+%27nickel%27%2C+%27quarter%27%2C+%27dime%27%2C+%27penny%27%2C+%27penny%27%5D&debug=0)
Based on [ETHproductions](https://codegolf.stackexchange.com/a/109047/20080)'s answer in Japt.
Explanation:
```
@D5
@D5Q    Variable introduction
 D Q    Sort the input by
@ 5     Its fifth character
```
[Answer]
# [APL (Dyalog APL)](https://www.dyalog.com/), 11 bytes
Takes and returns list of strings.
```
{⍵[⍋↑5⌽¨⍵]}
```
[Try it online!](https://tio.run/nexus/apl-dyalog#U0/JLC5Qf9Q31TlSPSUtr1hd4X/ao7YJ1Y96t0Y/6u1@1DbR9FHP3kMrgPzY2v9AdUBJkBaFNAX1gtS8vEp1BfW8zOTs1BwgIyUzNxVIFZYmFpWkFqlzoSqHK4Ppg9Ew9dhZUEOxUGjmY2iBWwhnYChBdcp/AA "APL (Dyalog APL) – TIO Nexus")
`{` anonymous function:
 `⍵[`…`]` the argument indexed by
 `⍋` the ascending-making indices of
 `↑` the matrix whose rows are the padded
 `5⌽` five-steps-rotated
 `¨⍵` items of the argument
`}`
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 3 bytes
```
↺₉ᵒ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3w/1HbrkdNnQ@3Tvr/PzpaqSA1L69SSUdBKS8zOTs1B8RKycxNBdGFpYlFJalFSrE6CtFI0nAdcAZMIU4mzESsNNh4LIoRNiJYWJShOSc2FgA "Brachylog – Try It Online")
Approach stolen from ETHproductions' Japt answer.
```
       The input
  ᵒ    sorted by
↺      its elements rotated left
 ₉     by 9
       is the output.
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 3 bytes
```
Öṙ9
```
[Try it online!](https://tio.run/##yygtzv7///C0hztnWv7//z9aqbA0sagktUhJRyklMzcVSOVlJmen5iAzMJQUpOblVcLpWAA "Husk – Try It Online")
Ported from my Brachylog answer, which rips off ETHproductions' Japt answer but isn't an exact translation since it uses rotation instead of simple accessing-the-nth-element. There, I did it because `∋` doesn't let you index past the end of the input (which is probably quite helpful in many circumstances due to the declarative nature of the language). In Husk, `!` *does* let you index past the end of the input, with the same modular wrapping around that Japt `ñg9` uses, but it's from 1 so this program in particular would end up being one byte longer: `Ö!10`.
```
Ö      Sort by
 ṙ     rotation by
  9    9.
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 3 bytes
```
µ5i
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCtTVpIiwiIiwiWyduaWNrZWwnLCAncGVubnknLCAncGVubnknLCAncXVhcnRlcicsICdxdWFydGVyJywgJ3F1YXJ0ZXInLCAnZGltZScsICdkaW1lJywgJ2RpbWUnLCAnZGltZSddIl0=) or [Run all the test cases](https://vyxal.pythonanywhere.com/#WyJQaiIsInbijIg6xpsiLCLCtTVpIiwiOztaYCA9PiBgdmoiLCJbXCJwZW5ueSBuaWNrZWwgZGltZSBxdWFydGVyXCIsIFwibmlja2VsIHBlbm55IHBlbm55IHF1YXJ0ZXIgcXVhcnRlciBxdWFydGVyIGRpbWUgZGltZSBkaW1lIGRpbWVcIiwgXCJxdWFydGVyIGRpbWUgbmlja2VsIG5pY2tlbCBxdWFydGVyIGRpbWUgcGVubnkgcGVubnlcIl0iXQ==)
## How?
```
µ5i
µ   # Sort by:
 5i #  Index 5 into the list (zero-indexed, modular)
```
Port of Jelly.
[Answer]
## Batch, 82 bytes
```
@for %%c in (quarter dime nickel penny)do @for %%a in (%*)do @if %%a==%%c echo %%c
```
Takes input as command-line arguments and outputs to STDOUT. Works by concatenating the lists resulting from filtering the original list on each coin.
[Answer]
# Ruby, 34 bytes
```
->m{m.sort_by{|c|c[1..2]}.reverse}
```
input and output as an array of strings
[Answer]
## Ruby, 31 bytes
```
->s{s.sort_by{|i|i[1]}.reverse}
```
[Answer]
# Ruby, 30 bytes
```
->m{m.sort_by{|s|s[3].ord^16}}
```
Magical numbers found by trial and error. A bit clumsy, but shorter than using `.reverse`.
[Answer]
# [Perl 6](https://perl6.org), ~~40 36~~ 34 bytes
```
*.sort: {(<q d n p>Zxx 1..*).Bag{~m/./}}
```
[Try it](https://tio.run/nexus/perl6#ZYy7DoJAEEX7/YpbGSBhiI2Fr8LPsCPLqhthFnZBIQT/2hqjbKLE5t7JnJnTOIXbiuRGFB0W0miOnbE1dmNE72GNPthWyMAo98e2xZIoCumQnvtHkVAyDOPJWOSalQtC9AIomxpfEd2NzZwYxlIxd2AtrypHpguFqkltrazwu@lgSo/@@vM3DzFj3uVrhn78TzaxTOVFvQA "Perl 6 – TIO Nexus")
```
*.sort: {%(<q d n p>Z=>1..*){~m/./}}
```
[Try it](https://tio.run/nexus/perl6#ZYxBDoIwEEX3PcXfaICEEjcuVDiIO1LG2AhTaAFDCN7aNUZposTN/5N5M69zhH4v1VFUA7bKaI6dsS3SOZLv4YBxE5waFGDU2TnNdlJG4fioEplM03wxFqVmckGIUQB11@IrkXdjCyemuSbmAazVjUoUuiI0XW5bssLvloMlPfrrz986xIp5l68V@vE/2cQqV1d6AQ "Perl 6 – TIO Nexus")
```
*.sort: {%(<q d n p>Z=>^4){~m/./}}
```
[Try it](https://tio.run/nexus/perl6#ZYzBCoJAEIbv@xT/pdDA9RIdKn0QD4GsEy3prO5qIWJv3dkoF0q6/P8w38zXOcJtJ9VBVD3WymiOnLEtkmkj38Mewyo4NijAqNMsSU/bcHhUsYzHcTobi1IzuSDEIIC6a/FVyLuxhRPjVBNzD9bqSiUKXRGaLrctWeF388GcHv31528ZYsG8y9cC/fifbCKVqwu9AA "Perl 6 – TIO Nexus")
## Expanded:
```
*\            # WhateverCode lambda ( this is the parameter )
.sort:        # sort using the following code block
{             # bare block lambda with implicit parameter ｢$_｣
  %(          # treat this list as a hash
    <q d n p> # list of first characters
    Z[=>]     # zipped using pair constructor
    ^4        # Range from 0 up-to 4 ( excludes 4 )
  ){          # get the value associated with this key
    ~m/./     # regex which gets the first character ( implicitly from ｢$_｣ )
  }
}
```
[Answer]
# Mathematica, 50 bytes
```
Flatten@{Last@#,Most@#}&@Split@Sort@StringSplit@#&
```
[Answer]
# [RProgN](https://github.com/TehFlaminTaco/Reverse-Programmer-Notation), 18 bytes
```
~{3mtt¢\3mtt¢>}$
```
## Explained
```
~               # Zero Space Segment
 {            } # Anonymous Function
  3m            # Repeat the inputted string 3 times
    tt¢         # And take the tenth character of that
       \3mtt¢   # Do the same for the entry underneith
             >  # Compare the ascii value of the two
               $# Sort the input by the anonymous function.
```
[Try it online!](https://tio.run/nexus/rprogn#@19XbZxbUnJoUQyEsqtV@f//f3VeZnJ2ao5OQWpeXiWULCxNLCpJLcKgUzJzU9GIWgA "RProgN – TIO Nexus")
[Answer]
# java 8, ~~128~~ 112 bytes
This is a lambda expression for a `java.util.function.Function<String[],String[]>`
```
s->{String r="";for(String k:"q d c p".split(" "))for(String t:s)if(t.contains(k))r+=" "+t;return r.split(" ");}
```
Explantion:
For each of the 4 coins in order, go through the input and append the coin's name to the result every time there is a match for that coin's unique character. Split the result into an array and return it.
]