JSFiddle - React, Tailwind, and code Playground

by Ryan J

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.17.1/axios.js"></script>
<script src="https://momentjs.com/downloads/moment.min.js"></script>

JavaScript

var fundCode = 460
var selectedDate = '2017-10-31';

var arrHolder = [];
axios
  .get(`https://content.rbcgam.com/funds/growth-of-10k?rbcFundCode=${fundCode}`)
  .then(res => res.data)
  .then(data => {
    console.log(data.growthOf10K)
    var growthOf10kArrSinceInception = [];
    data.growthOf10K.map(fund => {
      if (moment(fund.key).isBefore(selectedDate) || moment(fund.key).isSame(selectedDate)) {
        growthOf10kArrSinceInception.push(fund);
      }
    });
    return growthOf10kArrSinceInception;
  })
  .then(growthOf10kArrSinceInception => {
    console.log("Show new array")
    console.log(growthOf10kArrSinceInception);

    //Get one year range and set in arr
    var tmpHolderArr = [];
    var selectedDateHolder = selectedDate;
    selectedDateHolder = moment(selectedDateHolder);
    var oneYearDate = moment(selectedDateHolder.subtract(1, 'year').add(1, 'month'));
    console.log("oneYearDate: " + oneYearDate.format('YYYY-MM-DD'));

    //Loop thru to get the ID of object in 1 Year
    var arrPointer = -1;
    var oneYearArrHolder = []
    growthOf10kArrSinceInception.map(fund => {
      var currentDateHolder = moment(fund.key);
      arrPointer++;
      if (oneYearDate.isSame(currentDateHolder)) {
        console.log(`Found date: ${fund.key} with the pointer value: ${arrPointer}`);
        console.log(`Showing the arr..`)
        console.log(growthOf10kArrSinceInception[arrPointer]);
        console.log(growthOf10kArrSinceInception[growthOf10kArrSinceInception.length - 1]);

        //Save new range of objs to one year arr holder
        oneYearArrHolder = growthOf10kArrSinceInception.slice(arrPointer, growthOf10kArrSinceInception.length);
      }
    });
    console.log("Showing oneYearArrHolder[]");
    console.log(oneYearArrHolder);

    //Add business logic
    var oneYearArrHolderProduct = null;
    oneYearArrHolder.map(fund => {
      console.log((fund.variation / 100) + 1)
      //console.log("BEFORE oneYearArrHolderProduct " +...