Golden Choice (Javascript)

My code so far:

function colOf (coin) {
    return Math.round((coin.pos.x-14)/4);
}
function rowOf (coin) {
    return Math.round((coin.pos.y-14)/6);
}
function coinsOn (t, n) {
    var coins = [];
    for (let coin of hero.findItems()) {
        if (typeof t == "string") {
            if ((t == "col" && colOf(coin) == n) || (t == "row" && rowOf(coin) == n)) {
                coins.push(coin);
            }
        }
        if (typeof t == "number") {
            if (rowOf(coin) == t && colOf(coin) == n) {
                coins.push(coin);
            }
        }
    }
    return coins;
}
function most (a, prop) {
    if (prop) return a.filter(i => a.filter(j => j[prop] > i[prop]).length === 0);
    return a.filter(i => a.filter(j => j > i).length === 0);
    
}
function property (array, prop) {
    var ret = [];
    for (let item of array) if (prop) ret.push(item[prop]); else break;
    if (ret.length === 0) ret = array;
    return ret;
}
var grid = [];
for (let i = 0; i < 10; i++) grid.push(property(coinsOn("row", i)));
for (let l = 0; l < 10; l++) {
    let best = hero.findNearest(most(grid[l].filter(c => hero.distanceTo(c) <= 7.25 || l === 0), "value"));
    if (l === 0) hero.moveXY(best.pos.x, hero.pos.y);
    hero.moveXY(best.pos.x, best.pos.y);
}

But it only collects about 2/3-9/10 of what is required. :confused:

Ok, so I solved it with enough random submissions, but I want it to find the path every time.