lib.js 597 B

12345678910111213141516171819
  1. Array.prototype.count = function(fnc) {
  2. return this.reduce((total, i, index) => fnc(i, index) ? total+1 : total, 0);
  3. }
  4. Array.prototype.countUnique = function(fnc) {
  5. return this.reduce((total, i, index) => (total.indexOf(i) === -1 && fnc(i, index)) ? total.concat(i):total, []).length;
  6. }
  7. async function sleep(duration) {
  8. return new Promise((ok, ko) => setTimeout(ok, duration));
  9. }
  10. const COLOR_RESET = '\x1B[39m';
  11. const CLEAR_SCR = '\033[2J';
  12. const COLOR_MAP = [ '\033[31m', '\033[32m', '\033[33m', '\033[35m', '\033[36m' ];
  13. const chars = ['@', '!', '$', '%', '+', '=', '?', '#'];