Skip to content

Instantly share code, notes, and snippets.

@dreamline2
Last active December 22, 2017 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreamline2/da5de7ac2b0d477a004ad53a40ec3ce3 to your computer and use it in GitHub Desktop.
Save dreamline2/da5de7ac2b0d477a004ad53a40ec3ce3 to your computer and use it in GitHub Desktop.
Oursky Pre-Test
function isSubset(wrap, sub) {
var result = true;
sub.map(function(letter){
if (wrap.indexOf(letter) == -1) { result = false; }
});
return result;
}

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.

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]);
// 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