Advertisement
Sparkster

Untitled

Nov 13th, 2013
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Array.prototype.codewarsCharCode = function (n) {
  2.   return 99 +
  3.   Math.min(12, n * 12) -
  4.   Math.min(11, Math.max(n - 1, 0) * 11) +
  5.   Math.min( 1, Math.max(n - 2, 0) *  1) +
  6.   Math.min(18, Math.max(n - 3, 0) * 18) -
  7.   Math.min(22, Math.max(n - 4, 0) * 22) +
  8.   Math.min(17, Math.max(n - 5, 0) * 17) +
  9.   Math.min( 1, Math.max(n - 6, 0) *  1)
  10. }
  11.  
  12. Array.prototype.codewarsString = function() {
  13.   var i, result = '';
  14.   for (i = 0; i < 8; i++) {
  15.     result = result.slice(0, i) + String.fromCharCode(this.codewarsCharCode(i)) + result.slice(i);
  16.   }
  17.   return result;
  18. }
  19.  
  20. Array.prototype.codewars = function () {
  21.   var index, i;
  22.   index = this.indexOf(this.codewarsString);
  23.   if (index !== -1) {
  24.     this.splice(0, index);
  25.     this.splice(index - 1, this.length);
  26.   } else {
  27.     this.splice(0, this.length);
  28.     this.push(this.codewarsString());
  29.   }
  30. }
  31.  
  32. websites.codewars(); // :D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement