Skip to content

Instantly share code, notes, and snippets.

@RusAlex
Created August 7, 2017 09:49
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 RusAlex/4400808c3f1c447955f2d3c3e6d8efee to your computer and use it in GitHub Desktop.
Save RusAlex/4400808c3f1c447955f2d3c3e6d8efee to your computer and use it in GitHub Desktop.
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