I dont know this question actually...but I try to understand it by definition. I think the computational complexity is O(n^2) because we compare with every sub element with wrap array, it is two-demension comparation according my function writing.
Last active
December 22, 2017 11:33
-
-
Save dreamline2/da5de7ac2b0d477a004ad53a40ec3ce3 to your computer and use it in GitHub Desktop.
Oursky Pre-Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isSubset(wrap, sub) { | |
var result = true; | |
sub.map(function(letter){ | |
if (wrap.indexOf(letter) == -1) { result = false; } | |
}); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nextFibonacci (arr) { | |
var i; // every item of array | |
var j; // compare with max count | |
for (i = 0; i < arr.length; i++) { | |
for (j = 0; j < 60; j++) { | |
if (fibonacci(j) > arr[i]) { | |
console.log(fibonacci(j)) | |
break; | |
} | |
} | |
} | |
} | |
function fibonacci(value) { | |
if (value <= 1) return 1; | |
return fibonacci(value - 1) + fibonacci(value - 2); | |
} | |
nextFibonacci([1,9,22]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if you want to create array of functions, we need to execute anonymous function every time to pass i variable into return function. | |
// Therefore we can create array of functions by loop x+i; | |
function createArrayOfFunctions(y) { | |
var arr = []; | |
for(var i = 0; i<y; i++) { | |
arr[i] = (function(i) { | |
return function(x) { | |
return x + i; | |
} | |
})(i) | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment