Skip to content

Instantly share code, notes, and snippets.

Avatar
🤠

Meli DataIsMeta

🤠
View GitHub Profile
View index.js
//Log all pairs of array
//O(n^2)
const boxes = [1,2,3,4,5];
function logAllPairs(array){
for(let i = 0; i < array.length; i++){
for(let j = 0; j < array.length; j++){
console.log(array[i], array[j]);
}
}
View index.js
//Log all pairs of array
//O(n^2)
const boxes = [1,2,3,4,5];
function logAllPairs(array){
for(let i = 0; i < array.length; i++){
for(let j = 0; j < array.length; j++){
console.log(array[i], array[j]);
}
}
@DataIsMeta
DataIsMeta / index.js
Created Jan 21, 2019
ShinyValuableConversions created by DataIsMeta - https://repl.it/@DataIsMeta/ShinyValuableConversions
View index.js
//What is the Big O of the below function?
function anotherFunChallenge(input){
let a = 5; // O(1)
let b = 10; // O(1)
let c = 50; // O(1)
for(let i = 0; i < input; i++){ // O(n)
let x = i + 1; // O(n)
let y = i + 2; // O(n)
let z = i + 3; // O(n)
}
View index.js
// What is the Big O of the below function?
function funChallenge(input) {
let a = 10; // O(1)
a = 50 + 3; // O(1)
// O(1) Constant Time
for (let i = 0; i < input.length; i++) { // O(n)
anotherFunction(); // O(n)
let stranger = true; // O(n)
a++; // O(n) Linear Time
}
View index.js
// O(1) = Constant time
const boxes = [0,1,2,3,4,5];
function logFirstTwoBoxes(boxes){
console.log(boxes[0]); // O(1)
console.log(boxes[1]); // O(1)
}
logFirstTwoBoxes(boxes); // function is running O(2) operations
You can’t perform that action at this time.