Tuesday, 29 October 2019

code to compare to arrays and update based on value never returns update

I have a block of code in javascript that takes in an array of items from an API (the source of truth for this data) and it is supposed to update the data in my dynamo database when the update date on each object in the array does not match what I have. Everything looks right to me but I'm always returning that nothing needs to be updated even when I've validated updates exist. Not quite sure what I'm doing wrong here.

let count = 0;

    for (let appToCompare of arrayOfFormattedApps) {

        let hasMatch = false;

        for (let index = 1; index < currentCachedListOfApps.length; ++index) {
            var cachedApp = currentCachedListOfApps[index];

            if (cachedApp.ApplicationId === appToCompare.ApplicationId) {
                if (cachedApp.LastUpdateDateTime !== appToCompare.LastUpdateDateTime) {
                    arrayOfAppsWithUpdates.push(appToCompare);
                    hasMatch = true;
                    console.log(cachedApp.AppName + ' is being updated')
                    ++count;
                    break;
                }
            }
        }

        if (hasMatch) {
            arrayOfAppsWithUpdates.push(appToCompare);
        }
    }


from code to compare to arrays and update based on value never returns update

No comments:

Post a Comment