I'm fairly new to Big O and I am not sure what the time complexity of the following code will be:
const items = [
{type: 'phone', name: 'iPhone', color: 'gold'},
{type: 'phone', name: 'Samsung', color: 'gold'},
{type: 'laptop', name: 'Chromebook', color: 'gray'},
{type: 'tv', name: 'LG', color: 'gray'},
{type: 'gooo', name: 'LG', color: 'silver'},
{type: 'phone', name: 'Nokia', color: 'gold'}
];
items.filter(item => {
for(let i=0; i < Object.keys(item).length; i++) {
console.log('item is', Object.keys(item)[i])
}
})
Can we say this is O(i + c)
where i
is items
and c
is the constant console.log
? Or do we need to say something like O(i * j + c)
where j
is the individual item
i.e. {type: 'phone', name: 'iPhone', color: 'gold'}
Can someone please help me out... thank you in advance!