javascript - map a prefix on array of hashes and set a parameter in a promise chain -


// want map prefix ("myprefix") each member of array , use later "myprefix:yshepu" inside redis.prototype.exists function. is, because in redis db have different prefix:hash types.

the "exists" function return 0 or 1 , "getactive" function should later return filtered result array pure hashes stay in array. filter eleminates not existing array items. result array items should not have prefix "myprefix". redis lookup prefix should temporally used lookup correct hash. hope there solution, don't need use array.map 3 times

  • map prefix each array item
  • compute whole map again eleminate prefix each array item again

is there elegant , performant way in context?

this code:

var array = ["yshepu","mmxhhb", "qwertz", "wvlgrs", "knfght"];   var prefix = "myprefix";  redis.prototype.getactive = function (prefix, array) {     var self = this;      return this.q.all(array.map(self.exists.bind(self)))         .then(function (res) {             return array.filter(function (val, idx) {                 return res[idx];             });         }); };   redis.prototype.exists = function (prefix, key) {      return this.client.exists(prefix + ':' + key)         .then(function (data) {              return data; /* res 0 or 1 */         }); }; 


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -