Inventory update - TypeError: this is undefined

Inventory update - TypeError: this is undefined
0.0 0

#1

Hello there!, I finally made my solution of ‘Inventory update’ work but it throws TypeError: this is undefined. The code does what is intended as all seems to work fine in Runkit and all the green marks appear but I still don´t get the challenge approved. I tried solving it by just defining pos with let and return an array but that doesn’t work lol

function updateInventory(arr1, arr2) {
    let newObj = {};
    for(let x = 0, len = arr2.length;x < len;x++) {
        let isInCurrentInv = arr1.some((subArr, index) => {
            this.pos = index;
            return subArr[1] === arr2[x][1];
        });
        if(isInCurrentInv) {
            newObj[arr2[x][1].toLowerCase()] = arr2[x][0] + arr1[pos][0];
        } else {
            newObj[arr2[x][1].toLowerCase()] = arr2[x][0];
        }
    }
    for(let y = 0, len = arr1.length;y < len;y++) {
        if(!newObj.hasOwnProperty(arr1[y][1].toLowerCase())) {
            newObj[arr1[y][1].toLowerCase()] = arr1[y][0];
        }
    }
    let keys = Object.keys(newObj);
    keys = keys.sort();
    let newArr = [];
    for(let z = 0, len = keys.length;z < len;z++) {
        newArr.push([newObj[keys[z]], keys[z].replace(/\b\w/g, char => char.toUpperCase())]);
    }
    
    return newArr;
}

#2

When I paste your code into the challenge, it passes. Are you beta testing the new curriculum?


#3

Nope i don’t even know what is that