Post History
JavaScript (Node.js), 75 68 bytes -7 bytes thanks to Hakerh400 (a,b)=>b.map(i=>[a[i],a[j]]=[a[j=b[Math.random()*b.length|0]],a[i]]) Try it online! Basic random swap algorithm. Unfortuna...
Answer
#3: Post edited
# [JavaScript (Node.js)], 75 bytes- ```javascript
(a,b,x)=>{for(i of b)x=b[Math.random()*b.length|0],[a[i],a[x]]=[a[x],a[i]]}- ```
- [Try it online!][TIO-kqliws20]
- Basic random swap algorithm. Unfortunately, JavaScript doesn't have a built in shuffle function.
- [JavaScript (Node.js)]: https://nodejs.org
[TIO-kqliws20]: https://tio.run/##dVDLboMwELzzFT7kYKoN4tU8FJE/6BdYq2ZNDHHl4gqsCony7dSmUZtL9@L1zM5qZt/ok4a61x9u29mrWppq4QQSxrg6T43tuWa2YTIeKyleyN2Snrqrfefxk0yM6lp3@0oRBAmNQGJErER4IAA4L7XtBsecGtzAKiYi5kuIDHIooIRn2MEegYkUHiBE@H8u99@HiWPhqWyVpymUGewPUGRQlJDfBUF/gCNihKco8okYD3ZCqtVWzKZ1l1GOCQIm0RsNzOkXplfb61Z3ZDxFyWB0rXj8wzfhWvc@hLVGJca2/CI2059uDl42k5yRbc@hoxkvXjUv3w "JavaScript (Node.js) – Try It Online"
- # [JavaScript (Node.js)], ~~75~~ 68 bytes
- -7 bytes thanks to Hakerh400
- ```javascript
- (a,b)=>b.map(i=>[a[i],a[j]]=[a[j=b[Math.random()*b.length|0]],a[i]])
- ```
- [Try it online!][TIO-kqliws20]
- Basic random swap algorithm. Unfortunately, JavaScript doesn't have a built in shuffle function.
- [JavaScript (Node.js)]: https://nodejs.org
- [TIO-kqliws20]: https://tio.run/##dZBNboMwEIX3nMKLLKCaIP7aJIrMDXoCa9SMiSFGBEdgdUM5O7WharOpV8/z3jd6dkufNFaDfth9b65qqfkSEsiIlzK@0yPUvBQkNAKJFpE73XIp3sne4oH6q7mH0YuMO9U39vaVoM9pxGipTD9aZtVoR8aZCJg7QqSQQQ4FvMIbHBCYSOBp5Oj/c5m7PiVOubPSFU8SKFI4HCFPIS8g@wE8f4QTYoDnIKjNwEJfh5l6qxWxad3VKcsEAZPoinrn/DumDzPoRvfUOYvisdOVCqPNr9dv2rR/rOlU3JkmvIjd9MfNvstukjOyfekVzXhx1Lx8Aw "JavaScript (Node.js) – Try It Online"
#2: Post edited
- # [JavaScript (Node.js)], 75 bytes
- ```javascript
- (a,b,x)=>{for(i of b)x=b[Math.random()*b.length|0],[a[i],a[x]]=[a[x],a[i]]}
- ```
- [Try it online!][TIO-kqliws20]
- Basic random swap algorithm. Unfortunately, JavaScript doesn't have a built in shuffle function.
- [JavaScript (Node.js)]: https://nodejs.org
[TIO-kqliws20]: https://tio.run/##dVBLboMwEN1zillkAdUE8Ws@isgNeoLRqBknQKgojsCKkChnpzap2mzqjcfvM3rPH3KX/tzVN7Nu9aWYy3z2BRUOQX4cS935NegSVDDkit7EXMNO2ov@9IMXFTZFW5nrV8RIQjWj0MCck7vQATzNZ932BkzRmx5yIA/sIYoxwRQzfMUNbhmBInyCmPF/XWKfT4p9aql4sUcRZjFud5jGmGaY/Bicf4d7Zo8Pnmcbge/iuFZLrADGZVdTGCBBUGyDOubwC8u77uqqbqWxlDzw0v1S8JhdSd0UYaMr/0Sr8U8/uQyrUU0M66ObZOKTdU3zNw "JavaScript (Node.js) – Try It Online"
- # [JavaScript (Node.js)], 75 bytes
- ```javascript
- (a,b,x)=>{for(i of b)x=b[Math.random()*b.length|0],[a[i],a[x]]=[a[x],a[i]]}
- ```
- [Try it online!][TIO-kqliws20]
- Basic random swap algorithm. Unfortunately, JavaScript doesn't have a built in shuffle function.
- [JavaScript (Node.js)]: https://nodejs.org
- [TIO-kqliws20]: https://tio.run/##dVDLboMwELzzFT7kYKoN4tU8FJE/6BdYq2ZNDHHl4gqsCony7dSmUZtL9@L1zM5qZt/ok4a61x9u29mrWppq4QQSxrg6T43tuWa2YTIeKyleyN2Snrqrfefxk0yM6lp3@0oRBAmNQGJErER4IAA4L7XtBsecGtzAKiYi5kuIDHIooIRn2MEegYkUHiBE@H8u99@HiWPhqWyVpymUGewPUGRQlJDfBUF/gCNihKco8okYD3ZCqtVWzKZ1l1GOCQIm0RsNzOkXplfb61Z3ZDxFyWB0rXj8wzfhWvc@hLVGJca2/CI2059uDl42k5yRbc@hoxkvXjUv3w "JavaScript (Node.js) – Try It Online"
#1: Initial revision
# [JavaScript (Node.js)], 75 bytes ```javascript (a,b,x)=>{for(i of b)x=b[Math.random()*b.length|0],[a[i],a[x]]=[a[x],a[i]]} ``` [Try it online!][TIO-kqliws20] Basic random swap algorithm. Unfortunately, JavaScript doesn't have a built in shuffle function. [JavaScript (Node.js)]: https://nodejs.org [TIO-kqliws20]: https://tio.run/##dVBLboMwEN1zillkAdUE8Ws@isgNeoLRqBknQKgojsCKkChnpzap2mzqjcfvM3rPH3KX/tzVN7Nu9aWYy3z2BRUOQX4cS935NegSVDDkit7EXMNO2ov@9IMXFTZFW5nrV8RIQjWj0MCck7vQATzNZ932BkzRmx5yIA/sIYoxwRQzfMUNbhmBInyCmPF/XWKfT4p9aql4sUcRZjFud5jGmGaY/Bicf4d7Zo8Pnmcbge/iuFZLrADGZVdTGCBBUGyDOubwC8u77uqqbqWxlDzw0v1S8JhdSd0UYaMr/0Sr8U8/uQyrUU0M66ObZOKTdU3zNw "JavaScript (Node.js) – Try It Online"