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
// begin config | |
const ghost_host = '<your host here>';//your blogs domain -- see documentation of tryghost/content-api | |
const ghost_key = '<your key here>';//key to your integration -- see documentation of tryghost/content-api | |
const updateInterval = 60000;//how often the index should update given in milliseconds | |
const requestTimeout = 5000;// maximum time for a search request before it times out given in milliseconds (note this isn't exact, it depends on the load of the event loop) | |
const resultsPerPage = [8];// allowed values for limit. in my case we only allow 8, but made this configurable so users of ghost can benefit | |
// end config | |
const elasticlunr = require('elasticlunr'); |
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
// i did poorly in my interview, the solution i gave worked but it was innefficient. | |
// splunk passed on me, but i couldn't let it go. so here is my final solution of the problem | |
function findFirstDuplicateInSeq( _seq ) { | |
const seq = [..._seq];// clone the array first so we are not mutating it. | |
while(true){ | |
const next = seq[seq.length-1].toString().split('').map(v=>Math.pow(~~v,2)).reduce((a,b)=>a+b,0);// next val is sum of digits squared | |
if(seq.indexOf(next)!==-1){ | |
return seq.length+1;// if seq contains our next value already, we found the first duplicate. return length+1 | |
} | |
seq.push(next);// no match, push the next val in to the sequence |
OlderNewer