Created
August 7, 2017 09:49
-
-
Save RusAlex/4400808c3f1c447955f2d3c3e6d8efee to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let storage = []; | |
let tmpObject = {}; | |
module.exports = { | |
refresh: function (functionNames, modificationDates) { | |
for (let i = 0; i < functionNames.length; i++) { | |
tmpObject[functionNames[i]] = modificationDates[i]; | |
} | |
functionNames.sort( | |
(a, b) => { | |
if (tmpObject[a] > tmpObject[b]) return 1; | |
if (tmpObject[a] < tmpObject[b]) return -1; | |
if (a > b) return 1; | |
if (a < b) return -1; | |
return 0; | |
} | |
); | |
storage = functionNames; | |
}, | |
guess: function (start) { | |
function matchString(element, index, array) { | |
return element.substring(0, start.length) === start; | |
} | |
if (!storage.some(matchString)) { | |
return []; | |
} | |
let startIndex = 0; | |
let counter = 0, i = startIndex; | |
let result = []; | |
let el; | |
while(counter < 12 && i < storage.length) { | |
el = storage[i]; | |
if (el.substring(0, start.length) === start) { | |
result.push(el); | |
counter++; | |
} | |
i++; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment