1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Buying Paying $25 fix my short Google Sheets Script

Discussion in 'Programming' started by phaze3131, Jun 11, 2022.

  1. #1
    I have a list of all my stock trades with 3 columns of use, many duplicates of TICKER so that's why I want to use the "reduce" function which does work but only to reduce using TICKER and QUANTITY, can't figure out how to get my script to do PRICE also.

    https://www.dropbox.com/s/3dj1glt2t...Dashboard - Google Sheets - Google C.jpg?dl=0

    TICKER QUANTITY PRICE

    GOOG------3-------------$200

    my script here works great to reduce down the TICKER QUANTITY so it consolidates one line for each ticker and shows the added values of QUANTITY for each TICKER / row



    function MyPortfolio(symbols, quantity) {
    const sums = symbols.reduce((map, ticker, i ) => {
    ticker = ticker.toString();
    if (map[ticker]) {
    map[ticker] += Number(quantity[i]);
    } else {
    map[ticker] = Number(quantity[i]);
    }
    return map;
    }, {});
    
    return Object.entries(sums);
    }
    Code (markup):


    I want my script to also do the PRICE and have "pseudo" scripted it, the logic is correct but I know I can't do map[ticker].price I'm just not sure how to reference the price.

    Here is my "code"

    function MyPortfolio(symbols, quantity, price) {
    const sums = symbols.reduce((map, ticker, i ) => {
    ticker = ticker.toString();
    if (map[ticker].quantity) {
    map[ticker].quantity += Number(quantity[i]);
    } else {
    map[ticker].quantity = Number(quantity[i]);
    map[ticker].price = Number(price[i]) * map[ticker].quantity;
    }
    return map;
    }, {});
    return Object.entries(sums);
    }
    Code (markup):

    if you can get this working for me so all 3 columns get updated instead of just the 2 in the working script at the top, I can paypal you $25 just message me on skype. I will update this once its done. thanks so much :)

    skype:
    TravisBKlein
     
    phaze3131, Jun 11, 2022 IP