function generateTrade(stockQuant, stockPrice, action, assetClass, broker, user, date, tradeType) {
  return {
    shares: stockQuant,
    price: stockPrice,
    action: action,
    assetClass: assetClass,
    broker: broker,
    user: user,
    date: date,
    type: tradeType
  };
}

function generateFifo(type, date, security, actions, quantity, price, assetClass, broker, user) {
  let positionsMap = new Map();
  
  for (var i = 0; i < security.length; i++) {
    // Skip empty rows
    if (!security[i] && !actions[i] && !quantity[i] && !price[i]) {
      continue;
    }
    var currentType = type[i] ? type[i].toString().trim().toLowerCase() : '';
    var currentDate = date[i] ? new Date(date[i]) : new Date();
    var ticker = security[i] ? security[i].toString().trim() : '';
    var action = actions[i] ? actions[i].toString().trim().toLowerCase() : '';
    
    var stockQuant = Number(quantity[i]) || 0;
    var stockPrice = Number(price[i]) || 0;
    
    var currentAssetClass = assetClass && assetClass[i] ? assetClass[i] : 'Unknown';
    var currentBroker = broker && broker[i] ? broker[i] : 'Unknown';
    var currentUser = user && user[i] ? user[i] : 'Unknown';

    let tradeType = '';  // Will determine this based on action

    // Only process delivery trades
    if (currentType === 'delivery') {
      if (action === 'buy') {
        tradeType = 'Long';
        let key = `${ticker}|${currentBroker}|${currentUser}|${currentAssetClass}|${tradeType}`;
        let trade = generateTrade(stockQuant, stockPrice, action, currentAssetClass, currentBroker, currentUser, currentDate, tradeType);
        let activeTrades = positionsMap.get(key);
        if (!activeTrades) {
          positionsMap.set(key, [trade]);
        } else {
          activeTrades.push(trade);
        }
      } else if (action === 'sell') {
        tradeType = 'Long';  // Selling from Long positions
        let key = `${ticker}|${currentBroker}|${currentUser}|${currentAssetClass}|${tradeType}`;
        let activeTrades = positionsMap.get(key);
        if (activeTrades) {
          let sharesToProcess = stockQuant;
          activeTrades.sort((a, b) => new Date(a.date) - new Date(b.date)); // ensure FIFO
          let iTrade = 0;
          while (sharesToProcess > 0 && iTrade < activeTrades.length) {
            let trade = activeTrades[iTrade];
            if (trade.shares <= sharesToProcess) {
              sharesToProcess -= trade.shares;
              activeTrades.splice(iTrade, 1);
            } else {
              trade.shares -= sharesToProcess;
              sharesToProcess = 0;
            }
          }
          if (activeTrades.length == 0) {
            positionsMap.delete(key);
          }
        }
      } else if (action === 'sellshort') {
        tradeType = 'Short';
        let key = `${ticker}|${currentBroker}|${currentUser}|${currentAssetClass}|${tradeType}`;
        let trade = generateTrade(stockQuant, stockPrice, action, currentAssetClass, currentBroker, currentUser, currentDate, tradeType);
        let activeTrades = positionsMap.get(key);
        if (!activeTrades) {
          positionsMap.set(key, [trade]);
        } else {
          activeTrades.push(trade);
        }
      } else if (action === 'buytocover') {
        tradeType = 'Short';  // Covering Short positions
        let key = `${ticker}|${currentBroker}|${currentUser}|${currentAssetClass}|${tradeType}`;
        let activeTrades = positionsMap.get(key);
        if (activeTrades) {
          let sharesToProcess = stockQuant;
          activeTrades.sort((a, b) => new Date(a.date) - new Date(b.date)); // ensure FIFO
          let iTrade = 0;
          while (sharesToProcess > 0 && iTrade < activeTrades.length) {
            let trade = activeTrades[iTrade];
            if (trade.shares <= sharesToProcess) {
              sharesToProcess -= trade.shares;
              activeTrades.splice(iTrade, 1);
            } else {
              trade.shares -= sharesToProcess;
              sharesToProcess = 0;
            }
          }
          if (activeTrades.length == 0) {
            positionsMap.delete(key);
          }
        }
      }
    } else if (currentType === 'corp. action' && action === 'split') {
      // process split
      let splitRatioStr = quantity[i].toString();
      let ratioParts = splitRatioStr.split(':');
      let numerator = parseFloat(ratioParts[0]);
      let denominator = parseFloat(ratioParts[1]);
      let ratio = numerator / denominator;
      positionsMap.forEach((value, pKey) => {
        if (pKey.startsWith(`${ticker}|`)) {
          value.forEach(trade => {
            trade.shares *= ratio;
            trade.price /= ratio;
          });
        }
      });
    } else if (currentType === 'my action') {
      if (action === 'transferfrom') {
        // Assuming transfer applies to Long positions
        tradeType = 'Long';
        let transferKey = `${ticker}|${currentBroker}|${currentUser}|${currentAssetClass}|${tradeType}`;
        let newBroker = broker[i + 1] ? broker[i + 1] : 'Unknown';
        let newKey = `${ticker}|${newBroker}|${currentUser}|${currentAssetClass}|${tradeType}`;
        let activeTrades = positionsMap.get(transferKey);
        if (activeTrades) {
          let sharesToTransfer = stockQuant;
          let totalAvailableShares = activeTrades.reduce((sum, trade) => sum + trade.shares, 0);
          if (sharesToTransfer > totalAvailableShares) {
            continue; // Skip this transfer if not enough shares
          }
          let transferredTrades = [];
          activeTrades.sort((a, b) => new Date(a.date) - new Date(b.date)); // ensure FIFO
          while (sharesToTransfer > 0 && activeTrades.length > 0) {
            let trade = activeTrades[0];
            if (trade.shares <= sharesToTransfer) {
              sharesToTransfer -= trade.shares;
              transferredTrades.push({...trade}); // Copy trade to new broker
              activeTrades.splice(0,1);
            } else {
              let transferredTrade = {...trade, shares: sharesToTransfer};
              trade.shares -= sharesToTransfer;
              sharesToTransfer = 0;
              transferredTrades.push(transferredTrade);
            }
          }
          if (activeTrades.length == 0) {
            positionsMap.delete(transferKey);
          }
          // Add transferred trades to new broker
          let newActiveTrades = positionsMap.get(newKey);
          if (!newActiveTrades) {
            positionsMap.set(newKey, transferredTrades);
          } else {
            newActiveTrades.push(...transferredTrades);
          }
        }
      }
    }
  }
  return positionsMap;
}

function myPositions(type, date, security, actions, quantity, price, assetClass, broker, user) {
  let positionsMap = generateFifo(type, date, security, actions, quantity, price, assetClass, broker, user);
  let returnArry = [['SN.', 'Ticker', 'Type', '# Shares', 'Avg. Buy @', 'Asset Class', 'Broker', 'User']];
  let sn = 1;
  let sortedKeys = Array.from(positionsMap.keys()).sort();
  sortedKeys.forEach(key => {
    let value = positionsMap.get(key);
    let totalShares = 0;
    let totalCost = 0;
    let avgPrice = 0;
    let [ticker, currentBroker, currentUser, currentAssetClass, longOrShort] = key.split('|');
    value.forEach(trade => {
      totalShares += trade.shares;
      totalCost += trade.shares * trade.price;
    });
    avgPrice = totalShares > 0 ? totalCost / totalShares : 0;

    returnArry.push([
      sn++,
      ticker,
      longOrShort,
      totalShares.toFixed(2),
      avgPrice.toFixed(2),
      currentAssetClass,
      currentBroker,
      currentUser
    ]);
  });
  return returnArry;
}


is this code formatting number of shares in output as number or text format.