JSFiddle - React, Tailwind, and code Playground

by joplomacedo

JavaScript

function getTickers( tweetText ) {
  const tickers = [];

  let tickerInBuilding = null;

  for( let i = 0; i < tweetText.length; i++) {
      let char = tweetText[i];

      if ( tickerInBuilding !== null ) {
        if ( char !== ' ' ) {
          tickerInBuilding += char;
        } else {
          tickers.push(tickerInBuilding.toUpperCase());
          tickerInBuilding = null;
        }

      } else {
        if ( char === "$" ) {
          tickerInBuilding = '';
        }
      }
  }

  return tickers;
}


txt = ' asodoas d as d as d as d sa  $appl d  a4 asd $tsla asdas asd  sa';


tickers =  getTickers(txt);

console.log('tickers', tickers)