this is my code. pretty simple code for finding unique values within an array. i’m confused on whether this is n time or n^2 time because the number of times the uniqueValues array is looped through is related to how big the length is. so that makes it somewhat unrelated to the for loop doesnt it?
function countUniqueValues(array) {
let uniqueArray = []; //constant
for (let i = 0; i < array.length; i++) { //n time
if (uniqueArray.includes(array[i])) { //n time
} else {
uniqueArray.push(array[i]); //constant time
}
console.log(i) //constant
console.log(uniqueArray) //constant
}
console.log(uniqueArray.length);
return uniqueArray.length;
}
countUniqueValues([1, 2, 3, 4, 4, 4, 7, 7, 12, 12, 13]);