Post History
JavaScript (Node.js), 153 147 bytes -6 bytes thanks to Shaggy! a=>a.sort((x,y)=>g(x)-g(y),g=x=>"y gree br sc bla oc pe rub ol v f li go ch m cre c s ro a l ru g pu w p o b".split` `.find...
Answer
#3: Post edited
# [JavaScript (Node.js)], 153 bytes- ```
(a,g=x=>"re y gree br sc bla oc pe rub ol v f li go ch m cre c s ro a l r g pu w p o b".split` `.findIndex(t=>x.startsWith(t)))=>a.sort((x,y)=>g(x)-g(y))- ```
- [Try it online!][TIO-ksy1go2e]
- Inspired by [user's solution](https://codegolf.codidact.com/posts/283376/283384#answer-283384), I found the minimum number of initial characters that uniquely identified each color. I then golfed if further by realizing the ones at the end of the list don't actually have to uniquely identify the color, because the ones it couldn't determine would have been caught already. (E.g. `green` and `grey` need the `gree` to determine green, but if it isn't `green` then it must be `grey` and we can catch that with just `g`)
- ----
- # Old answer, 219 bytes
- ```javascript
- a=>"red yellow green brown scarlet black ochre peach ruby olive violet fawn lilac gold chocolate mauve cream crimson silver rose azure lemon russet grey purple white pink orange blue".split(' ').filter(i=>a.includes(i))
- ```
- [Try it online!][TIO-ksawomhk]
[TIO-ksy1go2e]: https://tio.run/##ZVFNb9wgED3Hv@LJl2DJ8Q9I5L3n1GMP6UrBLLZpMIMAfzXqb99i2Gir9sIM772ZNwM/@cK9cMqGJ0MXee3bK@P10G7tqXQSOwYnJToHL9BpDhKwEm7uQBoLemiFgSBGTBCxQMDDETg0HAbYGSssCF3ZeKtVeMd70ytzeTUXubHQnrbGB@6C/67CyEJVVe2JN55cYGyr93gb2FY9DWyvqqsg4wOC9MGjxVvx8Hau41EeM5qyRtnpWR7RyUu6OlpNedOQTljU7rcov7i4TsTKXWpNa0xSeVb@V5yNer6muI4qJEf@a3bZmrzMo3DxcSR2dlYniBw3Q8q80ot0SZ6s75NrFeuOJP7J5CmZWGU@MiT5lERyyoybvZfh77VIqyU1WhTpTE18zpAYSZDmeeCvZWN7ycV4f66jiRjzMl5wd@tyvMm5OL8URU8O7P4VoD5/SYXP4uHAo3GjaWDlq7FzeI7VB1@9/MN@m8ON7lkS1Hj8YR6j7vf1Dw "JavaScript (Node.js) – Try It Online"- [JavaScript (Node.js)]: https://nodejs.org
- [TIO-ksawomhk]: https://tio.run/##ZVJLbgIxDF0zp7CyYUaic4Ai2HfVA1AWIXggbUhG@QyiVc9ObQdE1W4Sx37@vOe860knE@2Yn3zY43VYXfVqrSLu4YLOhTMcIqKHXQxnD8no6DDDzmnzAcEcI8KI2hwhlt0FgrMTwmQDYwZNCc4SEg7B7cEcgwlOZ4STLgQzEfWJTntKgSpbN2GEGBKC/ixU1@GJ/LGkRMVoiAuMJY4O4Xy0VGS0niaI2h@Qximo@jQ6m9s5zLt@sC5jbO1qrXvrjSt7TK3tuqsJPmXImHKCFWya2Wa7oEMJSbUAJaXoJgHkybTVDUMs2Mez3G68x5i@WqgqGRmSXpH/kmsjlodvYcOGsJbWpEEdhURmo/Jmq/Jlq@olcGn9mFwkZ@MmrVQgsaqLNBcQi1uzWd/ftGSJbNQ9siULk/z7DvlxJ0vl@Qs85OIi/DVkzvpj7pJum@2yaYYQoX2sAsJQV9LBVzNjPzXuXTi06sWPJT9TNse75Z/oa8m38NAKYAHzNz8n3Pf1Bw "JavaScript (Node.js) – Try It Online"
- # [JavaScript (Node.js)], ~~153~~ 147 bytes
- *-6 bytes thanks to Shaggy!*
- ```
- a=>a.sort((x,y)=>g(x)-g(y),g=x=>"y gree br sc bla oc pe rub ol v f li go ch m cre c s ro a l ru g pu w p o b".split` `.findIndex(t=>!x.indexOf(t)))
- ```
- [Try it online!][TIO-ksy1go2e]
- Inspired by [user's solution](https://codegolf.codidact.com/posts/283376/283384#answer-283384), I found the minimum number of initial characters that uniquely identified each color. I then golfed if further by realizing the ones at the end of the list don't actually have to uniquely identify the color, because the ones it couldn't determine would have been caught already. (E.g. `green` and `grey` need the `gree` to determine green, but if it isn't `green` then it must be `grey` and we can catch that with just `g`)
- ----
- # Old answer, 219 bytes
- ```javascript
- a=>"red yellow green brown scarlet black ochre peach ruby olive violet fawn lilac gold chocolate mauve cream crimson silver rose azure lemon russet grey purple white pink orange blue".split(' ').filter(i=>a.includes(i))
- ```
- [Try it online!][TIO-ksawomhk]
- [TIO-ksy1go2e]: https://tio.run/##ZVHLbtwwDDzHXzH1JTbg@AMaeO855QOSBSJrZVuNLAqS/GrRb9/qscEW7cWkZ4YcUvzBVua4lcY/abqI69BdWXdirSPrq2pvjro7jdVeP43VUTdjt3en8sBohUBv4Th6xUAcRsAuPUhhxQAlMRL4hBncCnA4WAKDCiKMMAs2GBD6snVGSf@Bj3aQ@vKiL2KvfHf6trcy5q9D5eu6vnLSzsML5x06vBUPb@cmfMo4iC4blL1aRIxWXNKvpU2XNw2phAXtcYviiwszB6w8hFK0hSSVZ@V/xdloYFuK2yR9cmQ/F5utyYk8CuOfMTGLNSpBZJkeU@akWoVN8mR9n1zJUBeTcI3ZUTIxUn9mSLA5icScGbs4J/zfa5GSa2q0SlKZmtmSIT4RJ8XywF/LhvaC8en@XLEJn/IyjjN76xLf5Fycn4tiIIvqfgrQkE9S41fxEPFg3Coaq/JFm8V/D9WRr5//YV8Xf6PDeaOgweO7fgy639c/ "JavaScript (Node.js) – Try It Online"
- [JavaScript (Node.js)]: https://nodejs.org
- [TIO-ksawomhk]: https://tio.run/##ZVJLbgIxDF0zp7CyYUaic4Ai2HfVA1AWIXggbUhG@QyiVc9ObQdE1W4Sx37@vOe860knE@2Yn3zY43VYXfVqrSLu4YLOhTMcIqKHXQxnD8no6DDDzmnzAcEcI8KI2hwhlt0FgrMTwmQDYwZNCc4SEg7B7cEcgwlOZ4STLgQzEfWJTntKgSpbN2GEGBKC/ixU1@GJ/LGkRMVoiAuMJY4O4Xy0VGS0niaI2h@Qximo@jQ6m9s5zLt@sC5jbO1qrXvrjSt7TK3tuqsJPmXImHKCFWya2Wa7oEMJSbUAJaXoJgHkybTVDUMs2Mez3G68x5i@WqgqGRmSXpH/kmsjlodvYcOGsJbWpEEdhURmo/Jmq/Jlq@olcGn9mFwkZ@MmrVQgsaqLNBcQi1uzWd/ftGSJbNQ9siULk/z7DvlxJ0vl@Qs85OIi/DVkzvpj7pJum@2yaYYQoX2sAsJQV9LBVzNjPzXuXTi06sWPJT9TNse75Z/oa8m38NAKYAHzNz8n3Pf1Bw "JavaScript (Node.js) – Try It Online"
#2: Post edited
# [JavaScript (Node.js)], 219 bytes- ```javascript
- a=>"red yellow green brown scarlet black ochre peach ruby olive violet fawn lilac gold chocolate mauve cream crimson silver rose azure lemon russet grey purple white pink orange blue".split(' ').filter(i=>a.includes(i))
- ```
- [Try it online!][TIO-ksawomhk]
- [JavaScript (Node.js)]: https://nodejs.org
- [TIO-ksawomhk]: https://tio.run/##ZVJLbgIxDF0zp7CyYUaic4Ai2HfVA1AWIXggbUhG@QyiVc9ObQdE1W4Sx37@vOe860knE@2Yn3zY43VYXfVqrSLu4YLOhTMcIqKHXQxnD8no6DDDzmnzAcEcI8KI2hwhlt0FgrMTwmQDYwZNCc4SEg7B7cEcgwlOZ4STLgQzEfWJTntKgSpbN2GEGBKC/ixU1@GJ/LGkRMVoiAuMJY4O4Xy0VGS0niaI2h@Qximo@jQ6m9s5zLt@sC5jbO1qrXvrjSt7TK3tuqsJPmXImHKCFWya2Wa7oEMJSbUAJaXoJgHkybTVDUMs2Mez3G68x5i@WqgqGRmSXpH/kmsjlodvYcOGsJbWpEEdhURmo/Jmq/Jlq@olcGn9mFwkZ@MmrVQgsaqLNBcQi1uzWd/ftGSJbNQ9siULk/z7DvlxJ0vl@Qs85OIi/DVkzvpj7pJum@2yaYYQoX2sAsJQV9LBVzNjPzXuXTi06sWPJT9TNse75Z/oa8m38NAKYAHzNz8n3Pf1Bw "JavaScript (Node.js) – Try It Online"
- # [JavaScript (Node.js)], 153 bytes
- ```
- (a,g=x=>"re y gree br sc bla oc pe rub ol v f li go ch m cre c s ro a l r g pu w p o b".split` `.findIndex(t=>x.startsWith(t)))=>a.sort((x,y)=>g(x)-g(y))
- ```
- [Try it online!][TIO-ksy1go2e]
- Inspired by [user's solution](https://codegolf.codidact.com/posts/283376/283384#answer-283384), I found the minimum number of initial characters that uniquely identified each color. I then golfed if further by realizing the ones at the end of the list don't actually have to uniquely identify the color, because the ones it couldn't determine would have been caught already. (E.g. `green` and `grey` need the `gree` to determine green, but if it isn't `green` then it must be `grey` and we can catch that with just `g`)
- ----
- # Old answer, 219 bytes
- ```javascript
- a=>"red yellow green brown scarlet black ochre peach ruby olive violet fawn lilac gold chocolate mauve cream crimson silver rose azure lemon russet grey purple white pink orange blue".split(' ').filter(i=>a.includes(i))
- ```
- [Try it online!][TIO-ksawomhk]
- [TIO-ksy1go2e]: https://tio.run/##ZVFNb9wgED3Hv@LJl2DJ8Q9I5L3n1GMP6UrBLLZpMIMAfzXqb99i2Gir9sIM772ZNwM/@cK9cMqGJ0MXee3bK@P10G7tqXQSOwYnJToHL9BpDhKwEm7uQBoLemiFgSBGTBCxQMDDETg0HAbYGSssCF3ZeKtVeMd70ytzeTUXubHQnrbGB@6C/67CyEJVVe2JN55cYGyr93gb2FY9DWyvqqsg4wOC9MGjxVvx8Hau41EeM5qyRtnpWR7RyUu6OlpNedOQTljU7rcov7i4TsTKXWpNa0xSeVb@V5yNer6muI4qJEf@a3bZmrzMo3DxcSR2dlYniBw3Q8q80ot0SZ6s75NrFeuOJP7J5CmZWGU@MiT5lERyyoybvZfh77VIqyU1WhTpTE18zpAYSZDmeeCvZWN7ycV4f66jiRjzMl5wd@tyvMm5OL8URU8O7P4VoD5/SYXP4uHAo3GjaWDlq7FzeI7VB1@9/MN@m8ON7lkS1Hj8YR6j7vf1Dw "JavaScript (Node.js) – Try It Online"
- [JavaScript (Node.js)]: https://nodejs.org
- [TIO-ksawomhk]: https://tio.run/##ZVJLbgIxDF0zp7CyYUaic4Ai2HfVA1AWIXggbUhG@QyiVc9ObQdE1W4Sx37@vOe860knE@2Yn3zY43VYXfVqrSLu4YLOhTMcIqKHXQxnD8no6DDDzmnzAcEcI8KI2hwhlt0FgrMTwmQDYwZNCc4SEg7B7cEcgwlOZ4STLgQzEfWJTntKgSpbN2GEGBKC/ixU1@GJ/LGkRMVoiAuMJY4O4Xy0VGS0niaI2h@Qximo@jQ6m9s5zLt@sC5jbO1qrXvrjSt7TK3tuqsJPmXImHKCFWya2Wa7oEMJSbUAJaXoJgHkybTVDUMs2Mez3G68x5i@WqgqGRmSXpH/kmsjlodvYcOGsJbWpEEdhURmo/Jmq/Jlq@olcGn9mFwkZ@MmrVQgsaqLNBcQi1uzWd/ftGSJbNQ9siULk/z7DvlxJ0vl@Qs85OIi/DVkzvpj7pJum@2yaYYQoX2sAsJQV9LBVzNjPzXuXTi06sWPJT9TNse75Z/oa8m38NAKYAHzNz8n3Pf1Bw "JavaScript (Node.js) – Try It Online"
#1: Initial revision
# [JavaScript (Node.js)], 219 bytes ```javascript a=>"red yellow green brown scarlet black ochre peach ruby olive violet fawn lilac gold chocolate mauve cream crimson silver rose azure lemon russet grey purple white pink orange blue".split(' ').filter(i=>a.includes(i)) ``` [Try it online!][TIO-ksawomhk] [JavaScript (Node.js)]: https://nodejs.org [TIO-ksawomhk]: https://tio.run/##ZVJLbgIxDF0zp7CyYUaic4Ai2HfVA1AWIXggbUhG@QyiVc9ObQdE1W4Sx37@vOe860knE@2Yn3zY43VYXfVqrSLu4YLOhTMcIqKHXQxnD8no6DDDzmnzAcEcI8KI2hwhlt0FgrMTwmQDYwZNCc4SEg7B7cEcgwlOZ4STLgQzEfWJTntKgSpbN2GEGBKC/ixU1@GJ/LGkRMVoiAuMJY4O4Xy0VGS0niaI2h@Qximo@jQ6m9s5zLt@sC5jbO1qrXvrjSt7TK3tuqsJPmXImHKCFWya2Wa7oEMJSbUAJaXoJgHkybTVDUMs2Mez3G68x5i@WqgqGRmSXpH/kmsjlodvYcOGsJbWpEEdhURmo/Jmq/Jlq@olcGn9mFwkZ@MmrVQgsaqLNBcQi1uzWd/ftGSJbNQ9siULk/z7DvlxJ0vl@Qs85OIi/DVkzvpj7pJum@2yaYYQoX2sAsJQV9LBVzNjPzXuXTi06sWPJT9TNse75Z/oa8m38NAKYAHzNz8n3Pf1Bw "JavaScript (Node.js) – Try It Online"