constcreateRandomPath=minutes=>{letpath=[];// if the minutes are even, calculate pathif(minutes%2===0){// populate the array from opposite ends with complementary valuesfor(letx=0;x<minutes/2;x++){constletter=Math.floor(Math.random()*4);path[x]="nsew".charAt(letter);path[minutes-x-1]="snwe".charAt(letter);}// randomize pathpath.sort((a,b)=>Math.floor(Math.random()*2)?1:-1);}// return the generated array or an empty array if steps are oddreturnpath;}
And a one-liner but not really randomized, just going north-then-south:
JS
Not a great solution, but a solution.
And a one-liner but not really randomized, just going north-then-south:
And the link to a demo on CodePen