Tell us what’s happening:
i am writing programs in java, how come arrays increase the size dynamically without using predefined data structure provided by java.
if we cant increase the size dynamically then there is no point in adding new inventory item.
Your code so far
function updateInventory(arr1, arr2) {
// All inventory must be accounted for or you're fired!
return arr1;
}
// Example inventory lists
var curInv = [
[21, "Bowling Ball"],
[2, "Dirty Sock"],
[1, "Hair Pin"],
[5, "Microphone"]
];
var newInv = [
[2, "Hair Pin"],
[3, "Half-Eaten Apple"],
[67, "Bowling Ball"],
[7, "Toothpaste"]
];
updateInventory(curInv, newInv);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
.
Challenge: Inventory Update
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Sky020
August 12, 2020, 3:30pm
2
Welcome, ylnsagar.
Just to clarify: The freeCodeCamp curriculum does not teach Java, it has content relating to JavaScript. This code is all JavaScript.
Which predefined data structure are you referring to?
How could an array dynamically increase its size, if it was predefined?
Why do you think you cannot increase the size?
by predefined data structure, i meant that like ArrayList or dynamic array etc.
so without creating a new array how can we update the inventory if a new item needs to be added?. if we have to use only 2 arrays, then update of existing inventory item is possible but not adding a new value.
if i am wrong please guide me.
hii, i am sorry. i didnt realize freeCodeCamp is pure javascript related.
sorry for the trouble.
Sky020
August 12, 2020, 5:07pm
5
I think you are making the challenge more complicated than it needs to be. All you need to do is:
Compare arr1
to arr2
If arr2
contains an element similar to another in arr1
, but with a different number, then update the number.
If arr2
contains an element non-existent in arr1
, update to include this new element.
Return a new array containing all updated, current, and new elements from arr1
and arr2
.
I hope that is clearer.