[
  {
    "path": "\"this\" is an other problem.js",
    "content": "/*\nDescription:\nAfter you've solved @priyankaherur's problem ( http://www.codewars.com/kata/this-is-a-problem/javascript ) you may try to solve this other one.\n\nThe problem:\nHaving created a function NamedOne which takes first & last names as parameters and returns an object with firstName, lastName and fullName ( = firstName + a space + lastName ) properties which should be all accessibles, we discovered that \"accessible\" also means \"mutable\".\n\nIf, for example, we've got a \"NamedOne\" like this :\n\nvar namedOne = new NamedOne(\"Naomi\",\"Wang\")\nnamedOne.firstName // -> \"Naomi\"\nnamedOne.lastName  // -> \"Wang\"\nnamedOne.fullName  // -> \"Naomi Wang\"\n...properties may be changed :\n\nnamedOne.firstName = \"John\"\nnamedOne.firstName // -> \"John\"\nnamedOne.lastName = \"Doe\"\nnamedOne.lastName  // -> \"Doe\"\n...but all properties are not updated !\n\nnamedOne.fullName  // -> \"Naomi Wang\" \n//-- Oh no ! we want fullName == \"John Doe\" now !\nYour mission:\nSo the purpose of this kata is to create an object with accessible and \"updatable\" (can i say that?) properties.\n\nIf .firstName or .lastName are changed, then .fullName should also be changed\nIf .fullName is changed, then .firstName and .lastName should also be changed.\nNote : \"input format\" to .fullName will be firstName + space+ lastName. If given fullName isn't valid then no property is changed.\n\nExamples:\nvar namedOne = new NamedOne(\"Naomi\",\"Wang\")\n\nnamedOne.firstName = \"John\"\nnamedOne.lastName = \"Doe\"\n// ...then...\nnamedOne.fullName // -> \"John Doe\"\n\n// -- And :\nnamedOne.fullName = \"Bill Smith\"\n// ...then...\nnamedOne.firstName // -> \"Bill\"\nnamedOne.lastName  // -> \"Smith\"\n\n// -- But :\nnamedOne.fullName = \"Tom\" // -> no : lastName missing\nnamedOne.fullName = \"TomDonnovan\" // -> no : no space between first & last names\nnamedOne.fullName // -> \"Bill Smith\" (unchanged)\nCan you change our function to create such a NamedOne object ?\n\n( Hint: in this kata you'll try to define properties of an object )\n*/\nclass NamedOne {\n  constructor(f, l) { this.firstName = f; this.lastName = l }\n  get fullName() { return this.firstName + ' ' + this.lastName }\n  set fullName(v) { if (/ /.test(v)) [this.firstName, this.lastName] = v.split(' ') }\n}\n"
  },
  {
    "path": "\"this\" is an other solution.js",
    "content": "/*\nDescription:\nIn a previous kata ( http://www.codewars.com/kata/547f1a8d4a437abdf800055c ) we try to create an object with mutable properties.\n\nThe function NamedOne taken first & last names as parameters, returned an object with firstName, lastName and fullName ( = firstName + a space + lastName ) properties. These properties were mutable.\n\nFor example, with a \"NamedOne\" like this :\n\nvar namedOne = new NamedOne(\"Naomi\",\"Wang\")\nnamedOne.fullName  // -> \"Naomi Wang\"\n...we were able to change its properties:\n\nnamedOne.firstName = \"John\" \nnamedOne.lastName = \"Doe\"\nnamedOne.fullName  // -> \"John Doe\" \n//..or..\nnamedOne.fullName = \"Bill Smith\"\nnamedOne.firstName // -> \"Bill\" \nnamedOne.lastName // -> \"Smith\"\n##Your mission\n\nOn the contrary, the purpose of this kata is to create an OnceNamedOne object with immutable properties.\n\nThat means .firstName, .lastName and .fullName are defined into the Constructor and can't be no more changed.\n\nThe properties are still readable using the dot or bracket notation but there're not writable.\n\n##Examples:\n\nvar onceNamed = new OnceNamedOne(\"Naomi\",\"Wang\")\n\n// ...then...\nonceNamed.firstName // -> \"Naomi\"\nonceNamed.lastName  // -> \"Wang\"\nonceNamed.fullName // -> \"Naomi Wang\"\n\n// ...if you try : ...\nonceNamed.firstName = \"Bill\"\n// ...or...\nonceNamed['lastName'] = \"Smith\"\n\n// ...then...\nonceNamed['firstName'] // -> \"Naomi\"\nonceNamed['lastName']  // -> \"Wang\"\nonceNamed['fullName'] // -> \"Naomi Wang\"\n\n// ..but you can still create other instances..\nvar otherOne = new OnceNamedOne(\"Don\",\"Jones\")\notherOne.fullName // -> \"Don Jones\"\nCan you change our function to create such a OnceNamedOne object ?\n\n( Hint: in this kata you'll try to define properties of an object )\n*/\nfunction OnceNamedOne(first, last) {\n    this.firstName = first;\n    this.lastName = last;\n    this.fullName = this.firstName + ' ' + this.lastName;\n    Object.freeze(this)\n}\n"
  },
  {
    "path": "(L33T + Grεεκ) Case.js",
    "content": "/*\nDescription:\nGetting Familiar: LEET: (sometimes written as \"1337\" or \"l33t\"), also known as eleet or leetspeak, is another alphabet for the English language that is used mostly on the internet. It uses various combinations of ASCII characters to replace Latinate letters. For example, leet spellings of the word leet include 1337 and l33t; eleet may be spelled 31337 or 3l33t.\n\nGREEK: The Greek alphabet has been used to write the Greek language since the 8th century BC. It was derived from the earlier Phoenician alphabet, and was the first alphabetic script to have distinct letters for vowels as well as consonants. It is the ancestor of the Latin and Cyrillic scripts.Apart from its use in writing the Greek language, both in its ancient and its modern forms, the Greek alphabet today also serves as a source of technical symbols and labels in many domains of mathematics, science and other fields.\n\nYour Task :\n\nYou have to create a function **GrεεκL33t** which    \ntakes a string as input and returns it in the form of \n(L33T+Grεεκ)Case.\nNote: The letters which are not being converted in \n(L33T+Grεεκ)Case should be returned in the lowercase.\n(L33T+Grεεκ)Case:\n\nA=α (Alpha)      B=β (Beta)      D=δ (Delta)\nE=ε (Epsilon)    I=ι (Iota)      K=κ (Kappa)\nN=η (Eta)        O=θ (Theta)     P=ρ (Rho)\nR=π (Pi)         T=τ (Tau)       U=μ (Mu)      \nV=υ (Upsilon)    W=ω (Omega)     X=χ (Chi)\nY=γ (Gamma)\nExamples:\n\nGrεεκL33t(\"CodeWars\") = \"cθδεωαπs\"\nGrεεκL33t(\"Kata\") = \"κατα\"\n*/\nfunction GrεεκL33t(str){\n  let dict = {a:'α',b:'β',d:'δ',e:'ε',i:'ι',k:'κ',n:'η',o:'θ',p:'ρ',r:'π',t:'τ',u:'μ',\n  v:'υ',w:'ω',x:'χ',y:'γ'}\n  return str.replace(/./g,v=>{\n    if (dict[v.toLowerCase()]){\n      return v===v.toUpperCase()?dict[v.toLowerCase()]:dict[v]\n    }\n    return v.toLowerCase()\n  })\n}\n"
  },
  {
    "path": "+1 Array.js",
    "content": "/*\nDescription:\nGiven an array of integers of any length, return an array that has 1 added to the value represented by the array.\n\nthe array can't be empty\nonly non-negative, single digit integers are allowed\nReturn nil (or your language's equivalent) for invalid inputs.\n\nExamples\nFor example the array [2, 3, 9] equals 239, adding one would return the array [2, 4, 0].\n\n[4, 3, 2, 5] would return [4, 3, 2, 6]\n*/\nfunction upArray(arr){\n  if (!arr.every(v=>v>=0)||arr.length===0) return null\n  if (arr.some(v=>v.toString().length>1)) return null\n  let arr1 =[];\n  for (let i=0;i<arr.length;i+=15){\n  arr1.push(arr.slice(i,i+15))\n  }\n  arr1[arr1.length-1]= arr1[arr1.length-1].join('')*1+1\n  arr1=arr1.map(v=>Array.isArray(v)?v.join('')*1:v)\n  return (arr1.join('')).split('').map(v=>v*1)\n}\n"
  },
  {
    "path": "1 n- Cycle.js",
    "content": "/*\nDescription:\nLet be n an integer prime with 10 e.g. 7.\n\n1/7 = 0.142857 142857 142857 ....\n\nWe see that the decimal part has a cycle: 142857. The length of this cycle is 6. In the same way:\n\n1/11 = 0.09 09 09 .... Cycle length is 2.\n\nTask\nGiven an integer n (n > 1), the function cycle(n) returns the length of the cycle if n and 10 are coprimes, otherwise returns -1.\n\nExemples:\ncycle(5) = -1\ncycle(13) = 6 -> 0.076923 076923 0769\ncycle(21) = 6 -> 0.047619 047619 0476\ncycle(27) = 3 -> 0.037 037 037 037 0370\ncycle(33) = 2 -> 0.03 03 03 03 03 03 03 03\ncycle(37) = 3 -> 0.027 027 027 027 027 0\ncycle(94) = -1 \n\ncycle(22) = -1 since 1/22 ~ 0.0 45 45 45 45 ...\n*/\nfunction cycle(n) {\n if (n%2 == 0 || n%5 == 0) {\n    return -1\n  } else {\n    let res = 10 % n, c = 1;\n    while (res != 1) \n    {\n        res = res * 10 % n; \n        c++;\n    }\n    return c;\n    }\n}\n"
  },
  {
    "path": "1RM Calculator.js",
    "content": "/*\nDescription:\nYou just got done with your set at the gym, and you are wondering how much weight you could lift if you did a single repetition. Thankfully, a few scholars have devised formulas for this purpose (from Wikipedia) :\n\nEpley\n\nMcGlothin\n\nLombardi\n\nYour function will receive a weight w and a number of repetitions r and must return your projected one repetition maximum. Since you are not sure which formula to use and you are feeling confident, your function will return the largest value from the three formulas shown above, rounded to the nearest integer. However, if the number of repetitions passed in is 1 (i.e., it is already a one rep max), your function must return w. Also, if the number of repetitions passed in is 0 (i.e., no repetitions were completed), your function must return 0.\n*/\nfunction calculate1RM(w, r){\n  let a= w *(1+r/30);\n  let b= (100*w)/(101.3-2.67123*r);\n  let c=w*(r**0.1);\n  if (r===0||w===0) return 0;\n  if (r===1) return w;\n  return Math.round(Math.max(a,b,c))\n}\n"
  },
  {
    "path": "80's Kids #7: She's a Small Wonder.js",
    "content": "/*\nDescription:\nVicky is quite the small wonder. Most people don't even realize she's not a real girl, but a robot living amongst us. Sure, if you stick around her home for a while you might see her creator open up her back and make a few tweaks and even see her recharge in the closet instead of sleeping in a bed.\n\nIn this kata, we're going to help Vicky keep track of the words she's learning.\n\nWrite a function, learnWord(word) which is a method of the Robot object. The function should report back whether the word is now stored, or if she already knew the word.\n\nExample:\n\nvar vicky = new Robot();\nvicky.learnWord('hello') -> 'Thank you for teaching me hello'\nvicky.learnWord('abc') -> 'Thank you for teaching me abc'\nvicky.learnWord('hello') -> 'I already know the word hello'\nvicky.learnWord('wow!') -> 'I do not understand the input'\nRobot vicky = new Robot();\nvicky.learnWord(\"hello\") -> \"Thank you for teaching me hello\"\nvicky.learnWord(\"abc\") -> \"Thank you for teaching me abc\"\nvicky.learnWord(\"hello\") -> \"I already know the word hello\"\nvicky.learnWord(\"wow!\") -> \"I do not understand the input\"\nCase shouldn't matter. Only alpha characters are valid. There's also a little trick here. Enjoy!\n*/\nfunction Robot() {\n  this.arr =['i', 'already', 'know', 'the', 'word','thank', 'you', 'for','me','teaching','understand']\n}\n\nRobot.prototype.learnWord = function(word) {\n  if (/\\W|\\d|\\s/i.test(word)||!word) return \"I do not understand the input\"\n  if (!this.arr.includes(word.toLowerCase())){\n  this.arr.push(word.toLowerCase())\n  return `Thank you for teaching me ${word}`\n  }else\n  return `I already know the word ${word}`\n}\n"
  },
  {
    "path": "A Rule of Divisibility by 13.js",
    "content": "/*\nDescription:\nWhen you divide the successive powers of 10 by 13 you get the following remainders of the integer divisions:\n\n1, 10, 9, 12, 3, 4.\n\nThen the whole pattern repeats.\n\nHence the following method: Multiply the right most digit of the number with the left most number in the sequence shown above, the second right most digit to the second left most digit of the number in the sequence. The cycle goes on and you sum all these products. Repeat this process until the sequence of sums is stationary.\n\n...........................................................................\n\nExample: What is the remainder when 1234567 is divided by 13?\n\n7×1 + 6×10 + 5×9 + 4×12 + 3×3 + 2×4 + 1×1 = 178\n\nWe repeat the process with 178:\n\n8x1 + 7x10 + 1x9 = 87\n\nand again with 87:\n\n7x1 + 8x10 = 87\n\n...........................................................................\n\nFrom now on the sequence is stationary and the remainder of 1234567 by 13 is the same as the remainder of 87 by 13: 9\n\nCall thirt the function which processes this sequence of operations on an integer n (>=0). thirt will return the stationary number.\n\nthirt(1234567) calculates 178, then 87, then 87 and returns 87.\n\nthirt(321) calculates 48, 48 and returns 48\n*/\nfunction thirt(n) {\n   const dict=[1, 10, 9, 12, 3, 4]\n   let sum=n;\n   while(1){\n       let temp=sum\n       sum=sum.toString().split``.reverse().join``.split``.map((v,i)=>{\n         v=v*dict[i%6]\n         return v\n       }).reduce((a,b)=>a+b,0)\n       if (sum===temp){break}\n     }\n   return sum\n}\n"
  },
  {
    "path": "A String of Sorts.js",
    "content": "/*\nDescription:\nDefine a method that accepts 2 strings as parameters. The method returns the first string sorted by the second.\n\nsortString(\"foos\", \"of\")       => \"oofs\"\n\nsortString(\"string\", \"gnirts\") => \"gnirts\"\n\nsortString(\"banana\", \"abn\")    => \"aaabnn\"\nTo elaborate, the second string defines the ordering. It is possible that in the second string characters repeat, so you should remove repeating characters, leaving only the first occurrence.\n\nAny character in the first string that does not appear in the second string should be sorted to the end of the result in original order.\n*/\nfunction sortString(string,ordering) {\n  ordering=ordering.split``\n  let arr1 = string.split``.filter(v=>ordering.includes(v)).sort((a,b)=>ordering.indexOf(a)-ordering.indexOf(b))\n  let arr2 = string.split``.filter(v=>!ordering.includes(v))\n  return arr1.join``+arr2.join``\n}\n"
  },
  {
    "path": "A Taste of Curry.js",
    "content": "/*\nDescription:\nYour relative have decided to open a small Indian restaurant, and so she bought an automatic cooker. It publishes an API function\n\nfunction cook(\n    /*String*/ dish,\n    /*Number*/ nServings\n    /* , other params, specific to the dish - represented by strings */\n) {\n    ...\n}```\n\n which takes an amount of servings, dish name and several other parameters which can vary per dish (yes, this is a very advanced cooking machine).\n\nThe restaurant instantly became very popular, and your relative noticed that most people order some curry with additional ingredients - because she was already tired to repeatedly type the word _'curry'_  when making a request to cooker. So she decided to ask for your help.\n\nShe cannot lend you her cooker, because it is in constant use - so she needs you to write a function\n\n```javascript\nfunction curry(fun, /*args*/) { \n    ...\n}\nwhich takes another function fun and an arbitrary number of other arguments - and returns a function, which works like fun with the first arguments replaced by the remaining arguments of curry.\n\nFor example\n\nfunction add(a, b, c) { return a+b+c; }\nvar addOne = curry(add , 1);\n\nadd(1, 2, 3) === addOne(2, 3);\nAnd one more thing - some code warrior who was having a snack at your relative's restaurant told her that there is such thing as execution context, and that the cook function might rely on it somehow - it is designed to work exclusively with cooking machine after all.\n\nSo another request for curry function is that if the resulting function is invoked with context ctx the original function inside it should also be invoked with context ctx\n\nFor example,\n\nvar obj = {\n  a: 'foo',\n  b: function (a) { return this.a + a; }\n}\n\nobj.foobar = curry(obj.b, 'bar');\nobj.foobar() //should return foobar\n*/\nfunction curry(fun,...args) {\n    return function(...arg2) {\n    return fun.call(this,...args,...arg2);\n  }\n}\n"
  },
  {
    "path": "A disguised sequence (I).js",
    "content": "/*\nDescription:\nGiven u0 = 1, u1 = 2 and the relation 6unun+1-5unun+2+un+1un+2 = 0 calculate un for any integer n >= 0.\n\n#Examples\n\nfcn(n) returns un: fcn(17) -> 131072, fcn(21) -> 2097152\n\nRemark: You can take two points of view to do this kata:\n\nthe first one purely algorithmic from the definition of un\n\nthe second one - not at all mandatory, but as a complement - is to get a bit your head around and find which sequence is hidden behind un.\n*/\nfunction fcn (n) {\n    return 2**n\n}\n"
  },
  {
    "path": "A tetrahedron of cannonballs.js",
    "content": "/*\nDescription:\nPreviously on Codewars...\n\n\"Triangular numbers are so called because of the equilateral triangular shape that they occupy when laid out as dots. i.e.\n\n1st (1)   2nd (3)    3rd (6)\n*          **        ***\n           *         **\n                     *\nIn the Triangular Treasure kata you need to return the nth triangular number.\"\n\n(If you haven't solved Triangular Treasure go solve it, cause you are going to need the solution here)\n\nNow, in this kata...\n\nThe triangular number you just calculated is going to be the base of our \"brand new\" tetrahedral stack.\n\nYou need to calculate the number of cannonballs that can be stacked to form a regular tetrahedron with the given edge's length.\n\nA regular tetrahedron is a platonic solid composed of triangular faces with all the edges having the same length. *** Please note, this is not a square pyramid, but a triangular one\n\nFor our problem, we are going to consider that the length of the edge is the number of cannonballs that can be lined up along one edge. *** Please note, we are not talking about volume here, we are talking about stacking spheres.\n\nSo. Given an edge with length = 1, the number of cannonballs contained in the base triangle (the triangular number) will be 1, and the number of cannonballs you would be able to stack in a regular tetrahedron will be 1.\n\nThe table for the series is this:\n\n(edge's length -> triangular number -> \"cannonball number\")\n\n 1 ->   1 ->    1\n 2 ->   3 ->    4\n 3 ->   6 ->   10\n 4 ->  10 ->   20\n 5 ->  15 ->   35\n 6 ->  21 ->   56\n 7 ->  28 ->   84\n 8 ->  36 ->  120\n 9 ->  45 ->  165\n10 ->  55 ->  220\n11 ->  66 ->  286\n12 ->  78 ->  364\n13 ->  91 ->  455\n14 -> 105 ->  560\n15 -> 120 ->  680\n16 -> 136 ->  816\n17 -> 153 ->  969\n18 -> 171 -> 1140\n19 -> 190 -> 1330\n20 -> 210 -> 1540 \nYou can see some properties here:\n\nThe nth triangular number is: t(n) = n + t(n-1)\nThe nth cannonball number is: c(n) = t(n) + c(n-1)\nHint: Remember that, even though, we are talking about tetrahedrons the key number here is not 4 but 3.\n\n*** Please, don't worry about the parameters. You will only receive positive integers.\n*/\nfunction tetrahedron(size) {\n  return size*(size + 1)*(size + 2)/6\n}\n"
  },
  {
    "path": "ASCII hex converter.js",
    "content": "/*\nWrite a module Converter that can take ASCII text and convert it to hexadecimal. The class should also be able to take hexadecimal and convert it to ASCII text.\n\nExample\nConverter.toHex(\"Look mom, no hands\")\n=> \"4c6f6f6b206d6f6d2c206e6f2068616e6473\"\n\nConverter.toAscii(\"4c6f6f6b206d6f6d2c206e6f2068616e6473\")\n=> \"Look mom, no hands\"\n*/\nvar Converter = {\n  toAscii: function (hex) {\n    let arr=[];\n    for (let i=0;i<hex.length;i+=2){\n        arr.push(hex.slice(i,i+2))\n      }\n    return arr.map(v=>String.fromCharCode(parseInt(v,16))).join('')\n  },\n  toHex: function (ascii) {\n     return ascii.split('').map(v=>v.charCodeAt().toString(16)).join('')\n  }\n}\n"
  },
  {
    "path": "Ackermann Function.js",
    "content": "/*\nDescription:\nThe Ackermann function is a famous function that played a big role in computability theory as the first exemple of a total computable function that is not primitive recursive.\n\nSince then the function has been a bit simplified but is still of good use. Due to its definition in terms of extremely deep recursion it can be used as a benchmark of a compiler's ability to optimize recursion.\n\nThe goal of this kata is to code a function wich will be given two input, m and n, and will return the Ackermann number A(m,n) defined by:\n\nA(m,n) = n+1                          if m=0  \nA(m,n) = A(m-1,1)                     if m>0 , n=0\nA(m,n) = A(m-1,A(m,n-1))              if m,n > 0\nm,n should be non-negative integers, the function should return null (Javascript), None (Python), or nil (Ruby) for other type, non-integer and negative numbers. In C, input is restricted to integer type.\n*/\nAckermann=function(m,n) {\n    if (m<0||n<0){\n        return null\n    }\n    if (m == 0) {\n        return n + 1;\n    }\n    if (m>0&&n == 0) {\n        return Ackermann(m - 1, 1)\n    }\n    if (m>0&&n>0){\n        return Ackermann(m-1,Ackermann(m,n-1))\n    }\n}\n"
  },
  {
    "path": "Adding Binary Numbers.js",
    "content": "/*\nDescription:\n##Task: You have to write a function add which takes two binary numbers as strings and returns their sum as a string.\n\n##Note:\n\nYou are not allowed to convert binary to decimal & vice versa.\nThe sum should contain No leading zeroes.\n##Examples:\n\nadd('111','10'); => '1001'\nadd('1101','101'); => '10010'\nadd('1101','10111') => '100100'\n*/\nfunction add(a,b){\n  a = a.split('').reverse();\n  b = b.split('').reverse();\n  var result = '', temp = 0;\n  while (a.length || b.length || temp) {\n    temp += (~~a.shift()) + (~~b.shift());\n    let mod = temp % 2;\n    result = mod + result;\n    temp = temp > 1;\n  }\n  return (+result) ? result.replace(/^0+/, '') : '0';\n};\n"
  },
  {
    "path": "Adding ordinal indicator suffixes to numbers.js",
    "content": "/*\nDescription:\nFinish the function numberToOrdinal, which should take a number and return it as a string with the correct ordinal indicator suffix (in English). That is:\n\nnumberToOrdinal(1) ==> '1st'\nnumberToOrdinal(2) ==> '2nd'\nnumberToOrdinal(3) ==> '3rd'\nnumberToOrdinal(4) ==> '4th'\n... and so on\nFor the purposes of this kata, you may assume that the function will always be passed a non-negative integer. If the function is given 0 as an argument, it should return '0' (as a string).\n\nTo help you get started, here is an excerpt from Wikipedia's page on Ordinal Indicators:\n\nst is used with numbers ending in 1 (e.g. 1st, pronounced first)\nnd is used with numbers ending in 2 (e.g. 92nd, pronounced ninety-second)\nrd is used with numbers ending in 3 (e.g. 33rd, pronounced thirty-third)\nAs an exception to the above rules, all the \"teen\" numbers ending with 11, 12 or 13 use -th (e.g. 11th, pronounced eleventh, 112th, pronounced one hundred [and] twelfth)\nth is used for all other numbers (e.g. 9th, pronounced ninth).\n*/\nfunction numberToOrdinal(n) {\n  var suffix = \"th\";\n  if (n == 0) suffix = \"\";\n  if (n % 10 == 1 && n % 100 != 11) suffix = \"st\";\n  if (n % 10 == 2 && n % 100 != 12) suffix = \"nd\";\n  if (n % 10 == 3 && n % 100 != 13) suffix = \"rd\";\n  return n + suffix;\n}\n"
  },
  {
    "path": "Adjacent pairs in a string.js",
    "content": "/*\nDescription:\nYou know how sometimes you write the the same word twice in a sentence, but then don't notice that it happened? For example, you've been distracted for a second. Did you notice that *\"the\"* is doubled in the first sentence of this description?\n\nAs as aS you can see, it's not easy to spot those errors, especially if words differ in case, like *\"as\"* at the beginning of the sentence.\n\nWrite a function countAdjacentPairs that counts the number of adjacent pairs in a string. It should be case-insenstive. A word in this kata is a sequence of non-whitespace characters enclosed by whitespace, so the string \"dog dog.\" contains the two words \"dog\" and \"dog.\", which differ. The occurence of two or more equal words next after each other count as one.\n\nExample:\n\ncountAdjacentPairs \"dog cat\"       == 0\ncountAdjacentPairs \"dog dog cat\"   == 1\ncountAdjacentPairs \"apple dog cat\" == 0\ncountAdjacentPairs \"pineapple apple dog cat\" == 0\ncountAdjacentPairs \"apple     apple dog cat\" == 1\ncountAdjacentPairs \"apple dog apple dog cat\" == 0\ncountAdjacentPairs \"dog dog dog dog dog dog\" == 1\ncountAdjacentPairs \"dog dog dog dog cat cat\" == 2\ncountAdjacentPairs \"cat cat dog dog cat cat\" == 3\n//returns 0\ncountAdjacentPairs('')\n\n// returns 1\ncountAdjacentPairs('cat dog dog')\n\n// returns 1 (The first pair has been matched, and will be ignored from then on).\ncountAdjacentPairs('dog dog dog')\n\n// returns 2\ncountAdjacentPairs('cat cat dog dog cat')\n*/\nfunction countAdjacentPairs(searchString) {\n  let obj={};\n  searchString.toLowerCase().split(' ').map(v=>obj[v]=obj[v]?obj[v]+1:1);\n  return Object.values(obj).filter(v=>v>1).length\n}\n"
  },
  {
    "path": "Almost Even.js",
    "content": "/*\nDescription:\nWe need the ability to divide an unknown integer into a given number of even parts — or at least as even as they can be. The sum of the parts should be the original value, but each part should be an integer, and they should be as close as possible.\n\nExample code:\n\nsplitInteger(20, 6)  //  returns [3, 3, 3, 3, 4, 4]\nComplete the function so that it returns an array of integer representing the parts. Ignoring the order of the parts, there is only one valid solution for each input to your function!\n\n(Also, there is no reason to test for edge cases: the input to your function will always be valid for this kata.)\n*/\nvar splitInteger = function(num, parts) {\n  let n =Math.floor(num/parts)\n  const arr  = [];\n  for (let i=0;i<parts;i++){\n    arr.push(n)\n  }\n  if (arr.reduce((a,b)=>a+b,0)===num) return arr\n  for (let i=0;i<parts;i++){\n    arr[i]++\n    if (arr.reduce((a,b)=>a+b,0)===num) return arr\n  }\n}\n"
  },
  {
    "path": "Alphabet war - airstrike - letters massacre.js",
    "content": "/*\nDescription:\nIntroduction\nThere is a war and nobody knows - the alphabet war!\nThere are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. The letters called airstrike to help them in war - dashes and dots are spreaded everywhere on the battlefield.\n\nTask\nWrite a function that accepts fight string consists of only small letters and * which means a bomb drop place. Return who wins the fight after bombs are exploded. When the left side wins return Left side wins!, when the right side wins return Right side wins!, in other case return Let's fight again!.\n\nThe left side letters and their power:\n\n w - 4\n p - 3 \n b - 2\n s - 1\nThe right side letters and their power:\n\n m - 4\n q - 3 \n d - 2\n z - 1\nThe other letters don't have power and are only victims.\nThe * bombs kills the adjacent letters ( i.e. aa*aa => a___a, **aa** => ______ );\n\nExample\nalphabetWar(\"s*zz\");           //=> Right side wins!\nalphabetWar(\"*zd*qm*wp*bs*\"); //=> Let's fight again!\nalphabetWar(\"zzzz*s*\");       //=> Right side wins!\nalphabetWar(\"www*www****z\");  //=> Left side wins!\n*/\n\nfunction alphabetWar(fight)\n{ let dict={'w':4,'p':3,'b':2,'s':1,'m':-4,'q':-3,'d':-2,'z':-1};\n  \n  const arr=[];\n  const arr1=fight.split('')\n  for (let i=0;i<fight.length;i++){\n  if(arr1[i-1]!=='*'&&arr1[i]!=='*'&&arr1[i+1]!=='*'){arr.push(arr1[i])}\n  }\n  let sum=arr.reduce((a,b)=>a+(dict[b]?dict[b]:0),0)\n  return sum<0?'Right side wins!':sum>0?'Left side wins!':'Let\\'s fight again!';\n}\n"
  },
  {
    "path": "Alphabetized.js",
    "content": "/*\nDescription:\nThe alphabetized kata\nRe-order the characters of a string, so that they are concatenated into a new string in \"case-insensitively-alphabetical-order-of-appearance\" order. Whitespace and punctuation shall simply be removed!\n\nThe input is restricted to contain no numerals and only words containing the english alphabet letters.\n\nExample:\n\nalphabetized(\"The Holy Bible\") // \"BbeehHilloTy\"\nInspired by Tauba Auerbach\n*/\nfunction alphabetized(s) {\n var ans=\"\";\n for (var i=97; i<123; ++i)\n   for (var j=0; j<s.length; j++)\n     if (s[j].toLowerCase().charCodeAt()==i)\n     ans+=s[j]\n return ans\n}\n"
  },
  {
    "path": "Alternating Loops.js",
    "content": "/*\nDescription:\nWrite\n\nfunction combine()\nthat combines arrays by alternatingly taking elements passed to it.\n\nE.g\n\ncombine(['a', 'b', 'c'], [1, 2, 3]) == ['a', 1, 'b', 2, 'c', 3]\ncombine(['a', 'b', 'c'], [1, 2, 3, 4, 5]) == ['a', 1, 'b', 2, 'c', 3, 4, 5]\ncombine(['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]) == ['a', 1, 6, 8, 'b', 2, 7, 'c', 3, 4, 5]\nArrays can have different lengths.\n*/\nfunction combine(...arr) {\n  let newArr=[]\n  let max=Math.max(...arr.map(v=>v.length))\n  for(let i=0;i<max;i++){\n    for (let j=0;j<arr.length;j++){\n      arr[j][i]?newArr.push(arr[j][i]):1\n      }\n  }\n   return newArr\n}\n"
  },
  {
    "path": "Anagram difference.js",
    "content": "/*\nDescription:\nGiven two words, how many letters do you have to remove from them to make them anagrams?\nExample\nFirst word : c od e w ar s (4 letters removed)\nSecond word : ha c k er r a nk (6 letters removed)\nResult : 10\nHints\nA word is an anagram of another word if they have the same letters (usually in a different order).\nDo not worry about case. All inputs will be lowercase.\nWhen you're done with this kata, check out its big brother/sister : https://www.codewars.com/kata/hardcore-anagram-difference\n*/\nfunction anagramDifference(str1,str2){\n    let count1 = Array(26).fill(0) \n    let count2 = Array(26).fill(0) \n    let i = 0\n    while (i < str1.length){\n        count1[str1[i].charCodeAt()-97] += 1\n        i += 1\n        }\n    i =0\n    while (i < str2.length){\n        count2[str2[i].charCodeAt()-97] += 1\n        i += 1\n        }\n   let result = 0\n    for (let i = 0; i<26;i++){\n        result += Math.abs(count1[i] - count2[i]) \n    }\n    return result \n}\n"
  },
  {
    "path": "Anything to integer.js",
    "content": "/*\nDescription:\nYour task is to program a function which converts any input to an integer.\n\nDo not perform rounding, the fractional part should simply be discarded.\n\nIf converting the input to an integer does not make sense (with an object, for instance), the function should return 0 (zero).\n\nAlso, Math.floor(), parseInt() and parseFloat() are disabled for your unconvenience.\n\nOnegaishimasu!\n*/\nfunction toInteger(n) {\n  if (isNaN(n)) return 0\n  n=Math.trunc(n)\n  if (!Number.isFinite(n)) return 0\n  return n  \n}\n"
  },
  {
    "path": "Arabian String.js",
    "content": "/*\nDescription:\nYou must create a method that can convert a string from any format into CamelCase. This must support symbols too.\n\nDon't presume the separators too much or you could be surprised.\n\nTests\ncamelize(\"example name\")   // => ExampleName\ncamelize(\"your-NaMe-here\") // => YourNameHere\ncamelize(\"testing ABC\")    // => TestingAbc\n*/\nfunction camelize(str){\n  return str.replace(/[^a-z0-9]/gi,' ').split` `.map(v=>v.slice(0,1).toUpperCase()+v.slice(1).toLowerCase()).join``\n}\n"
  },
  {
    "path": "Are they the \"same\"?",
    "content": "/*\nDescription:\nGiven two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two arrays have the \"same\" elements, with the same multiplicities. \"Same\" means, here, that the elements in b are the elements in a squared, regardless of the order.\n\nExamples\nValid arrays\na = [121, 144, 19, 161, 19, 144, 19, 11]  \nb = [121, 14641, 20736, 361, 25921, 361, 20736, 361]\ncomp(a, b) returns true because in b 121 is the square of 11, 14641 is the square of 121, 20736 the square of 144, 361 the square of 19, 25921 the square of 161, and so on. It gets obvious if we write b's elements in terms of squares:\n\na = [121, 144, 19, 161, 19, 144, 19, 11] \nb = [11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]\nInvalid arrays\nIf we change the first number to something else, comp may not return true anymore:\n\na = [121, 144, 19, 161, 19, 144, 19, 11]  \nb = [132, 14641, 20736, 361, 25921, 361, 20736, 361]\ncomp(a,b) returns false because in b 132 is not the square of any number of a.\n\na = [121, 144, 19, 161, 19, 144, 19, 11]  \nb = [121, 14641, 20736, 36100, 25921, 361, 20736, 361]\ncomp(a,b) returns false because in b 36100 is not the square of any number of a.\n\nRemarks\na or b might be [] (all languages except R, Shell). a or b might be nil or null or None or nothing (except in Haskell, Elixir, C++, Rust, R, Shell).\n\nIf a or b are nil (or null or None), the problem doesn't make sense so return false.\n\nIf a or b are empty the result is evident by itself.\n*/\n\nfunction comp(array1, array2){\n  array1=array1.map(v=>v*v)\nreturn array2?array1.reduce((a,b)=>a+b,0)===array2.reduce((a,b)=>a+b,0):false\n}\n"
  },
  {
    "path": "Are we alternate?.js",
    "content": "/*\nDescription:\nCreate a function isAlt() that accepts a string as an argument and validates whether the vowels (a, e, i, o, u) and consonants are in alternate order.\n\nisAlt(\"amazon\")\n// true\nisAlt(\"apple\")\n// false\nisAlt(\"banana\")\n// true\nArguments consist of only lowercase letters.\n*/\nfunction isAlt(word) {\n \n  return word.split('').every((v,i)=>{\n  if (/[aeiou]/.test(word[0])){\n    if (i%2===0&&/[aeiou]/.test(v)){\n      return true\n      } else if (i%2!==0&&!/[aeiou]/.test(v)){ return true\n      } else {return false}\n    }\n  if (!/[aeiou]/.test(word[0])){\n    if (i%2==0&&!/[aeiou]/.test(v)){\n      return true\n      } else if (i%2!==0&&/[aeiou]/.test(v)){ return true\n      } else {return false}\n    }\n  })\n}\n"
  },
  {
    "path": "Array Deep Count.js",
    "content": "/*\nDescription:\nArray.prototype.length will give you the number of top-level elements in an array.\n\nYour task is to create a function deepCount that returns the number of ALL elements within an array, including any within inner-level arrays.\n\nFor example:\n\ndeepCount([1, 2, 3]);  \n//>>>>> 3\ndeepCount([\"x\", \"y\", [\"z\"]]);  \n//>>>>> 4\ndeepCount([1, 2, [3, 4, [5]]]);  \n//>>>>> 7\nThe input will always be an array.\n*/\nfunction deepCount(a){\n  return a.reduce((s,e)=>s+(Array.isArray(e)?deepCount(e):0),a.length);\n}\n"
  },
  {
    "path": "Array Helpers.js",
    "content": "/*\nDescription:\nThis kata is designed to test your ability to extend the functionality of built-in classes. In this case, we want you to extend the built-in Array class with the following methods: square(), cube(), average(), sum(), even() and odd().\n\nExplanation:\n\nsquare() must return a copy of the array, containing all values squared\ncube() must return a copy of the array, containing all values cubed\naverage() must return the average of all array values; on an empty array must return NaN (note: the empty array is not tested in Ruby!)\nsum() must return the sum of all array values\neven() must return an array of all even numbers\nodd() must return an array of all odd numbers\nNote: the original array must not be changed in any case!\n\nExample\nvar numbers = [1, 2, 3, 4, 5];\n\nnumbers.square();  // must return [1, 4, 9, 16, 25]\nnumbers.cube();    // must return [1, 8, 27, 64, 125]\nnumbers.average(); // must return 3\nnumbers.sum();     // must return 15\nnumbers.even();    // must return [2, 4]\nnumbers.odd();     // must return [1, 3, 5]\n*/\n\nArray.prototype.square=function(){\nreturn this.map(v=>v*v)\n}\nArray.prototype.cube=function(){\nreturn this.map(v=>v*v*v)\n}\nArray.prototype.sum=function(){\nreturn this.reduce((a,b)=>a+b,0)\n}\nArray.prototype.average=function(){\nreturn this.reduce((a,b)=>a+b,0)/this.length\n}\nArray.prototype.even=function(){\nreturn this.filter(v=>v%2==0)\n}\nArray.prototype.odd=function(){\nreturn this.filter(v=>v%2!==0)\n}\n"
  },
  {
    "path": "Array#reduce.js",
    "content": "/*\nDescription:\nIn this kata, you must define the Array.reduce method.\n\nI have disabled the pre-existing reduce methods.\n\nHere's how it works:\n\n[1,2,3].reduce( function(sum, next){return sum+next}, 0) \n// => 6\n\n['a','b','a'].reduce( function(obj, elem){if(!obj[elem]) obj[elem] = 0; obj[elem] += 1; return obj}, {})\n// => {'a':2, 'b':1}\nSummary: The reduce method goes through each element of an array, applies the function to whatever the function returned last, and returns the last outcome. On the first iteration, it should pass the initial value to the function, as well as the first element of the array. If no initial value is passed, skip to the first element of the array.\n\nRuby methods should expect a lambda.\n*/\nArray.prototype.reduce = function(process, initial) {\n  for (let i = 0; i < this.length; i++) {\n    if (!initial){i++;initial=this[0]}\n    initial =  process(initial, this[i]);\n }\n return initial\n}\n"
  },
  {
    "path": "Array.diff",
    "content": "/*\nDescription:\nYour goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.\n\nIt should remove all values from list a, which are present in list b.\n\narray_diff([1,2],[1]) == [2]\nIf a value is present in b, all of its occurrences must be removed from the other:\n\narray_diff([1,2,2,2,3],[2]) == [1,3]\n*/\n\nfunction array_diff(a, b) {\n  return a.filter(e => !b.includes(e));\n}\n"
  },
  {
    "path": "Arrays Similar.js",
    "content": "/*\nDescription:\nWrite a function that determines whether the passed in arrays are similar. Similar means they contain the same elements, and the same number of occurrences of elements.\n\nvar arr1 = [1, 2, 2, 3, 4],\n    arr2 = [2, 1, 2, 4, 3],\n    arr3 = [1, 2, 3, 4],\n    arr4 = [1, 2, 3, \"4\"]\n\narraysSimilar(arr1, arr2); // Should equal true\narraysSimilar(arr2, arr3); // Should equal false\narraysSimilar(arr3, arr4); // Should equal false\n*/\nfunction arraysSimilar(arr1, arr2) {\n  arr1=arr1.sort((a,b)=>a-b) \n  arr2=arr2.sort((a,b)=>a-b) \n  return arr1.length>arr2.length?arr1.every((v,i)=>v===arr2[i]):arr2.every((v,i)=>v===arr1[i])\n}\n"
  },
  {
    "path": "Arrh, grabscrab!.js",
    "content": "/*\nDescription:\nPirates have notorious difficulty with enunciating. They tend to blur all the letters together and scream at people.\n\nAt long last, we need a way to unscramble what these pirates are saying.\n\nWrite a function that will accept a jumble of letters as well as a dictionary, and output a list of words that the pirate might have meant.\n\nFor example:\n\ngrabscrab( \"ortsp\", [\"sport\", \"parrot\", \"ports\", \"matey\"] )\nShould return [\"sport\", \"ports\"].\n\nReturn matches in the same order as in the dictionary. Return an empty array if there are no matches.\n\nGood luck!\n*/\nfunction grabscrab(anagram, dictionary) {\n  anagram=anagram.split('').sort().join()\n  let arr = dictionary.slice().map(v=>v.split('').sort().join()===anagram)\n  return dictionary.filter((v,i)=>arr[i]===true)\n}\n"
  },
  {
    "path": "Atbash Cipher Helper.js",
    "content": "/*\nDescription:\nThe Atbash cipher is a simple substitution cipher originally known to be implemented using the Hebrew alphabet (אתבש, aleph-tav-beth-shin). The Atbash cipher is particularly well-known for its use in the Bible. It was in use as early as 500BC by scribes writing the Book of Jeremiah.\n\nIn the Atbash cipher, the first letter of the alphabet is substituted with the last letter, the second letter with the second to last letter, and so on.\n\nFor the Latin alphabet, this could be mapped as:\n\nA|B|C|D|E|F|G|H|I|J|K|L|M\nZ|Y|X|W|V|U|T|S|R|Q|P|O|N\nFor the Hebrew alphabet:\n\nא|ב|ג|ד|ה|ו|ז|ח|ט|י|כ\nת|ש|ר|ק|צ|פ|ע|ס|נ|מ|ל\nWhen viewing Hebrew text:\n\nThis is about viewing the text and should have no impact on your code. It may, however, help you with debugging text.\nI assume that your computer will display the characters properly.\nHebrew is written right-to-left, such that: \"א|ב\".charAt(0) == \"א\".\nThere are alternate forms of some letters in Hebrew (e.g. final forms) that aren't listed here. You won't need to worry about them for this Kata.\nYour solution should support any alphabet provided to the constructor, and should leave characters that are not in the specified alphabet in situ (e.g. uppercase letters should be left as-is if provided an alphabet of only lowercase letters).\n*/\nfunction AtbashCipher(abc) {\n  this.decode = this.encode = function(str) {\n    return str.replace(/./g, function(c) {\n      return abc[abc.length - 1 - abc.indexOf(c)] || c;\n    });\n  };\n}\n"
  },
  {
    "path": "Autocomplete! Yay!.js",
    "content": "/*\nDescription:\nIt's time to create an autocomplete function! Yay!\n\nThe autocomplete function will take in an input string and a dictionary array and return the values from the dictionary that start with the input string. If there are more than 5 matches, restrict your output to the first 5 results. If there are no matches, return an empty array.\n\nExample:\n\nautocomplete('ai', ['airplane','airport','apple','ball']) = ['airplane','airport']\nFor this kata, the dictionary will always be a valid array of strings. Please return all results in the order given in the dictionary, even if they're not always alphabetical. The search should NOT be case sensitive, but the case of the word should be preserved when it's returned.\n\nFor example, \"Apple\" and \"airport\" would both return for an input of 'a'. However, they should return as \"Apple\" and \"airport\" in their original cases.\n\nImportant note:\n\nAny input that is NOT a letter should be treated as if it is not there. For example, an input of \"$%^\" should be treated as \"\" and an input of \"ab*&1cd\" should be treated as \"abcd\".\n\n(Thanks to wthit56 for the suggestion!)\n*/\nfunction autocomplete(input, d){\n  input=input.replace(/[^a-zA-Z]/gi,'')\n  const arr=[];\n  for (let i=0;i<d.length;i++){\n    if (d[i].slice(0,input.length).toLowerCase()===input.toLowerCase()){ arr.push(d[i]) }\n  }\n  return arr.slice(0,5)\n}\n"
  },
  {
    "path": "Baby Magpies.js",
    "content": "/*\nMagpies are my favourite birds\nBaby ones even more so...\n\n\nIt is a little known fact^ that the black & white colours of baby magpies differ by at least one place and at most two places from the colours of the mother magpie.\n\nSo now you can work out if any two magpies may be related.\n\n...and Quardle oodle ardle wardle doodle the magpies said\n\nKata Task\nGiven the colours of two magpies, determine if one is a possible child or grand-child of the other.\n\nNotes\nEach pair of birds being compared will have same number of colour areas\nB = Black\nW = White\nExample\nGiven these three magpies\n\nMagpie 1  BWBWBW\nMagpie 2  BWBWBB\nMagpie 3  WWWWBB\nYou can see:\n\nMagpie 2 may be a child of Magpie 1 because there is only one difference\nMagpie 3 may be child of Magpie 2 because there are two differences\nSo Magpie 3 may be a grand-child of Magpie 1\nOn the other hand, Magpie 3 cannot be a child of Magpie 1 because there are three differences\nDM :-)\n\n^ This fact is little known because I just made it up\n*/\nvar child = function(bird1, bird2) {\n  if (bird1===bird2) return false\n  return ( getDifference(bird1, bird2) < 3 ? true : false );\n}\nvar grandchild = function(bird1, bird2) {\n  if (bird1.length===1&&bird2.length===1&&bird2!==bird1) return false\n  return ( getDifference(bird1, bird2) <=4 ? true : false );\n}\n\nfunction getDifference(bird1,bird2) {\n        let dif = 0;\n        for(let i=0; i<bird1.length; i++) {\n          if(bird1.slice(i,i+1)!==bird2.slice(i,i+1)) dif++;\n         }\n        return dif;\n}\n"
  },
  {
    "path": "Backspaces in string.js",
    "content": "/*\nDescription:\nAssume \"#\" is like a backspace in string. This means that string \"a#bc#d\" actually is \"bd\"\n\nYour task is to process a string with \"#\" symbols.\n\nExamples\n\"abc#d##c\"      ==>  \"ac\"\n\"abc##d######\"  ==>  \"\"\n\"#######\"       ==>  \"\"\n\"\"              ==>  \"\"\n*/\nfunction clean_string(s) {\n  s=s.split``\n\tfor (let i=0;i<s.length;i++){\n    if (s[i]==='#'){\n      s[i]=''\n      s[i-1]=''\n      s=s.filter(v=>v!=='')\n      i-=2\n    }\n  }\n  return s.join``\n};\n"
  },
  {
    "path": "Backwards Read Primes.js",
    "content": "/*\nDescription:\nBackwards Read Primes are primes that when read backwards in base 10 (from right to left) are a different prime. (This rules out primes which are palindromes.)\n\nExamples:\n13 17 31 37 71 73 are Backwards Read Primes\n13 is such because it's prime and read from right to left writes 31 which is prime too. Same for the others.\n\nTask\nFind all Backwards Read Primes between two positive given numbers (both inclusive), the second one always being greater than or equal to the first one. The resulting array or the resulting string will be ordered following the natural order of the prime numbers.\n\nExample\nbackwardsPrime(2, 100) => [13, 17, 31, 37, 71, 73, 79, 97] backwardsPrime(9900, 10000) => [9923, 9931, 9941, 9967] backwardsPrime(501, 599) => []\n\nbackwardsPrime(2, 100) => [13, 17, 31, 37, 71, 73, 79, 97] \nbackwardsPrime(9900, 10000) => [9923, 9931, 9941, 9967]\n*/\n\nfunction backwardsPrime(start, stop){\n    var arr = [];\n    for(var x = start; x <= stop; x++) {\n        if(isPrime(x)) {\n            if(arr.includes(x)) {\n                continue;\n            }\n            let temp = parseInt(x.toString().split('').reverse().join(''))\n            if (temp != x && isPrime(temp)) {\n                arr.push(x);\n                arr.push(temp);\n            }\n        }    \n    }\n    return arr.filter(a=> a >= start && a <= stop).sort((b,c)=>b-c);\n}\n\nfunction isPrime(n) {\n    if(n == 2 || n == 3) {\n        return true;\n    }\n    if(n % 2 == 0 || n % 3 == 0 || n < 2) {\n        return false;\n    }\n    var x = 5;\n    var N = Math.sqrt(n);\n    while (x <= N) {\n        if (n % x == 0) {\n            return false;\n        }\n        x++;\n    }\n    return true;\n}\n"
  },
  {
    "path": "Balance the arrays.js",
    "content": "/*\nDescription:\nCheck that the two provided arrays both contain the same number of different unique items, regardless of order. For example in the following:\n\n[a,a,a,a,b,b] and [c,c,c,d,c,d]\nBoth arrays have four of one item and two of another, so balance should return true.\n\n#Have fun!\n*/\nfunction balance (arr1, arr2){\n  if (arr1.length!==arr2.length) return false\n  let f = arr1.reduce((a,b)=>(a[b]=a[b]+1|0+1,a),{})\n  let s = arr2.reduce((a,b)=>(a[b]=a[b]+1|0+1,a),{})\n  return Object.values(f).sort().toString()===Object.values(s).sort().toString()\n}\n"
  },
  {
    "path": "Ball Upwards.js",
    "content": "/*\nYou throw a ball vertically upwards with an initial speed v (in km per hour). The height h of the ball at each time t is given by h = v*t - 0.5*g*t*t where g is Earth's gravity (g ~ 9.81 m/s**2). A device is recording at every tenth of second the height of the ball. For example with v = 15 km/h the device gets something of the following form: (0, 0.0), (1, 0.367...), (2, 0.637...), (3, 0.808...), (4, 0.881..) ... where the first number is the time in tenth of second and the second number the height in meter.\n\nTask\nWrite a function max_ball with parameter v (in km per hour) that returns the time in tenth of second of the maximum height recorded by the device.\n\nExamples:\nmax_ball(15) should return 4\n\nmax_ball(25) should return 7\n\nNotes\nRemember to convert the velocity from km/h to m/s or from m/s in km/h when necessary.\nThe maximum height recorded by the device is not necessarily the maximum height reached by the ball.\n*/\nfunction maxBall(v0) {\n  const v = v0 * 1000 * 10 / 3600;\n  return Math.round(v / 9.81); \n}\n"
  },
  {
    "path": "Banker's Plan.js",
    "content": "/*\nDescription:\nJohn has some amount of money of which he wants to deposit a part f0 to the bank at the beginning of year 1. He wants to withdraw each year for his living an amount c0.\n\nHere is his banker plan:\n\ndeposit f0 at beginning of year 1\nhis bank account has an interest rate of p percent per year, constant over the years\nJohn can withdraw each year c0, taking it whenever he wants in the year; he must take account of an inflation of i percent per year in order to keep his quality of living. i is supposed to stay constant over the years.\nall amounts f0..fn-1, c0..cn-1 are truncated by the bank to their integral part\nGiven f0, p, c0, i the banker guarantees that John will be able to go on that way until the nth year.\nExample:\nf0 = 100000, p = 1 percent, c0 = 2000, n = 15, i = 1 percent\nbeginning of year 2 -> f1 = 100000 + 0.01*100000 - 2000 = 99000;  c1 = c0 + c0*0.01 = 2020 (with inflation of previous year)\nbeginning of year 3 -> f2 =  99000 + 0.01*99000 - 2020  = 97970;  c2 = c1 + c1*0.01 = 2040.20 \n(with inflation of previous year, truncated to 2040)\nbeginning of year 4 -> f3 =  97970 + 0.01*97970 - 2040  = 96909.7 (truncated to 96909); \nc3 = c2 + c2*0.01 = 2060.4 (with inflation of previous year, truncated to 2060)\nand so on...\n\nJohn wants to know if the bankers'plan is right or wrong. Given parameters f0, p, c0, n, i build a function fortune which returns true if John can make a living until the nth year and false if it is not possible.\n\nSome cases:\nfortune(100000, 1, 2000, 15, 1) -> True\nfortune(100000, 1, 10000, 10, 1) -> True\nfortune(100000, 1, 9185, 12, 1) -> False\n\nFor the last case you can find below the amounts of his account at the beginning of each year:\n100000, 91815, 83457, 74923, 66211, 57318, 48241, 38977, 29523, 19877, 10035, -5\nf11 = -5 so he has no way to withdraw something for his living in year 12.\nNote: Don't forget to convert the percent parameters as percentages in the body of your function: if a parameter percent is 2 you have to convert it to 0.02.\n*/\nconst fortune = (f0, p, c0, n, i) => {\n    let c = c0;\n    let sum = f0;\n\n    for (let j = 1; j < n; j++) {\n        sum = Math.ceil(sum * (1 + p / 100) - c);\n        c = Math.ceil(c * (1 + i / 100))\n    }\n\n    return sum >= 0;\n};\n"
  },
  {
    "path": "Base Conversion.js",
    "content": "/*\nDescription:\nIn this kata you have to implement a base converter, which converts positive integers between arbitrary bases / alphabets. Here are some pre-defined alphabets:\n\nvar Alphabet = {\n  BINARY:        '01',\n  OCTAL:         '01234567',\n  DECIMAL:       '0123456789',\n  HEXA_DECIMAL:  '0123456789abcdef',\n  ALPHA_LOWER:   'abcdefghijklmnopqrstuvwxyz',\n  ALPHA_UPPER:   'ABCDEFGHIJKLMNOPQRSTUVWXYZ',\n  ALPHA:         'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',\n  ALPHA_NUMERIC: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'\n};\nThe function convert() should take an input (string), the source alphabet (string) and the target alphabet (string). You can assume that the input value always consists of characters from the source alphabet. You don't need to validate it.\n\nExamples\n// convert between numeral systems\nconvert(\"15\", Alphabet.DECIMAL, Alphabet.BINARY); // should return \"1111\"\nconvert(\"15\", Alphabet.DECIMAL, Alphabet.OCTAL); // should return \"17\"\nconvert(\"1010\", Alphabet.BINARY, Alphabet.DECIMAL); // should return \"10\"\nconvert(\"1010\", Alphabet.BINARY, Alphabet.HEXA_DECIMAL); // should return \"a\"\n\n// other bases\nconvert(\"0\", Alphabet.DECIMAL, Alphabet.ALPHA); // should return \"a\"\nconvert(\"27\", Alphabet.DECIMAL, Alphabet.ALPHA_LOWER); // should return \"bb\"\nconvert(\"hello\", Alphabet.ALPHA_LOWER, Alphabet.HEXA_DECIMAL); // should return \"320048\"\nconvert(\"SAME\", Alphabet.ALPHA_UPPER, Alphabet.ALPHA_UPPER); // should return \"SAME\"\nAdditional Notes:\n\nThe maximum input value can always be encoded in a number without loss of precision in JavaScript. In Haskell, intermediate results will probably be too large for Int.\nThe function must work for any arbitrary alphabets, not only the pre-defined ones\nYou don't have to consider negative numbers\n*/\n\nfunction convert(input, source, target) {\n  let s=0;  let str='';\n  for (let i=0; i<input.length; i++) {\n    s=s*source.length+source.indexOf(input[i]);\n  }\n  while (s>0) {\n    str=target[s%target.length]+str;\n    s=Math.floor(s/target.length);\n  }  \n  return str ? str : target[0];\n}\n"
  },
  {
    "path": "Basic Encryption.js",
    "content": "/*\nDescription:\nThe most basic encryption method is to map a char to another char by a certain math rule. Because every char has an ASCII value, we can manipulate this value with a simple math expression. For example 'a' + 1 would give us 'b', because 'a' value is 97 and 'b' value is 98.\n\nYou will need to write a method which does exactly that -\n\nget a string as text and an int as the rule of manipulation, and should return encrypted text. for example:\n\nencrypt(\"a\",1) = \"b\"\n\nFull ascii table is used on our question (256 chars) - so 0-255 are the valid values.\n\nGood luck.\n*/\nfunction encrypt(text, rule) {\n  return text.split('').map(v=>String.fromCharCode((v.charCodeAt()+rule)%256)).join(``)\n};\n"
  },
  {
    "path": "Binary string.js",
    "content": "/*\nDescription:\nGiven a positive (or 0) number, return a string of 1's and 0's representing it's binary value: toBinaryString(6) should return \"110\" (no leading 0).\n\nUse of the native method\nnumber.toString(2);\nis disallowed.\n*/\nfunction toBinaryString(num){\n   let out = \"\", bit = 1;\n    while( num >= bit ) {\n        out = ( num & bit ? 1 : 0 ) + out;\n        bit <<= 1;\n    }\n    return out || \"0\";\n}\n"
  },
  {
    "path": "Binary to Text (ASCII) Conversion.js",
    "content": "/*\nDescription:\nWrite a function that takes in a binary string and returns the equivalent decoded text (the text is ASCII encoded).\n\nEach 8 bits on the binary string represent 1 character on the ASCII table.\n\nThe input string will always be a valid binary string.\n\nCharacters can be in the range from \"00000000\" to \"11111111\" (inclusive)\n\nNote: In the case of an empty binary string your function should return an empty string.\n*/\nfunction binaryToString(binary) {\n  let arr=[];\n  for (let i=0;i<binary.length;i+=8){\n  arr.push(binary.slice(i,i+8))\n  }\n  return arr.map(v=>String.fromCharCode(parseInt(v,2))).join('')\n}\n"
  },
  {
    "path": "Binding within the List Monad.js",
    "content": "/*\nDescription:\nIn Haskell, Monads are simple containers, or even 'box-like' datastructures, of which lists are included, which can respond to certain functions, which are defined in the Monad typeclass. (To put it simply!)\n\nIn this kata, you must implement the Bind function for lists, or arrays. In haskell, the function is represented by >>=, but we'll just call it bind.\n\nEssentially, bind should map the array with the function given, and then flatten it one time. Don't manipulate the original array; make you function pure: without side-effects, so that no variables are edited whilst the function is carried out.\n\nHere's how it should work:\n\nbind( [1,2,3], function(a){ return [a+1] } )\n=> [2,3,4]\n\nbind( [1,2,3], function(a){ return [[a]] } )\n=> [[1],[2],[3]]\n\nbind( [1,2,3], function(a){ return a } )\n=> # ERROR! The returned value is not a list!\nAs per usual, the ruby function will be passed a Proc or Lambda. Remember that the function still takes two arguments!\n*/\nbind = function(list, func) {\n  if (typeof func(list[0]) !== \"object\") {throw Error()}\n  return list.reduce((a,b)=>a.concat(func(b)),[])\n}\n"
  },
  {
    "path": "Bingo Card.js",
    "content": "/*\nDescription:\nAfter yet another dispute on their game the Bingo Association decides to change course and automize the game.\n\nCan you help the association by writing a method to create a random Bingo card?\n\nTask:\n\nFinish method:\ngetCard()\nA Bingo card contains 24 unique and random numbers according to this scheme:\n5 numbers from the B column in the range 1 to 15\n5 numbers from the I column in the range 16 to 30\n4 numbers from the N column in the range 31 to 45\n5 numbers from the G column in the range 46 to 60\n5 numbers from the O column in the range 61 to 75\n\nThe card must be returned as an array of Bingo style numbers:\n{ 'B14', 'B12', 'B5', 'B6', 'B3', 'I28', 'I27', ... }\nThe numbers must be in the order of their column: B, I, N, G, O. Within the columns the order of the numbers is random.\n*/\nfunction getCard() {\n    let arr=[];\n    for (let i=0;i<5;i++){\n    let r=`B${getRandomIntInclusive(1,15)}`\n    if (!arr.includes(r)){\n     arr.push(r)} else {i--}\n    }\n    for (let i=0;i<5;i++){\n    let r=`I${getRandomIntInclusive(16,30)}`\n    if (!arr.includes(r)){\n     arr.push(r)} else {i--}\n    }\n    for (let i=0;i<5;i++){\n    let r=`N${getRandomIntInclusive(31,45)}`\n    if (i===2){}  \n    else if (!arr.includes(r)){\n    arr.push(r)} else {i--}\n    }\n    for (let i=0;i<5;i++){\n      let r=`G${getRandomIntInclusive(46,60)}`\n    if (!arr.includes(r)){\n     arr.push(r)} else {i--}\n    }\n    for (let i=0;i<5;i++){\n     let r=`O${getRandomIntInclusive(61,75)}`\n      if (!arr.includes(r)){\n     arr.push(r)} else {i--}\n    }\n    return arr\n}\nfunction getRandomIntInclusive(min, max) {\n  min = Math.ceil(min);\n  max = Math.floor(max);\n  return Math.floor(Math.random() * (max - min + 1)) + min;\n  }\n"
  },
  {
    "path": "Bit Counting",
    "content": "/*\nDescription:\nWrite a function that takes an integer as input, and returns the number of bits that are equal to one in the binary representation of that number. You can guarantee that input is non-negative.\n\nExample: The binary representation of 1234 is 10011010010, so the function should return 5 in this case\n*/\n\nvar countBits = function(n) {\n  return n.toString(2).replace(/0/g,'').length;\n};\n"
  },
  {
    "path": "Bleatrix Trotter (The Counting Sheep).js",
    "content": "/*\nDescription:\nBleatrix Trotter the sheep has devised a strategy that helps her fall asleep faster. First, she picks a number N. Then she starts naming N, 2 × N, 3 × N, and so on.\n\nWhenever she names a number, she thinks about all of the digits in that number. She keeps track of which digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) she has seen at least once so far as part of any number she has named. Once she has seen each of the ten digits at least once, she will fall asleep.\n\nBleatrix must start with N and must always name (i + 1) × N directly after i × N.\n\nFor example, suppose that Bleatrix picks N = 1692. She would count as follows:\n\nN = 1692. Now she has seen the digits 1, 2, 6, and 9.\n2N = 3384. Now she has seen the digits 1, 2, 3, 4, 6, 8, and 9.\n3N = 5076. Now she has seen all ten digits, and falls asleep.\nThe purpose of this kata is to return the last number Bleatrix Trotter sees before falling asleep.\n\nInput\nWill always be positive integer or zero\nOutput\nThe last number Bleatrix Trotter sees or \"INSOMNIA\" (-1 in Rust and C++) if she will count forever\nPlease note, this challenge is not my idea. It's from Google Code Jam 2016\n*/\nfunction trotter(n){\n  let check = n\n  let arr = n.toString().split``\n  for (let i=1;i<1000;i++){\n    n=check*i\n    arr=arr.concat(n.toString().split``)\n    arr=[...new Set(arr)]\n    if (arr.length===10) return n\n  }\n  return \"INSOMNIA\"\n}\n"
  },
  {
    "path": "Body mass index calculation.js",
    "content": "/*\nDescription:\nFor long period JavaScript warriors trained a lot in coding kata. But to find way warrior also need physical kata. Some of warriors forgot about this fact and enemies can use this weakness, your clan is under threat. You are chosen to fix this situation. Write a function to calculate Body mass index for each warrior.\n\nbmi = weght(kg)/(height(m)*height(m))\n\nWarriors know only their height in centimetres and weight (in kilogrames). Your task is to return an object with fields\n\nvalue - calculated Body mass index, rounded with one number after decimal point.\n\ncategory - from https://en.wikipedia.org/wiki/Body_mass_index\n\nEx :\n\ncalculateBmi(65,175)\nReturns :\n\n{value: \"21.2\", category: \"Normal (healthy weight)\"}\n*/\n\nfunction calculateBmi(weight, height) {\n  const bmi = (weight/((height/100)*(height/100))).toFixed(1)\n  let  z=''\n  const obj={};\n  if (bmi<15) z='Very severely underweight';\n  if (bmi<16&&bmi>15) z= 'Severely underweight';\n  if (bmi<18.5&&bmi>16) z= 'Underweight';\n  if (bmi<25&&bmi>18.5) z= \"Normal (healthy weight)\";\n  if (bmi<30&&bmi>25) z= 'Overweight';\n  if (bmi<35&&bmi>30) z= 'Obese Class I (Moderately obese)';\n  if (bmi<40&&bmi>35) z= 'Obese Class II (Severely obese)';\n  if (bmi<45&&bmi>40) z= 'Obese Class III (Very severely obese)';\n  if (bmi<50&&bmi>45) z= 'Obese Class IV (Morbidly Obese)';\n  if (bmi<60&&bmi>50) z= 'Obese Class V (Super Obese)';\n  if (bmi>60) z= 'Obese Class VI (Hyper Obese)';\n  obj.value=bmi\n  obj.category=z\nreturn obj\n}\n"
  },
  {
    "path": "Bouncing Balls",
    "content": "/*Description:\nA child is playing with a ball on the nth floor of a tall building. The height of this floor, h, is known.\n\nHe drops the ball out of the window. The ball bounces (for example), to two-thirds of its height (a bounce of 0.66).\n\nHis mother looks out of a window 1.5 meters from the ground.\n\nHow many times will the mother see the ball pass in front of her window (including when it's falling and bouncing?\n\nThree conditions must be met for a valid experiment:\nFloat parameter \"h\" in meters must be greater than 0\nFloat parameter \"bounce\" must be greater than 0 and less than 1\nFloat parameter \"window\" must be less than h.\nIf all three conditions above are fulfilled, return a positive integer, otherwise return -1.\n\nNote: The ball can only be seen if the height of the rebounding ball is stricty greater than the window parameter.\n\nExample:\n\nh = 3, bounce = 0.66, window = 1.5, result is 3\n\nh = 3, bounce = 1, window = 1.5, result is -1 (Condition 2) not fulfilled).\n*/\n\nfunction bouncingBall(h,  bounce,  window) {\n  var rebounds = -1;\n  if (bounce > 0 && bounce < 1) while (h > window) rebounds+=2, h *= bounce;\n  return rebounds;\n}\n"
  },
  {
    "path": "Bowling Pins.js",
    "content": "/*\nDescription:\nMount the Bowling Pins!\nTask:\nDid you ever play Bowling? Short: You have to throw a bowl into 10 Pins arranged like this:\n\n\nI I I I  # each Pin has a Number:    7 8 9 10\n I I I                                4 5 6\n  I I                                  2 3\n   I                                    1\n\nYou will get an Array with Numbers, e.g.: [3,5,9] and remove them from the field like this:\n\n\nI I   I\n I   I\n  I   \n   I   \n\nReturn a string with the current field.\n\nNote that:\nString.prototype.replace() is not allowed!\n\nYou begin a new line with \\n\nEach Line must be 7 chars long\nFill the missing pins with a whitespace\nHave fun!\n*/\nfunction bowlingPins(arr){\n  return \"7 8 9 10\\n 4 5 6 \\n  2 3  \\n   1   \".split`\\n`.map(\n  v=>v.split` `.map(v=>arr.includes(v*1)?' ':v===''?'':'I').join` `).join`\\n`\n}\n"
  },
  {
    "path": "Braces status.js",
    "content": "/*\nDescription:\nWrite a function that checks the braces status in a string, and return True if all braces are properly closed, or False otherwise. Available types of brackets: (), [], {}.\n\nPlease note, you need to write this function without using regex!\n\nExamples\n\"([[some](){text}here]...)\"  =>  true\n\"{([])}\"                     =>  true\n\"()[]{}()\"                   =>  true\n\"(...[]...{(..())}[abc]())\"  =>  true\n\"1239(df){\"                  =>  false\n\"[()])\"                      =>  false\n\")12[x]34(\"                  =>  false\nDon't forget to rate this kata! Thanks :)\n*/\nconst bracesStatus = s => {\n  s = s.replace(/[^\\(\\)\\[\\]\\{\\}]/g, '');\n  while (/\\(\\)|\\[\\]|\\{\\}/.test(s)) s = s.replace(/\\(\\)|\\[\\]|\\{\\}/g, '');\n  return s.length < 1;\n}\n"
  },
  {
    "path": "Bracket Duplicates.js",
    "content": "/*\nDescription:\nCreate a program that will take in a string as input and, if there are duplicates of more than two alphabetical characters in the string, returns the string with all the extra characters in a bracket.\n\nFor example, the input \"aaaabbcdefffffffg\" should return \"aa[aa]bbcdeff[fffff]g\"\n\nPlease also ensure that the input is a string, and return \"Please enter a valid string\" if it is not.\n*/\nfunction stringParse(string){\n  if (typeof string !== 'string') return \"Please enter a valid string\"\n  let arr = []\n  let str = ''\n  for (let i=0;i<string.length;i++){\n    if (string[i-1]===string[i]){\n      str+=string[i]\n    }else {\n      arr.push(str)\n      str=string[i]\n    }\n    if (i===string.length-1){arr.push(str)}\n  }\n  return arr.map(v=>v.length>2?v.slice(0,2)+'['+v.slice(2)+']':v).join``\n}\n"
  },
  {
    "path": "Braking well.js",
    "content": "/*\nDescription:\nBraking distance d1 is the distance a vehicle will go from the point when it brakes to when it comes to a complete stop. It depends on the original speed v and on the coefficient of friction mu between the tires and the road surface.\n\nThe braking distance is one of two principal components of the total stopping distance. The other component is the reaction distance, which is the product of the speed and the perception-reaction time of the driver.\n\nThe kinetic energy E is 0.5*m*v**2, the work W given by braking is mu*m*g*d1. Equalling E and W gives the braking distance: d1 = v*v / 2*mu*g where g is the gravity of Earth and m the vehicle's mass.\n\nWe have v in km per hour, g as 9.81 m/s/s and in the following we suppose that the reaction time is constant and equal to 1 s. The coefficient mu is dimensionless.\n\nThere are two tasks.\n\nThe first one is to calculate the total stopping distance in meters given v, mu (and the reaction time t = 1).\n\ndist(v, mu) -> d = total stopping distance\n\nThe second task is to calculate v in km per hour knowing d in meters and mu with the supposition that the reaction time is still t = 1.\n\nspeed(d, mu) -> v such that dist(v, mu) = d.\n\n#Examples:\n\ndist(100, 0.7) -> 83.9598760937531\n\nspeed(83.9598760937531, 0.7) -> 100.0\n\n#Notes:\n\nRemember to convert the velocity from km/h to m/s or from m/s in km/h when necessary.\nDon't forget the reaction time t: t = 1\nDon't truncate or round your results. See in \"RUN EXAMPLES\" the function assertFuzzyEquals.\nShell: only dist is tested.\n*/\nconst G = 9.81\nfunction dist(v, mu) {\t\t\t\t\t\t\t\t\n   let u = v*5/18;\n\t\treturn (u*u)/(2 * mu * G) + u;\t\n}\n\nfunction speed(d, mu) {\t\t\t\t\t\t\t\n      let b = -2 * mu * G;\n\t    return (3.6 * (b + Math.sqrt(b*b - 4*b*d) ) / 2);\n}\n"
  },
  {
    "path": "Break camelCase.js",
    "content": "/*\nComplete the solution so that the function will break up camel casing, using a space between words.\n\nExample\nsolution('camelCasing') // => should return 'camel Casing'\n*/\n\nfunction solution(string) {\n  return(string.replace(/([A-Z])/g, ' $1'));\n\n}\n"
  },
  {
    "path": "Breaking search bad.js",
    "content": "/*\nDescription:\nWe have a search function who return an array of titles that match the String passed as an argument.\n\nvar titles = ['Rocky 1', 'Rocky 2', 'My Little Poney'];\nsearch('ock')  // ==> should return ['Rocky 1', 'Rocky 2']\nBut the function return some weird result and skip some of the matching results.\n\nDoes the function have special movie taste ?\n\nLet's figure out !\n*/\nfunction search(searchTerm) {\n  return TITLES.filter(v=>new RegExp(searchTerm, 'i').test(v))\n} \n"
  },
  {
    "path": "Build Tower",
    "content": "/*\nDescription:\nBuild Tower\nBuild Tower by the following given argument:\nnumber of floors (integer and always greater than 0).\n\nTower block is represented as *\n\nPython: return a list;\nJavaScript: returns an Array;\nC#: returns a string[];\nPHP: returns an array;\nC++: returns a vector<string>;\nHaskell: returns a [String];\nRuby: returns an Array;\nHave fun!\n\nfor example, a tower of 3 floors looks like below\n\n[\n  '  *  ', \n  ' *** ', \n  '*****'\n]\nand a tower of 6 floors looks like below\n\n[\n  '     *     ', \n  '    ***    ', \n  '   *****   ', \n  '  *******  ', \n  ' ********* ', \n  '***********'\n]\nGo challenge Build Tower Advanced once you have finished this :)\n*/\n\n\nfunction towerBuilder(n) {\n  return [...Array(n)].map((_,i)=>\" \".repeat(n-1-i)+\"*\".repeat(i*2+1)+\" \".repeat(n-1-i))\n}\n"
  },
  {
    "path": "Build Tower Advanced.js",
    "content": "/*\nDescription:\nBuild Tower Advanced\nBuild Tower by the following given arguments:\nnumber of floors (integer and always greater than 0)\nblock size (width, height) (integer pair and always greater than (0, 0))\n\nTower block unit is represented as *\n\nPython: return a list;\nJavaScript: returns an Array;\nHave fun!\n\nfor example, a tower of 3 floors with block size = (2, 3) looks like below\n\n[\n  '    **    ',\n  '    **    ',\n  '    **    ',\n  '  ******  ',\n  '  ******  ',\n  '  ******  ',\n  '**********',\n  '**********',\n  '**********'\n]\nand a tower of 6 floors with block size = (2, 1) looks like below\n\n[\n  '          **          ', \n  '        ******        ', \n  '      **********      ', \n  '    **************    ', \n  '  ******************  ', \n  '**********************'\n]\nGo take a look at Build Tower which is a more basic version :)\n*/\nfunction towerBuilder(nFloors, nBlockSz) {\n  const tower = []\n  for (let i=0;i<nFloors;i++){\n    for (let j=0;j<nBlockSz[1];j++){\n      tower.push(' '.repeat((nFloors-i)*nBlockSz[0]-nBlockSz[0])+'*'.repeat(nBlockSz[0]+(i*(nBlockSz[0]*2)))+' '.repeat((nFloors-i)*nBlockSz[0]-nBlockSz[0]))\n    }\n  }\n  return tower\n}\n"
  },
  {
    "path": "Build a pile of Cubes",
    "content": "/*\nDescription:\nYour task is to construct a building which will be a pile of n cubes. The cube at the bottom will have a volume of n^3, the cube above will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3.\n\nYou are given the total volume m of the building. Being given m can you find the number n of cubes you will have to build?\n\nThe parameter of the function findNb (find_nb, find-nb, findNb) will be an integer m and you have to return the integer n such as n^3 + (n-1)^3 + ... + 1^3 = m if such a n exists or -1 if there is no such n.\n\nExamples:\nfindNb(1071225) --> 45\nfindNb(91716553919377) --> -1\nmov rdi, 1071225\ncall find_nb            ; rax <-- 45\n\nmov rdi, 91716553919377\ncall find_nb            ; rax <-- -1\n*/\n\n\nfunction findNb(m) {\nlet i=1;\nlet count=0;\nwhile (m>0){\n    m-=Math.pow(i,3)\n    i++\n    count++\n    }\n    \n    \n    return (m === 0) ? count : -1;\n}\n"
  },
  {
    "path": "Buying a car",
    "content": "/*\nDescription:\nLet us begin with an example:\n\nA man has a rather old car being worth $2000. He saw a secondhand car being worth $8000. He wants to keep his old car until he can buy the secondhand one.\n\nHe thinks he can save $1000 each month but the prices of his old car and of the new one decrease of 1.5 percent per month. Furthermore this percent of loss increases by 0.5 percent at the end of every two months. Our man finds it difficult to make all these calculations.\n\nCan you help him?\n\nHow many months will it take him to save up enough money to buy the car he wants, and how much money will he have left over?\n\nParameters and return of function:\n\nparameter (positive int, guaranteed) startPriceOld (Old car price)\nparameter (positive int, guaranteed) startPriceNew (New car price)\nparameter (positive int, guaranteed) savingperMonth \nparameter (positive float or int, guaranteed) percentLossByMonth\n\nnbMonths(2000, 8000, 1000, 1.5) should return [6, 766] or (6, 766)\nwhere 6 is the number of months at the end of which he can buy the new car and 766 is the nearest integer to 766.158 (rounding 766.158 gives 766).\n\nNote:\n\nSelling, buying and saving are normally done at end of month. Calculations are processed at the end of each considered month but if, by chance from the start, the value of the old car is bigger than the value of the new one or equal there is no saving to be made, no need to wait so he can at the beginning of the month buy the new car:\n\nnbMonths(12000, 8000, 1000, 1.5) should return [0, 4000]\nnbMonths(8000, 8000, 1000, 1.5) should return [0, 0]\nWe don't take care of a deposit of savings in a bank:-)\n*/\n\nfunction nbMonths(startPriceOld, startPriceNew, savingperMonth, percentLossByMonth){\n  if (startPriceOld>=startPriceNew) return [0,startPriceOld-startPriceNew] \n  var count=0;\n  var money=startPriceOld;\n  for (let i=1;money<=startPriceNew;i++){\n  if (i%2==0){percentLossByMonth+=0.5}\n    count++;\n    startPriceOld = startPriceOld - (startPriceOld*(percentLossByMonth/100));\n\t\tstartPriceNew = startPriceNew - ((startPriceNew*percentLossByMonth)/100);\n\t\tmoney = startPriceOld + (savingperMonth*count);\n    };\n   return [count,Math.round(money-startPriceNew)];\n  \n}\n"
  },
  {
    "path": "ByState.js",
    "content": "/*\nDescription:\nGiven a string with friends to visit in different states:\n\nad3=\"John Daggett, 341 King Road, Plymouth MA\nAlice Ford, 22 East Broadway, Richmond VA\nSal Carpenter, 73 6th Street, Boston MA\"\nwe want to produce a result that sorts the names by state and lists the name of the state followed by the name of each person residing in that state (people's names sorted). When the result is printed we get:\n\nMassachusetts\n.....^John Daggett 341 King Road Plymouth Massachusetts\n.....^Sal Carpenter 73 6th Street Boston Massachusetts\n^Virginia\n.....^Alice Ford 22 East Broadway Richmond Virginia\nSpaces not being always well seen, in the above result ^ means a white space.\n\nNot printed, the resulting string will be:\n\n\"Massachusetts\\n..... John Daggett 341 King Road Plymouth Massachusetts\\n..... Sal Carpenter 73 6th Street Boston Massachusetts\\n Virginia\\n..... Alice Ford 22 East Broadway Richmond Virginia\"\nNotes\nThere can be a blank last line in the given string of adresses.\nThe tests only contains CA, MA, OK, PA, VA, AZ, ID, IN for states.\nYou can see another example in the \"Sample tests\".\nStates\nFor the lazy ones:\n\n'AZ': 'Arizona',\n'CA': 'California',\n'ID': 'Idaho',\n'IN': 'Indiana',\n'MA': 'Massachusetts',\n'OK': 'Oklahoma',\n'PA': 'Pennsylvania',\n'VA': 'Virginia'\n*/\nfunction byState(str) {\n  let arr = str.replace(/,/g,\"\").split`\\n`;\n  let states = [[\"AZ\",\"Arizona\"],\n                [\"CA\",\"California\"],\n                [\"ID\",\"Idaho\"],\n                [\"IN\",\"Indiana\"],\n                [\"MA\",\"Massachusetts\"],\n                [\"OK\",\"Oklahoma\"],\n                [\"PA\",\"Pennsylvania\"],\n                [\"VA\",\"Virginia\"]];\n  let res = \"\";\n  states.forEach(([s,n]) => {\n    let temp = arr.filter(x => x.slice(-2) === s).sort();\n    if(temp.length){\n      res += \"\\r\\n \" + n + \"\\r\\n\";\n      res += temp.map(x => `..... ${x.slice(0,-3)} ${n}`).join`\\r\\n`;\n    }\n  });\n  return res.slice(3);\n}\n"
  },
  {
    "path": "Calculate Hypotenuse of Right-angled Triangle.js",
    "content": "/*\nDescription:\nTo solve this Kata, complete the function, calculateHypotenuse(a,b), which will return the length of the hyptenuse for a right angled triangle with the other two sides having a length equal to the inputs. More details:\n\nThe returned value should be a number rounded to three decimal places\nAn error (ArgumentException in C#) should be thrown if an invalid input is provided (inputs should both be numbers that are above zero)\ncalculateHypotenuse(1,1); // returns 1.414\ncalculateHypotenuse(3,4); // returns 5\ncalculateHypotenuse(-2,1); // throws error\ncalculateHypotenuse(\"one\", \"two\"); // throws error\nFor more information on the hypotenuse, visit: http://en.wikipedia.org/wiki/Hypotenuse\n*/\n\nfunction calculateHypotenuse(a,b){\n  if (typeof a !== 'number'||typeof b !== 'number') throw new Error('Not a Number')\n  if (isNaN(a)||isNaN(b)) throw new Error('Not a Number')\n  if (a<0||b<0) throw new Error('Less than 0')\n  return Math.hypot(a,b).toFixed(3)\n}\n"
  },
  {
    "path": "Calculate String Rotation.js",
    "content": "/*\nDescription:\nWrite a function that receives two strings and returns n, where n is equal to the number of characters we should shift the first string forward to match the second.\n\nFor instance, take the strings \"fatigue\" and \"tiguefa\". In this case, the first string has been rotated 5 characters forward to produce the second string, so 5 would be returned.\n\nIf the second string isn't a valid rotation of the first string, the method returns -1.\nExamples:\n``` \"coffee\", \"eecoff\" => 2 \"eecoff\", \"coffee\" => 4 \"moose\", \"Moose\" => -1 \"isn't\", \"'tisn\" => 2 \"Esham\", \"Esham\" => 0 \"dog\", \"god\" => -1 ```\nFor Swift, your function should return an Int?. So rather than returning -1 when the second string isn't a valid rotation of the first, return nil.\n\nshiftedDiff(\"coffee\", \"eecoff\") => 2\nshiftedDiff(\"eecoff\", \"coffee\") => 4\nshiftedDiff(\"moose\", \"Moose\") => nil\nshiftedDiff(\"isn't\", \"'tisn\") => 2\nshiftedDiff(\"Esham\", \"Esham\") => 0\nshiftedDiff(\"dog\", \"god\") => nil\n\n*/\nfunction shiftedDiff(first,second){\n  for (let i=0;i<first.length;i++){\n    if (first===second) return i;\n    first=rotLeft(first, first.length-1)\n  }\n  return -1\n}\nfunction rotLeft(arr, n) {\n     let arrTemp = arr.split(``)\n     for (let i = 0; i < n; i++) {\n         let temp = arrTemp.shift()\n        arrTemp.push(temp)\n     }\n    return arrTemp.join(``)\n}\n"
  },
  {
    "path": "Calculate number of inversions in array.js",
    "content": "/*\nDescription:\nArray inversion indicates how far the array is from being sorted.\n\nInversions are pairs of elements in array, that are out of order.\n\nExamples\ncountInversions([1,2,3,4]) // 0 inversions\n\ncountInversions([1,3,2,4]) // 1 inversion: 2 and 3\n\ncountInversions([4,1,2,3]) // 3 inversions: 4 and 1, 4 and 2, 4 and 3\n\ncountInversions([4,3,2,1]) // 6 inversions: 4 and 3, 4 and 2, 4 and 1, 3 and 2, 3 and 1, 2 and 1\nGoal\nThe goal is to come up with a function that can calculate inversions for any arbitrary array\n*/\nfunction countInversions( array ){\n  let sorted = array.slice().sort((a,b)=>a-b).join``\n  let count = 0;\n  for (let i=1;array.join``!==sorted;i++){\n    for (let j=0;j<array.length;j++){\n      if (array[j]<array[j-1]){\n      let temp = array[j]\n      array[j]=array[j-1]\n      array[j-1]=temp\n      count++\n      }\n    }\n  }\n  return count\n}\n"
  },
  {
    "path": "Calculate the area of a regular n sides polygon inside a circle of radius r.js",
    "content": "/*\nDescription:\nWrite the following function:\n\nfunction areaOfPolygonInsideCircle(circleRadius, numberOfSides)\nIt should calculate the area of a regular polygon of numberOfSides or number_of_sides sides inside a circle of radius circleRadius or circle_radius which passes through all the vertices of the polygon (such circle is called circumscribed circle or circumcircle). The answer should be a number rounded to 3 decimal places.\n\nInput :: Output Examples\n\nareaOfPolygonInsideCircle(3, 3) // returns 11.691\n\nareaOfPolygonInsideCircle(5.8, 7) // returns 92.053\n\nareaOfPolygonInsideCircle(4, 5) // returns 38.042\n*/\nfunction areaOfPolygonInsideCircle(r, s) {\n    let angle = Math.PI / s\n    let area = r * r * s * Math.sin(angle * 2) / 2\n    return +area.toFixed(3)\n}\n"
  },
  {
    "path": "Calculate the function f(x) for a simple linear sequence (Easy).js",
    "content": "/*\nFor any given linear sequence, calculate the function [f(x)] and return it as a string.\n\nFor example:\n\ngetFunction([0, 1, 2, 3, 4]) => \"f(x) = x\"\ngetFunction([0, 3, 6, 9, 12]) => \"f(x) = 3x\"\ngetFunction([1, 4, 7, 10, 13]) => \"f(x) = 3x + 1\"\nAssumptions for this kata are:\n\nthe sequence argument will always contain 5 values equal to f(0) - f(4).\nthe function will always be in the format \"nx +/- m\", 'x +/- m', 'nx', 'x' or 'm'\nif a non-linear sequence simply return 'Non-linear sequence' or Nothing in Haskell.\n*/\nfunction getFunction(seq) {\n  let add = seq[0], mul = seq[1]-add, linear=seq.every(function(v,i){return v==i*mul+add});\n  return linear ? \"f(x) = \"+ ( mul? (mul==1? '':mul==-1? \"-\":mul) +\"x\"+ (!add? \"\" : (add>0? \" + \":\" - \") +Math.abs(add)) : add ) : \"Non-linear sequence\"\n}\n"
  },
  {
    "path": "Calculate the function f(x) for a simple linear sequence (Medium).js",
    "content": "/*\nDescription:\nThis is a follow-up from my previous Kata which can be found here: http://www.codewars.com/kata/5476f4ca03810c0fc0000098\n\nThis time, for any given linear sequence, calculate the function [f(x)] and return it as a function in Javascript or Lambda/Block in Ruby.\n\nFor example:\n\ngetFunction([0, 1, 2, 3, 4])(5) => 5\ngetFunction([0, 3, 6, 9, 12])(10) => 30\ngetFunction([1, 4, 7, 10, 13])(20) => 61\nAssumptions for this kata are:\n\nThe sequence argument will always contain 5 values equal to f(0) - f(4).\nThe function will always be in the format \"nx +/- m\", 'x +/- m', 'nx', 'x' or 'm'\nIf a non-linear sequence simply return 'Non-linear sequence' for javascript, ruby, and python. For C#, throw an ArgumentException.\n*/\nfunction getFunction(sequence) {\n  const n = sequence[1]-sequence[0]\n  const check = sequence[1]-sequence[0]===sequence[2]-sequence[1]\n  if (!check) return'Non-linear sequence'\n  return (x)=>x*n+sequence[0]\n}\n"
  },
  {
    "path": "Cambridge Word Scramble.js",
    "content": "/*\nDescription:\nOne of the first chain emails I ever received was about a supposed Cambridge University study that suggests your brain can read words no matter what order the letters are in, as long as the first and last letters of each word are correct.\n\nYour task is to create a function that can take any string and randomly jumble the letters within each word while leaving the first and last letters of the word in place.\n\nFor example,\n\nmixwords('Winter is coming') // returns 'Wntier is cminog' or 'Wtiner is conimg'\nmixwords('Hey, friends!') // returns 'Hey, fierdns!' or 'Hey, fernids!'\nAll punctuation should remain in place\nWords smaller than 3 letters should not change\nLetters must be randomly moved (and so calling the function multiple times with the same string should return different values\nParameters that are not strings should return undefined\nThe tests do the following things to ensure a valid string is returned:\n\nCheck that the string returned is not equal to the string passed (you may have to revalidate the solution if your function randomly returns the same string)\nCheck that first and last letters of words remain in place\nCheck that punctuation remains in place\nChecks string length remains the same\nChecks the function returns undefined for non-strings\nChecks that word interiors (the letters between the first and last) maintain the same letters, albeit in a different order\nChecks that letters are randomly assigned.\n*/\nfunction mixwords(str){\n   if (typeof str ==='string'){\n     return str.replace(/[a-z]+/gi,v=>{\n     if (v.length>2) return v.slice(0,1)+v.slice(1,-1).split``.sort((a,b)=>Math.random()-0.5).join``+v.slice(-1)\n     return v\n     })\n   }\n};\n"
  },
  {
    "path": "CamelCase Method.js",
    "content": "/*\nDescription:\nWrite simple .camelCase method (camel_case function in PHP, CamelCase in C# or camelCase in Java) for strings. All words must have their first letter capitalized without spaces.\n\nFor instance:\n\n\"hello case\".camelCase() => HelloCase\n\"camel case word\".camelCase() => CamelCaseWord\nDon't forget to rate this kata! Thanks :)\n*/\n\nString.prototype.camelCase=function(){\n  let arg = this.toString().trim().split(' ');\n  let arr = arg.map((v,i,arr)=>v?v.slice(0,1).toUpperCase()+v.slice(1):v);\n  return arr.join('');\n}\n"
  },
  {
    "path": "CamelCase to underscore.js",
    "content": "/*\nDescription:\nYou wrote all your unit test names in camelCase. But some of your colleagues have troubles reading these long test names. So you make a compromise to switch to underscore separation.\n\nTo make these changes fast you wrote a class to translate a camelCase name into an underscore separated name.\n\nImplement the ToUnderscore() method.\n\nExample:\n\n\"ThisIsAUnitTest\" => \"This_Is_A_Unit_Test\"\n\nBut of course there are always special cases...\n\nYou also have some calculation tests. Make sure the results don't get splitted by underscores. So only add an underscore in front of the first number.\n\nAlso Some people already used underscore names in their tests. You don't want to change them. But if they are not splitted correct you should adjust them.\n\nSome of your colleagues mark their tests with a leading and trailing underscore. Don't remove this.\n\nAnd of course you should handle empty strings to avoid unnecessary errors. Just return an empty string then.\n\nExample:\n\n\"Calculate15Plus5Equals20\" => \"Calculate_15_Plus_5_Equals_20\"\n\n\"This_Is_Already_Splitted_Correct\" => \"This_Is_Already_Splitted_Correct\"\n\n\"ThisIs_Not_SplittedCorrect\" => \"This_Is_Not_Splitted_Correct\"\n\n\"_UnderscoreMarked_Test_Name_\" => _Underscore_Marked_Test_Name_\"\n*/\nconst toUnderScore = name => {\n  return name.replace(/([A-Z]|\\d+)/g,'_$1').replace(/^_/,'').replace(/__/g,'_')\n}\n"
  },
  {
    "path": "Can you keep a secret?.js",
    "content": "/*\nThere's no such thing as private properties on a coffeescript object! But, maybe there are?\n\nImplement a function createSecretHolder(secret) which accepts any value as secret and returns an object with ONLY two methods\n\ngetSecret() which returns the secret\nsetSecret() which sets the secret\nobj = createSecretHolder(5)\nobj.getSecret() # returns 5\nobj.setSecret(2)\nobj.getSecret() # returns 2\n*/\nfunction createSecretHolder(secret) {\n  return {\n  getSecret:function(){\n    return secret\n    },\n  setSecret:function(v){\n    secret=v}\n  }\n}\n"
  },
  {
    "path": "Case Reversal of Consecutive Duplicates.js",
    "content": "/*\nDescription:\nThe aim of this Kata is to write a function which will reverse the case of all consecutive duplicate letters in a string. That is, any letters that occur one after the other and are identical.\n\nIf the duplicate letters are lowercase then they must be set to uppercase, and if they are uppercase then they need to be changed to lowercase.\n\nExamples:\n\nreverseCase(\"puzzles\")    Expected Result: \"puZZles\"\nreverseCase(\"massive\")    Expected Result: \"maSSive\"\nreverseCase(\"LITTLE\")     Expected Result: \"LIttLE\"\nreverseCase(\"shhh\")       Expected Result: \"sHHH\"\nArguments passed will include only alphabetical letters A–Z or a–z.\n*/\nfunction reverseCase(string) {\n  return string.replace(/(\\w)(\\1)+/g,(v)=>v[0]===v[0].toLowerCase()?v.toUpperCase():v.toLowerCase())\n}\n"
  },
  {
    "path": "Cat Kata, Part 1.js",
    "content": "/*\nDescription:\nThe story you are about to hear is true\nOur cat, Balor, sadly died of cancer in 2015.\n\nWhile he was alive, the three neighborhood cats Lou, Mustache Cat, and Raoul all recognized our house and yard as Balor's territory, and would behave respectfully towards him and each other when they would visit.\n\nBut after Balor died, gradually each of these three neighborhood cats began trying to claim his territory as their own, trying to drive the others away by growling, yowling, snarling, chasing, and even fighting, when one came too close to another, and no human was right there to distract or extract one of them before the situation could escalate.\n\nIt is sad that these otherwise-affectionate animals, who had spent many afternoons peacefully sitting and/or lying near Balor and each other on our deck or around our yard, would turn on each other like that. However, sometimes, if they are far enough away from each other, especially on a warm day when all they really want to do is pick a spot in the sun and lie in it, they will ignore each other, and once again there will be a Peaceable Kingdom.\n\nYour Mission\nIn this, the first and simplest of a planned trilogy of cat katas :-), all you have to do is determine whether the distances between any visiting cats are large enough to make for a peaceful afternoon, or whether there is about to be an altercation someone will need to deal with by carrying one of them into the house or squirting them with water or what have you.\n\nAs input your function will receive a list of strings representing the yard as a grid, and an integer representing the minimum distance needed to prevent problems (considering the cats' current states of sleepiness). A point with no cat in it will be represented by a \"-\" dash. Lou, Mustache Cat, and Raoul will be represented by an upper case L, M, and R respectively. At any particular time all three cats may be in the yard, or maybe two, one, or even none.\n\nIf the number of cats in the yard is one or none, or if the distances between all cats are at least the minimum distance, your function should return True/true/TRUE (depending on what language you're using), but if there are two or three cats, and the distance between at least two of them is smaller than the minimum distance, your function should return False/false/FALSE.\n\nSome examples\n(The yard will be larger in the random test cases, but a smaller yard is easier to see and fit into the instructions here.)\n\nIn this first example, there is only one cat, so your function should return True.\n\n[\"------------\",\n \"------------\",\n \"-L----------\",\n \"------------\",\n \"------------\",\n \"------------\"], 10\nIn this second example, Mustache Cat is at the point yard[1][3] and Raoul is at the point yard[4][7] -- a distance of 5, so because the distance between these two points is smaller than the specified minimum distance of 6, there will be trouble, and your function should return False.\n\n[\"------------\",\n \"---M--------\",\n \"------------\",\n \"------------\",\n \"-------R----\",\n \"------------\"], 6\nIn this third example, Lou is at yard[0][11], Raoul is at yard[1][2], and Mustache Cat at yard[5][2]. The distance between Lou and Raoul is 9.05538513814, the distance between Raoul and Mustache Cat is 4, and the distance between Mustache Cat and Lou is 10.295630141 -- all greater than or equal to the specified minimum distance of 4, so the three cats will nap peacefully, and your function should return True.\n\n[\"-----------L\",\n \"--R---------\",\n \"------------\",\n \"------------\",\n \"------------\",\n \"--M---------\"], 4\nHave fun!\n*/\nfunction peacefulYard(yd, d) {\n  for(var pos=[],i=0;i<yd.length;i++)for(var j=0;j<yd[0].length;j++) if(yd[i][j]!=\"-\") pos.push([i,j])\n  return pos.every(x=>Math.min(...pos.map(y=>(Math.pow(x[0]-y[0],2)+Math.pow(x[1]-y[1],2))||d*d))>=d*d)\n}\n"
  },
  {
    "path": "Cat and Mouse - Harder Version.js",
    "content": "/*\nDescription:\nYou will be given a string (x) featuring a cat 'C', a dog 'D' and a mouse 'm'. The rest of the string will be made up of '.'.\n\nYou need to find out if the cat can catch the mouse from it's current position. The cat can jump (j) characters.\n\nAlso, the cat cannot jump over the dog.\n\nSo:\n\nif j = 5:\n\n..C.....m. returns 'Caught!' <-- not more than j characters between\n\n.....C............m...... returns 'Escaped!' <-- as there are more than j characters between the two, the cat can't jump far enough\n\nif j = 10:\n\n...m.........C...D returns 'Caught!' <--Cat can jump far enough and jump is not over dog\n\n...m....D....C....... returns 'Protected!' <-- Cat can jump far enough, but dog is in the way, protecting the mouse\n\nFinally, if all three animals are not present, return 'boring without all three'\n*/\nfunction catMouse(x, j){\n  if (!x.includes('D')||!x.includes('C')||!x.includes('m')) return \"boring without all three\"\n  if (Math.abs(x.indexOf('C')-x.indexOf('m'))>j) return \"Escaped!\"\n  if (x.replace(/\\./g,'')==='CDm'||x.replace(/\\./g,'')==='mDC') return 'Protected!'\n  return \"Caught!\"\n}\n"
  },
  {
    "path": "Catalog.js",
    "content": "/*\nDescription:\nYou are given a small extract of a catalog:\n\ns = \"<prod><name>drill</name><prx>99</prx><qty>5</qty></prod>\n\n<prod><name>hammer</name><prx>10</prx><qty>50</qty></prod>\n\n<prod><name>screwdriver</name><prx>5</prx><qty>51</qty></prod>\n\n<prod><name>table saw</name><prx>1099.99</prx><qty>5</qty></prod>\n\n<prod><name>saw</name><prx>9</prx><qty>10</qty></prod>\n\n...\n(prx stands for price, qty for quantity) and an article i.e \"saw\".\n\nThe function catalog(s, \"saw\") returns the line(s) corresponding to the article with $ before the prices:\n\n\"table saw > prx: $1099.99 qty: 5\\nsaw > prx: $9 qty: 10\\n...\"\nIf the article is not in the catalog return \"Nothing\".\n\nNotes\nThere is a blank line between two lines of the catalog.\nThe same article may appear more than once. If that happens return all the lines concerned by the article (in the same order as in the catalog).\nThe line separator of results may depend on the language \\nor \\r\\n. You can see examples in the \"Sample tests\".\n*/\nfunction catalog(s, article) {\n  return s.match(new RegExp(`name.+${article}.+\\/qty`,'g'))?s.match(new RegExp(`name.+${article}.+\\/qty`,'g'))\n  .map(v=>v.replace(/<\\/name><prx>/,' > prx: $'))\n  .map(v=>v.replace(/name>/,''))\n  .map(v=>v.replace(/<\\/prx><qty>/,' qty: '))\n  .map(v=>v.replace(/<\\/qty/,'')).join`\\r\\n`\n  :'Nothing'\n}\n"
  },
  {
    "path": "Chain Evaluation.js",
    "content": "/*\nDescription:\nMethod chaining is a very interesting way to keep your program clean.\n\nAs a part of this Kata, you need to create functions such that one could evaluate the following expression:\n\n(3).add(5).multiply(2)\nThe above expression evaluates to be 16.\n\nYou need to implement the following methods:\n\nadd\nsubtract\nmultiply\ndivide\nsquare\nAfter you're done, one could chain these five methods to create chains of almost any length.\n*/\nNumber.prototype.add=function(x){ return this+x};\nNumber.prototype.subtract=function(x){ return this-x;}\nNumber.prototype.multiply=function(x){ return this*x;}\nNumber.prototype.divide=function(x){ return this/x;}\nNumber.prototype.square=function(){ return this*this;}\n"
  },
  {
    "path": "Character frequency.js",
    "content": "/*\nDescription:\nWrite a function that takes a piece of text in the form of a string and returns the letter frequency count for the text. This count excludes numbers, spaces and all punctuation marks. Upper and lower case versions of a character are equivalent and the result should all be in lowercase.\n\nThe function should return a list of tuples (in Python) or arrays (in other languages) sorted by the most frequent letters first. The Rust implementation should return an ordered BTreeMap. Letters with the same frequency are ordered alphabetically. For example:\n\n  letterFrequency('aaAabb dddDD hhcc')\nwill return\n\n  [['d',5], ['a',4], ['b',2], ['c',2], ['h',2]]\nLetter frequency analysis is often used to analyse simple substitution cipher texts like those created by the Caesar cipher.\n*/\nfunction letterFrequency(text){\n  let str=text.toLowerCase().replace(/[^a-z]\\s*/gi,'').split(``).sort();\n  if (str.length===0) return []\n  let arr=[];\n  let obj={};\n  str.map(v=>obj[v]=obj[v]?obj[v]+1:1)\n  obj=JSON.stringify(obj).slice(1,-1).replace(/\"/g,'').split(',')\n  .map(v=>arr.push([v.split(':')[0],v.split(':')[1]*1]))\n  return arr.sort((a,b)=>b[1]-a[1]||a[0].localeCompare(b[0]))\n}\n"
  },
  {
    "path": "Character limits: How long is your piece of string?.js",
    "content": "/*\nDescription:\nCara is applying for several different jobs. The online application forms ask her to respond within a specific character count. Cara needs to check that her answers fit into the character limit.\n\nAnnoyingly, some application forms count spaces as a character, and some don't.\n\nYour challenge:\n\nWrite Cara a function charCheck() with the arguments:\n\n\"text\": a string containing Cara's answer for the question\n\"max\": a number equal to the maximum number of characters allowed in the answer\n\"spaces\": a boolean which is True if spaces are included in the character count and False if they are not\nThe function charCheck() should return an array: [True, \"Answer\"] , where \"Answer\" is equal to the original text, if Cara's answer is short enough.\n\nIf her answer \"text\" is too long, return an array: [False, \"Answer\"]. The second element should be the original \"text\" string truncated to the length of the limit.\n\nWhen the \"spaces\" argument is False, you should remove the spaces from the \"Answer\".\n\nFor example:\n\ncharCheck(\"Cara Hertz\", 10, True) should return [ True, \"Cara Hertz\" ]\ncharCheck(\"Cara Hertz\", 9, False) should return [ True, \"CaraHertz\" ]\ncharCheck(\"Cara Hertz\", 5, True) should return [ False, \"Cara \" ]\ncharCheck(\"Cara Hertz\", 5, False) should return [ False, \"CaraH\" ]\n*/\nfunction charCheck(text, max, spaces){\n  if (!spaces){\n    text=text.replace(/\\s+/g,'')\n  }\n  return [text.length<=max,text.slice(0,max)]\n};\n"
  },
  {
    "path": "Character with longest consecutive repetition.js",
    "content": "/*\nDescription:\nFor a given string s find the character c with longest consecutive repetition and return a tuple (c, l) (in Haskell Just (Char, Int), in C# Tuple<char?, int>, in Shell a String of comma-separated values c,l, in JavaScript [c,l], in Ruby [c, l], in Groovy [c, l]) where l is the length of the repetition. If there are two or more characters with the same l return the first.\n\nFor empty string return ('', 0) (in Haskell Nothing, in C# Tuple<char, int>(null, 0), in Shell ,0, in JavaScript [\"\",0], in Ruby [\"\", 0], in Groovy [\"\", 0]).\n\nHappy coding! :)\n*/\nfunction longestRepetition(s) {\n  let str='';\n  let count=1;\n  let arr = []\n  for (let i=0;i<s.length;i++){\n    if (s[i]===s[i+1]){\n      count++\n    } else {\n      if (arr.every(v=>v<count)){\n      str=s[i]+count\n      }\n      arr.push(count)\n      count=1\n    }\n  }\n  return !str?['',0]:[str.slice(0,1),str.slice(1)*1];\n}\n"
  },
  {
    "path": "Check if two words are isomorphic to each other.js",
    "content": "/*\nDescription:\nTwo strings a and b are called isomorphic if there is a one to one mapping possible for every character of a to every character of b. And all occurrences of every character in a map to same character in b.\n\nTask\nIn this kata you will create a function that return True if two given strings are isomorphic to each other, and False otherwise. Remember that order is important.\n\nYour solution must be able to handle words with more than 10 characters.\n\nExample\nTrue:\n\nCBAABC DEFFED\nXXX YYY\nRAMBUNCTIOUSLY THERMODYNAMICS\nFalse:\n\nAB CC\nXXY XYY\nABAB CD\n*/\nfunction isomorph(a, b) {\n  const dict = {};\n  const dict2 = {};\n  let f1 = true\n  let f2 = true\n  a.split``.map((v,i)=>{\n    if (!dict[v]){\n      dict[v]=b[i]\n    } else {\n      if (dict[v]!=b[i]) f1=false\n    }\n  })\n  b.split``.map((v,i)=>{\n    if (!dict2[v]){\n      dict2[v]=a[i]\n    } else {\n      if (dict2[v]!=a[i]) f2=false\n    }\n  })\n  return f1&&f2\n}\n"
  },
  {
    "path": "Checkerboard Generation.js",
    "content": "/*\nDescription:\nCheckerboard\nWrite a method checkerboard/Checkerboard which takes an integer size and returns a checkerboard of dimensions size x size. There are two colored squares on the checkerboard. Red squares are represented by the string [r] and black squares are represented by the string [b]. You MUST use the newline character \\n to insert a newline at the end of each row.\n\nThe top left corner should be a red square.\nEach row should have alternating squares in the row.\nThe starting square on each row should also alternate.\nAssumptions\nYou can assume you are given an integer size.\nYou cannot assume positive values.\nThus you should return an empty string for negative sizes and a size of 0. (An empty string does not have a newline ending).\nYou should assume the newline character used is \\n.\nYou MUST leave a newline character at the end of the full checkerboard thus allowing the board to be on its own if you were to run in a terminal.\nExamples\ncheckerboard(8);\n\"[r][b][r][b][r][b][r][b]\n[b][r][b][r][b][r][b][r]\n[r][b][r][b][r][b][r][b]\n[b][r][b][r][b][r][b][r]\n[r][b][r][b][r][b][r][b]\n[b][r][b][r][b][r][b][r]\n[r][b][r][b][r][b][r][b]\n[b][r][b][r][b][r][b][r]\"\nWhat We're Testing\nWe're testing loops and conditionals and aiming at beginners. There are many ways of achieving the solution so the correct solution will present a fairly basic version that should be more advanced than typical loop examples and has some extra challenge to the problem with the alternating on columns and rows.\n*/\nfunction checkerboard (size) {\n    \"use strict\";\n    if (size<=0) return '';\n    let str='';\n    for (let i=0;i<size;i++){\n    if (i%2==0) str+='[r]'\n    else str+='[b]'\n    }\n    let str1=''\n    for (let i=0;i<size;i++){\n    if (i%2==0) str1+='[b]'\n    else str1+='[r]'\n    }\n    let answ=''\n    for (let i=0;i<size;i++){\n    if (i%2==0) answ+=str+'\\n'\n    else answ+=str1+'\\n'\n    }\n    return answ\n};\n"
  },
  {
    "path": "Checkered Board.js",
    "content": "/*\nDescription:\nWrite a function which takes one parameter representing the dimensions of a checkered board. The board will always be square, so 5 means you will need a 5x5 board.\n\nThe dark squares will be represented by a unicode white square, while the light squares will be represented by a unicode black square (the opposite colours ensure the board doesn't look reversed on code wars' dark background). It should return a string of the board with a space in between each square and taking into account new lines.\n\nAn even number should return a board that begins with a dark square. An odd number should return a board that begins with a light square.\n\nThe input is expected to be a whole number that's at least two, and returns false otherwise (Nothing in Haskell).\n\nExamples:\n\ncheckeredBoard(5)\nreturns the string\n\n■ □ ■ □ ■\n□ ■ □ ■ □\n■ □ ■ □ ■\n□ ■ □ ■ □\n■ □ ■ □ ■\nThere should be no trailing white space at the end of each line, or new line characters at the end of the string.\n\nNote\nDo not use HTML entities for the squares (e.g. □ for white square) as the code doesn't consider it a valid square. A good way to check is if your solution prints a correct checker board on your local terminal.\n\nRuby note: CodeWars has encoding issues with rendered unicode in Ruby. You'll need to use unicode source code (e.g. \"\\u25A0\") instead of rendered unicode (e.g \"■\").\n*/\nfunction checkeredBoard(dimension) {\n  if (dimension!==parseInt(dimension)||dimension<2) return false\n  let light=true\n  let arr=[]\n  if (dimension%2===0){light=false}\n  for (let i=0;i<dimension;i++){\n      let temp=''\n      for (let j=0;j<dimension;j++){\n        if (!light){\n          if (j%2==0){\n            temp+='□ '\n          }else {\n            temp+='■ '\n          }\n        }else {\n          if (j%2!=0){\n            temp+='□ '\n          }else {\n            temp+='■ '\n          }\n        }\n    }\n      temp=temp.trim()\n      arr.push(temp)\n      light=!light\n  }\n  return arr.join`\\n`\n}\n"
  },
  {
    "path": "Checking Groups",
    "content": "/*\nDescription:\nIn English and programming, groups can be made using symbols such as () and {} that change meaning. However, these groups must be closed in the correct order to maintain correct syntax.\n\nYour job in this kata will be to make a program that checks a string for correct grouping. For instance, the following groups are done correctly:\n\n({})\n[[]()]\n[{()}]\nThe next are done incorrectly:\n\n{(})\n([]\n[])\nA correct string cannot close groups in the wrong order, open a group but fail to close it, or close a group before it is opened.\n\nYour function will take an input string that may contain any of the symbols (), {} or [] to create groups.\n\nIt should return True if the string is empty or otherwise grouped correctly, or False if it is grouped incorrectly.\n*/\n\nfunction groupCheck(braces){\n   while(/\\(\\)|\\[\\]|\\{\\}/g.test(braces)){braces = braces.replace(/\\(\\)|\\[\\]|\\{\\}/g,\"\")}\n return !braces.length;\n }\n"
  },
  {
    "path": "Chess Fun #1: Chess Board Cell Color.js",
    "content": "/*\nDescription:\nTask\nGiven two cells on the standard chess board, determine whether they have the same color or not.\n\nExample\nFor cell1 = \"A1\" and cell2 = \"C3\", the output should be true.\n\n\n\nFor cell1 = \"A1\" and cell2 = \"H3\", the output should be false.\n\n\n\nInput/Output\n[input] string cell1\n\n[input] string cell2\n\n[output] a boolean value\n\ntrue if both cells have the same color, false otherwise.\n*/\nfunction chessBoardCellColor(cell1, cell2) {\n let obj={};\n \n for (let i=1;i<9;i++){\n   if (i%2===0){\n   obj[`A${i}`]=1\n   obj[`B${i}`]=0\n   obj[`C${i}`]=1\n   obj[`D${i}`]=0\n   obj[`E${i}`]=1\n   obj[`F${i}`]=0\n   obj[`G${i}`]=1\n   obj[`H${i}`]=0\n   } else {\n   obj[`A${i}`]=0\n   obj[`B${i}`]=1\n   obj[`C${i}`]=0\n   obj[`D${i}`]=1\n   obj[`E${i}`]=0\n   obj[`F${i}`]=1\n   obj[`G${i}`]=0\n   obj[`H${i}`]=1\n   }\n }\n return obj[`${cell1}`]===obj[`${cell2}`] \n}\n"
  },
  {
    "path": "Chess Fun #2: Bishop And Pawn.js",
    "content": "/*\nDescription:\nTask\nGiven the positions of a white bishop and a black pawn on the standard chess board, determine whether the bishop can capture the pawn in one move.\n\nThe bishop has no restrictions in distance for each move, but is limited to diagonal movement. Check out the example below to see how it can move:\n\n\n\nExample\nFor bishop = \"a1\" and pawn = \"c3\", the output should be true.\n\n\n\nFor bishop = \"h1\" and pawn = \"h3\", the output should be false.\n\n\n\nInput/Output\n[input] string bishop\n\nCoordinates of the white bishop in the chess notation.\n\n[input] string pawn\n\nCoordinates of the black pawn in the same notation.\n\n[output] a boolean value\n\ntrue if the bishop can capture the pawn, false otherwise.\n*/\nfunction bishopAndPawn(bishop, pawn) {\n  let desk = []\n  for (let i=0;i<8;i++){\n    let temp = []\n    for (let j=0;j<8;j++){\n      temp.push(0)\n    }\n    desk.push(temp)\n  }\n  let mapL = {a:0,b:1,c:2,d:3,e:4,f:5,g:6,h:7}\n  let mapN = {1:7,2:6,3:5,4:4,5:3,6:2,7:1,8:0}\n  let b = bishop.split``\n  let x = mapL[b[0]]\n  let y = mapN[b[1]]\n    for (let i=y,j=x;j>=0&&i>=0;j--,i--){\n      desk[i][j]=1\n    }\n    for (let i=y,j=x;j<8&&i<8;j++,i++){\n      desk[i][j]=1\n    }\n    for (let i=y,j=x;j<8&&i>=0;j++,i--){\n      desk[i][j]=1\n    }\n    for (let i=y,j=x;j>=0&&i<8;j--,i++){\n      desk[i][j]=1\n    }\n  let p = pawn.split``\n  let xP = mapL[p[0]]\n  let yP = mapN[p[1]]\n  return desk[yP][xP]===1\n}\n"
  },
  {
    "path": "Christmas Day.js",
    "content": "/*\nDescription:\nSometimes it's useful to know on which day of the week Christmas, the holly holiday, will occur.\nWrite a function which takes the date of Christmas, and outputs the day of the week it falls on. Just don't limit yourself to this year. \n\nExample:\n\nfindOutChristmasWeekday('2013 12 25') // returns 'Wednesday'\nOnly valid Christmas dates will be passed to the function.\n\nDate parameter could be a string or a Date object. If it's a string here are possible date parameter formats:\n\n'2013 12 25'\n'12 25 2013'\n'25 December 2013'\nNote: calendar used in the kata is Gregorian.\n*/\n\nfunction findOutChristmasWeekday(date) {\n  if (typeof date == \"string\") date = date.replace(/ /g, '-');\n  return ['Sun', 'Mon','Tues','Wednes','Thurs','Fri','Satur'][new Date(date).getDay()] + \"day\";\n}\n"
  },
  {
    "path": "Christmas tree.js",
    "content": "/*\nDescription:\nCreate a function christmasTree(height) that returns a christmas tree of the correct height\n\nchristmasTree(5) should return:\n\n    *    \n   ***   \n  *****  \n ******* \n*********\nHeight passed is always an integer between 0 and 100.\n\nUse \\n for newlines between each line.\n\nPad with spaces so each line is the same length. The last line having only stars, no spaces.\n*/\nfunction christmasTree(height) {\n  let str=[];\n  for (let i=1;i<=height;i++){\n  str.push(' '.repeat(height-i)+'*'.repeat((i - 1) * 2 + 1)+' '.repeat(height-i))\n  }\n  return str.join('\\n')\n}\n"
  },
  {
    "path": "Circularly Sorted Array.js",
    "content": "/*\nDescription:\nWrite a method, isCircleSorted(int[] A) (Java, JavaScript), or Array#circularly_sorted? (Ruby) that determines if A is circularly sorted. An Array is circularly sorted if the elements are sorted in ascending order, but displaced, or rotated, by any number of steps.\n\nFor Example:\n\n// True:\nisCircleSorted([2,3,4,5,0,1]);\nisCircleSorted([4,5,6,9,1]);\nisCircleSorted([10,11,6,7,9]);\nisCircleSorted([1,2,3,4,5]);\nisCircleSorted([5,7,43,987,-9,0]);\n\n\n// False:\nisCircleSorted([4,1,2,5]);\nisCircleSorted([8,7,6,5,4,3]);\nisCircleSorted([6,7,4,8]);\nisCircleSorted([7,6,5,4,3,2,1]);\n*/\nfunction isCircleSorted( arr ){\n    let cnt = 0;\n    for (let i = 0; i < arr.length; i++) {\n        if (arr[i] > arr[(i + 1) % arr.length]) {\n            cnt++;\n        }\n    }\n    return cnt === 1;\n}\n"
  },
  {
    "path": "Clay Pigeon Shooting.js",
    "content": "/*\nDescription:\nPete and his mate Phil are out in the countryside shooting clay pigeons with a shotgun - amazing fun.\n\nThey decide to have a competition. 3 rounds, 2 shots each. Winner is the one with the most hits.\n\nSome of the clays have something attached to create lots of smoke when hit, guarenteed by the packaging to generate 'real excitement!' (genuinely this happened). None of the explosive things actually worked, but for this kata lets say they did.\n\nFor each round you will receive the following format:\n\n[{P1:'XX', P2:'XO'}, true]\n\nThat is an array containing an object and a boolean. Pl represents Pete, P2 represents Phil. X represents a hit and O represents a miss. If the boolean is true, any hit is worth 2. If it is false, any hit is worth 1.\n\nFind out who won. If it's Pete, return 'Pete Wins!'. If it is Phil, return 'Phil Wins!'. If the scores are equal, return 'Draw!'.\n\nNote that as there are three rounds, the actual input (x) will look something like this:\n\n[[{P1:'XX', P2:'XO'}, true], [{P1:'OX', P2:'OO'}, false], [{P1:'XX', P2:'OX'}, true]]\n*/\nfunction shoot(x){\n  let pete=0\n  let phil=0\n  for (let i=0;i<x.length;i++){\n    x[i][0].P1.replace(/X/g,v=>x[i][1]?pete+=2:pete++)\n    x[i][0].P2.replace(/X/g,v=>x[i][1]?phil+=2:phil++)\n  }\n  return pete>phil?'Pete Wins!':pete<phil?'Phil Wins!':'Draw!'\n}\n"
  },
  {
    "path": "Clock in Mirror.js",
    "content": "/*\nDescription:\nPeter can see a clock in the mirror from the place he sits in the office. When he saw the clock shows 12:22\n\nalt text\n\nHe knows that the time is 11:38\n\nalt text\n\nin the same manner:\n\n05:25 --> 06:35\n\n01:50 --> 10:10\n\n11:58 --> 12:02\n\n12:01 --> 11:59\n\nPlease complete the function WhatIsTheTime(timeInMirror), where timeInMirror is the mirrored time (what Peter sees) as string.\n\nReturn the real time as a string.\n\nConsider hours to be between 1 <= hour < 13.\n\nSo there is no 00:20, instead it is 12:20.\n\nThere is no 13:20, instead it is 01:20.\n*/\nfunction WhatIsTheTime(timeInMirror){\n    let time = timeInMirror.split(':')\n    let time2 = 60 - (parseInt(time[1]))\n    let time1 = time2 == 60 ? 12 - parseInt(time[0]) : 12 - (parseInt(time[0]) +1 )\n    let hour = time1 == 0 ? '12' : time1 == -1 ? '11' : time1 > 9 ? time1 : '0' + time1\n    let minute = time2 < 10 ? '0' + time2 : time2 == 60 ? '00' : time2\n    return `${hour}:${minute}`\n}\n"
  },
  {
    "path": "Clocky Mc Clock-Face.js",
    "content": "/*\nDescription:\nStory\nDue to lack of maintenance the minute-hand has fallen off Town Hall clock face.\n\nAnd because the local council has lost most of our tax money to a Nigerian email scam there are no funds to fix the clock properly.\n\nInstead, they are asking for volunteer programmers to write some code that tell the time by only looking at the remaining hour-hand!\n\nWhat a bunch of cheapskates!\n\nCan you do it?\n\nKata\nGiven the angle (in degrees) of the hour-hand, return the time in HH:MM format. Round down to the nearest minute.\n\nExamples\n12:00 = 0 degrees\n03:00 = 90 degrees\n06:00 = 180 degrees\n09:00 = 270 degrees\n12:00 = 360 degrees\nNotes\n0 <= angle <= 360\n*/\nvar whatTimeIsIt = function(angle) {\n  let hour=Math.floor(angle/30)\n  if (hour===0) hour=12\n  let min=Math.floor(angle%30*2)\n  return `${('0'+String(hour)).slice(-2)}:${('0'+String(min)).slice(-2)}`;\n}\n"
  },
  {
    "path": "Closures and Scopes.js",
    "content": "/*\nDescription:\nWe want to create a function, which returns an array of functions, which return their index in the array. For better understanding, here an example:\n\nvar callbacks = createFunctions(5); // create an array, containing 5 functions\n\ncallbacks[0](); // must return 0\ncallbacks[3](); // must return 3\nWe already implemented that function, but when we actually run the code, the result doesn't look like what we expected. Can you spot, what's wrong with it? A test fixture is also available\n*/\nfunction createFunctions(n) {\n  var callbacks = [];\n\n  for (let i=0; i<n; i++) {\n    callbacks.push(function() {\n      return i;\n    });\n  }\n  \n  return callbacks;\n}\n"
  },
  {
    "path": "Coding Meetup #10 - Higher-Order Functions Series - Create usernames.js",
    "content": "/*\nDescription:\nGiven the following input array:\n\nvar list1 = [\n  { firstName: 'Emily', lastName: 'N.', country: 'Ireland', continent: 'Europe', age: 30, language: 'Ruby' },\n  { firstName: 'Nor', lastName: 'E.', country: 'Malaysia', continent: 'Asia', age: 20, language: 'Clojure' }\n];\nwrite a function that adds the username property to each object in the input array:\n\n[\n  { firstName: 'Emily', lastName: 'N.', country: 'Ireland', continent: 'Europe', age: 30, language: 'Ruby', \n    username: 'emilyn1990' },\n  { firstName: 'Nor', lastName: 'E.', country: 'Malaysia', continent: 'Asia', age: 20, language: 'Clojure', \n    username: 'nore2000' }\n]\nThe value of the username property is composed by concatenating:\n\nfirstName in lower-case;\nfirst letter of the lastName in lower-case; and\nthe birth year which for the purpose of this kata is calculated simply by subtracting age from the current year. Please make sure that your function delivers the correct birth year irrespective of when it will be executed, for example it should also work correctly for a meetup organised in 10-years-time. The example above assumes that the function is run in year 2020.\nNotes:\n\nThe input array will always be valid and formatted as in the example above.\nAge is represented by a number which can be any positive integer.\nLastname will always be one upper-cased letter followed by dot, e.g. 'N.'\nOrder of the objects in the array should be maintained but order of the properties in the individual objects does not matter.\n\n\n\n\nThis kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.\n*/\nfunction addUsername(list) {\n  return list.map(v=>{return{...v,username:(v.firstName.toLowerCase()+v.lastName.slice(0,1).toLowerCase()+(Date.prototype.getFullYear()-v.age).toString())}})\n}\n"
  },
  {
    "path": "Coding Meetup #13 - Higher-Order Functions Series - Is the meetup language-diverse?.js",
    "content": "/*\nDescription:\nYou will be given an array of objects representing data about developers who have signed up to attend the next web development meetup that you are organising. Three programming languages will be represented: Python, Ruby and JavaScript.\n\nYour task is to return either:\n\ntrue if the number of meetup participants representing any of the three programming languages is ** at most 2 times higher than the number of developers representing any of the remaining programming languages**; or\nfalse otherwise.\nFor example, given the following input array:\n\nvar list1 = [\n  { firstName: 'Daniel', lastName: 'J.', country: 'Aruba', continent: 'Americas', age: 42, language: 'Python' },\n  { firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 22, language: 'Ruby' },\n  { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 43, language: 'Ruby' },\n  { firstName: 'Hanna', lastName: 'L.', country: 'Hungary', continent: 'Europe', age: 95, language: 'JavaScript' },\n  { firstName: 'Jayden', lastName: 'P.', country: 'Jamaica', continent: 'Americas', age: 18, language: 'JavaScript' },\n  { firstName: 'Joao', lastName: 'D.', country: 'Portugal', continent: 'Europe', age: 25, language: 'JavaScript' }\n];\nyour function should return false as the number of JavaScript developers (3) is 3 times higher than the number of Python developers (1). It can't be more than 2 times higher to be regarded as language-diverse.\n\nNotes:\n\nThe strings representing all three programming languages will always be formatted in the same way (e.g. 'JavaScript' will always be formatted with upper-case 'J' and 'S'.\nThe input array will always be valid and formatted as in the example above.\nEach of the 3 programming languages will always be represented.\n\n\n\n\nThis kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.\n*/\nfunction isLanguageDiverse(list) {\n  const arr = list.map(v=>v.language)\n  const obj = {}\n  arr.map(v=>obj[v]=obj[v]?obj[v]+1:1)\n  const count = Object.values(obj).sort((a,b)=>b-a)\n  const max = count.splice(0,1)\n  return count.every(v=>v*2>=max)\n}\n"
  },
  {
    "path": "Coding Meetup #15 - Higher-Order Functions Series - Find the odd names.js",
    "content": "/*\nDescription:\nYou will be given an array of objects representing data about developers who have signed up to attend the next coding meetup that you are organising.\n\nGiven the following input array:\n\nvar list1 = [\n  { firstName: 'Aba', lastName: 'N.', country: 'Ghana', continent: 'Africa', age: 21, language: 'Python' },\n  { firstName: 'Abb', lastName: 'O.', country: 'Israel', continent: 'Asia', age: 39, language: 'Java' }\n];\nwrite a function that when executed as findOddNames(list1) returns only the developers where if you add the ASCII representation of all characters in their first names, the result will be an odd number:\n\n[\n  { firstName: 'Abb', lastName: 'O.', country: 'Israel', continent: 'Asia', age: 39, language: 'Java' }\n]\nExplanation of the above:\n\nSum of ASCII codes of letters in 'Aba' is: 65 + 98 + 97 = 260 which is an even number\nSum of ASCII codes of letters in 'Abb' is: 65 + 98 + 98 = 261 which is an odd number\nNotes:\n\nPreserve the order of the original list.\nReturn an empty array [] if there is no developer with an \"odd\" name.\nThe input array and first names will always be valid and formatted as in the example above.\n\n\n\n\nThis kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.\n*/\nfunction findOddNames(list) {\n  return list.filter(v=>v.firstName.split``.reduce((a,b)=>a+b.charCodeAt(),0)%2!==0)\n}\n"
  },
  {
    "path": "Coding Meetup #16 - Higher-Order Functions Series - Ask for missing details.js",
    "content": "/*\nDescription:\nYou will be given an array of objects representing data about developers who have signed up to attend the next coding meetup that you are organising.\n\nGiven the following input array:\n\nvar list1 = [\n  { firstName: null, lastName: 'I.', country: 'Argentina', continent: 'Americas', age: 35, language: 'Java' },\n  { firstName: 'Lukas', lastName: 'X.', country: 'Croatia', continent: 'Europe', age: 35, language: null },\n  { firstName: 'Madison', lastName: 'U.', country: 'United States', continent: 'Americas', age: 32, language: 'Ruby' } \n];\nwrite a function that\n\n1) adds the question property to each object in the input array where the developer has not provided the relevant details (marked with a null value). The value of the question property should be the following string:\n\nHi, could you please provide your <property name>.\n\n2) and returns only the developers with missing details:\n\n[\n  { firstName: null, lastName: 'I.', country: 'Argentina', continent: 'Americas', age: 35, language: 'Java', \n  question: 'Hi, could you please provide your firstName.' },\n  { firstName: 'Lukas', lastName: 'X.', country: 'Croatia', continent: 'Europe', age: 35, language: null, \n  question: 'Hi, could you please provide your language.' }\n]\nNotes:\n\nAt most only one of the values will be null.\nPreserve the order of the original list.\nReturn an empty array [] if there is no developer with missing details.\nThe input array will always be valid and formatted as in the example above.\n\n\n\n\nThis kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.\n*/\nfunction askForMissingDetails(list) {\n  let arr = [];\n  list.map(list=>{\n  for (let i in list){\n    if (list[i]===null){\n      list={...list,question:`Hi, could you please provide your ${i}.`}\n      arr.push(list)\n    }\n  }})\n  return arr \n}\n"
  },
  {
    "path": "Coding Meetup #7 - Higher-Order Functions Series - Find the most senior developer.js",
    "content": "/*\nDescription:\nYou will be given an array of objects representing data about developers who have signed up to attend the next coding meetup that you are organising.\n\nYour task is to return an array which includes the developer who is the oldest. In case of a tie, include all same-age senior developers listed in the same order as they appeared in the original input array.\n\nFor example, given the following input array:\n\nvar list1 = [\n  { firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language: 'PHP' },\n  { firstName: 'Odval', lastName: 'F.', country: 'Mongolia', continent: 'Asia', age: 38, language: 'Python' },\n  { firstName: 'Emilija', lastName: 'S.', country: 'Lithuania', continent: 'Europe', age: 19, language: 'Python' },\n  { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' },\n];\nyour function should return the following array:\n\n[\n  { firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language: 'PHP' },\n  { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' },\n]\nNotes:\n\nThe input array will always be valid and formatted as in the example above.\n\n\n\n\nThis kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.\n*/\nfunction findSenior(list) {\n  let max = Math.max(...list.map(v=>v.age))\n  return list.filter(v=>v.age===max)\n}\n"
  },
  {
    "path": "Coding Meetup #8 - Higher-Order Functions Series - Will all continents be represented?.js",
    "content": "/*\nDescription:\nYou will be given an array of objects (associative arrays in PHP) representing data about developers who have signed up to attend the next coding meetup that you are organising.\n\nYour task is to return:\n\ntrue if all of the following continents / geographic zones will be represented by at least one developer: 'Africa', 'Americas', 'Asia', 'Europe', 'Oceania'.\nfalse otherwise.\nFor example, given the following input array:\n\nvar list1 = [\n  { firstName: 'Fatima', lastName: 'A.', country: 'Algeria', continent: 'Africa', age: 25, language: 'JavaScript' },\n  { firstName: 'Agustín', lastName: 'M.', country: 'Chile', continent: 'Americas', age: 37, language: 'C' },\n  { firstName: 'Jing', lastName: 'X.', country: 'China', continent: 'Asia', age: 39, language: 'Ruby' },\n  { firstName: 'Laia', lastName: 'P.', country: 'Andorra', continent: 'Europe', age: 55, language: 'Ruby' },\n  { firstName: 'Oliver', lastName: 'Q.', country: 'Australia', continent: 'Oceania', age: 65, language: 'PHP' },\n];\nyour function should return true as there is at least one developer from the required 5 geographic zones.\n\nNotes:\n\nThe input array and continent names will always be valid and formatted as in the list above for example 'Africa' will always start with upper-case 'A'.\n\n\n\n\nThis kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.\n*/\nfunction allContinents(list) {\n  return ['Africa', 'Americas', 'Asia', 'Europe', 'Oceania'].every(x => list.some(y => x==y.continent));\n}\n"
  },
  {
    "path": "Coding Meetup #9 - Higher-Order Functions Series - Is the meetup age-diverse?.js",
    "content": "/*\nDescription:\nYou will be given an array of objects (associative arrays in PHP) representing data about developers who have signed up to attend the next coding meetup that you are organising.\n\nYour task is to return:\n\ntrue if developers from all of the following age groups have signed up: teens, twenties, thirties, forties, fifties, sixties, seventies, eighties, nineties, centenarian (at least 100 years young).\nfalse otherwise.\nFor example, given the following input array:\n\nvar list1 = [\n  { firstName: 'Harry', lastName: 'K.', country: 'Brazil', continent: 'Americas', age: 19, language: 'Python' },\n  { firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 29, language: 'JavaScript' },\n  { firstName: 'Jing', lastName: 'X.', country: 'China', continent: 'Asia', age: 39, language: 'Ruby' },\n  { firstName: 'Noa', lastName: 'A.', country: 'Israel', continent: 'Asia', age: 40, language: 'Ruby' },\n  { firstName: 'Andrei', lastName: 'E.', country: 'Romania', continent: 'Europe', age: 59, language: 'C' },\n  { firstName: 'Maria', lastName: 'S.', country: 'Peru', continent: 'Americas', age: 60, language: 'C' },\n  { firstName: 'Lukas', lastName: 'X.', country: 'Croatia', continent: 'Europe', age: 75, language: 'Python' },\n  { firstName: 'Chloe', lastName: 'K.', country: 'Guernsey', continent: 'Europe', age: 88, language: 'Ruby' },\n  { firstName: 'Viktoria', lastName: 'W.', country: 'Bulgaria', continent: 'Europe', age: 98, language: 'PHP' },\n  { firstName: 'Piotr', lastName: 'B.', country: 'Poland', continent: 'Europe', age: 128, language: 'JavaScript' }\n];\nyour function should return true as there is at least one developer from each age group.\n\nNotes:\n\nThe input array will always be valid and formatted as in the example above.\nAge is represented by a number which can be any positive integer up to 199.\n\n\n\n\nThis kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.\n*/\nfunction isAgeDiverse(list) {\n  const check = [0,0,0,0,0,0,0,0,0,0]\n  list.map(v=>{\n    const age=v.age;\n    age>9&&age<20?check[0]=1:0;\n    age>19&&age<30?check[1]=1:0;\n    age>29&&age<40?check[2]=1:0;\n    age>39&&age<50?check[3]=1:0;\n    age>49&&age<60?check[4]=1:0;\n    age>59&&age<70?check[5]=1:0;\n    age>69&&age<80?check[6]=1:0;\n    age>79&&age<90?check[7]=1:0;\n    age>89&&age<100?check[8]=1:0;\n    age>100?check[9]=1:0;\n  })\n  return check.every(v=>v===1)\n}\n"
  },
  {
    "path": "Collatz.js",
    "content": "/*\nDescription:\nPreface\nA collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 :\n\ncollatz sequence\n n = { n / 2 for even n ;\n      3n + 1 for odd n }\n=======\n\nA more detailed description of the collatz conjecture may be found on Wikipedia.\n\nThe Problem\nCreate a function collatz that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form:\n\n\"X0->X1->...->XN\"\n\nWhere Xi is each iteration of the sequence and N is the length of the sequence.\n\nSample Input\ncollatz(4); // should return \"4->2->1\"\ncollatz(3); // should return \"3->10->5->16->8->4->2->1\"\nDon't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.\n*/\nfunction collatz(n){\n  let num=[];\n  for (let i=n;;){\n    if (i===1){\n    num.push(i)\n    break\n    }\n    if (i%2===0) {\n    num.push(i)\n    i=i/2\n    } else {\n    num.push(i)\n    i=i*3+1\n    }\n  }\n  return num.join('->')\n}\n"
  },
  {
    "path": "Color Choice.js",
    "content": "/*\nDescription:\nYou know combinations: for example, if you take 5 cards from a 52 cards deck you have 2,598,960 different combinations.\n\nIn mathematics the number of x combinations you can take from a set of n elements is called the binomial coefficient of n and x, or more often n choose x. The formula to compute m = n choose x is: m = n! / (x! * (n - x)!) where ! is the factorial operator.\n\nYou are a renowned poster designer and painter. You are asked to provide 6 posters all having the same design each in 2 colors. Posters must all have a different color combination and you have the choice of 4 colors: red, blue, yellow, green. How many colors can you choose for each poster?\n\nThe answer is two since 4 choose 2 = 6. The combinations will be: {red, blue}, {red, yellow}, {red, green}, {blue, yellow}, {blue, green}, {yellow, green}.\n\nNow same question but you have 35 posters to provide and 7 colors available. How many colors for each poster? If you take combinations 7 choose 2 you will get 21 with the above formula. But 21 schemes aren't enough for 35 posters. If you take 7 choose 5 combinations you will get 21 too. Fortunately if you take 7 choose 3 or 7 choose 4 combinations you get 35 and so each poster will have a different combination of 3 colors or 5 colors. You will take 3 colors because it's less expensive.\n\nHence the problem is:\n\nknowing m (number of posters to design), knowing n (total number of available colors), let us search x (number of colors for each poster so that each poster has a unique combination of colors and the number of combinations is exactly the same as the number of posters).\n\nIn other words we must find x such as n choose x = m (1) for a given m and a given n; m >= 0 and n > 0. If many x are solutions give as result the smallest x. It can happen that when m is given at random there are no x satisfying equation (1) then return -1.\n\nExamples:\n\ncheckchoose(6, 4) --> 2\ncheckchoose(4, 4) --> 1\ncheckchoose(4, 2) --> -1\ncheckchoose(35, 7) --> 3\ncheckchoose(36, 7) --> -1\n\na = 47129212243960\ncheckchoose(a, 50) --> 20\ncheckchoose(a + 1, 50) --> -1\n*/\nfunction checkchoose(m, n) {\n  let x = 1;\n  for (let i = 1; i < n; i++) {\n    x = Math.round(x * (n + 1 - i) / i)\n    if (x == m) \n      return i;\n  }\n  return -1;\n}\n"
  },
  {
    "path": "Combinator Flip.js",
    "content": "/*\nDescription:\nCreate a combinator function named flip that takes a function as an argument and returns that function with it's arguments reversed.\n\nFor example:\n\nflip(print)(4,5) // returns \"5 -> 4\"\nfunction print(a,b) {\n  return a + \" -> \" + b;\n}\nThe idea is to reverse any number of arguments using a higher order function, without any concern for the function being passed into it.\n*/\nfunction flip(fn) {\n    return (...args)=>fn(...(args.reverse()))\n}\n"
  },
  {
    "path": "Compare Versions.js",
    "content": "/*\nDescription:\nKaran's company makes software that provides different features based on the version of operating system of the user.\n\nFor finding which version is more recent, Karan uses the following method:\n\nfunction compareVersions (version1, version2) {\n  return parseFloat(version1) >= parseFloat(version2);\n}\nWhile this function worked for OS versions 10.6, 10.7, 10.8 and 10.9, the Operating system company just released OS version 10.10.\n\nKaran's function fails for the new version:\n\ncompareVersions (\"10.9\", \"10.10\");       // returns true, while it should return false\nKaran now wants to spend some time to right a more robust version comparison function that works for any future version/sub-version updates.\n\nHelp Karan write this function. Here are a few sample cases:\n\ncompareVersions(\"11\", \"10\");                    // returns true\ncompareVersions(\"11\", \"11\");                    // returns true\ncompareVersions(\"10.4.6\", \"10.4\");              // returns true\ncompareVersions(\"10.4\", \"11\");                  // returns false\ncompareVersions(\"10.4\", \"10.10\");               // returns false\ncompareVersions(\"10.4.9\", \"10.5\");              // returns false\nIt can be assumed that version strings are non empty and only contain numeric literals and the character '.'\n*/\nfunction compareVersions (version1, version2) {\n    let arr1 = version1.split('.');\n    let arr2 = version2.split('.');\n\n    let maxLength = Math.max(arr1.length, arr2.length);\n\n    for (let i = 0; i < maxLength; i++) {\n        if (Number(arr1[i] || 0) < Number(arr2[i] || 0)) {\n            return false;\n        }\n    } return true;\n}\n"
  },
  {
    "path": "Compare powers.js",
    "content": "/*\nDescription:\nYou certainly can tell which is the larger number between 210 and 215.\n\nBut what about, say, 210 and 310? You know this one too.\n\nThings tend to get a bit more complicated with both different bases and exponents: which is larger between 39 and 56?\n\nWell, by now you have surely guessed that you have to build a function to compare powers, returning -1 if the first member is larger, 0 if they are equal, 1 otherwise; powers to compare will be provided in the [base, exponent] format:\n\ncomparePowers([2,10],[2,15])===1\ncomparePowers([2,10],[3,10])===1\ncomparePowers([2,10],[2,10])===0\ncomparePowers([3,9],[5,6])===-1\ncomparePowers([7,7],[5,8])===-1\nOnly positive integers will be tested, incluing bigger numbers - you are warned now, so be diligent try to implement an efficient solution not to drain too much on CW resources ;)!\n*/\nfunction comparePowers([a,b],[x,y]){\n  let f =Math.log10(a)*b;\n  let s =Math.log10(x)*y;\n  return f===s?0:f>s?-1:1\n}\n"
  },
  {
    "path": "Compare section numbers.js",
    "content": "/*\nDescription:\nSection numbers are strings of dot-separated integers. The highest level sections (chapters) are numbered 1, 2, 3, etc. Second level sections are numbered 1.1, 1.2, 1.3, 2.1, 2.2, 2.3, etc. Next level sections are numbered 1.1.1, 1.1.2, 1.1.2, 1.2.1, 1.2.2, erc. There is no bound on the number of sections a document may have, nor is there any bound on the number of levels.\n\nA section of a certain level may appear directly inside a section several levels higher without the levels between. For example, section 1.0.1 may appear directly under section 1, without there being any level 2 section. Section 1.1 comes after section 1.0.1. Sections with trailing \".0\" are considered to be the same as the section with the trailing \".0\" truncated. Thus, section 1.0 is the same as section 1, and section 1.2.0.0 is the same as section 1.2.\n\nWrite a function cmp(section1, section2) that returns -1, 0, or 1 depending on whether section1 is before, same as, or after section2 respectively.\n*/\nfunction cmp(section1,section2) {\n  const one = section1.split('.');\n  const two = section2.split('.');\n\n  for (let i = 0; i < Math.max(one.length, two.length); i++) {\n    const s1 = +one[i] || 0;\n    const s2 = +two[i] || 0;\n    if (s1 > s2) return 1;\n    else if (s2 > s1) return -1;\n  }\n  return 0;\n}\n"
  },
  {
    "path": "Complete Fibonacci Series.js",
    "content": "/*\nDescription:\nThe function 'fibonacci' should return an array of fibonacci numbers. The function takes a number as an argument to decide how many no. of elements to produce. If the argument is less than or equal to 0 then return empty array\n\nExample:\n\nfibonacci(4); // should return [0,1,1,2]\nfibonacci(-1); // should return []\n*/\nfunction fibonacci(n) {\n if (n<1) return [];\n if (n<2) return [0];\n let arr=[0,1];\n for (let i=2;i<n;i++){\n arr.push(arr[i-2]+arr[i-1])\n }\n return arr\n}\n"
  },
  {
    "path": "Complete The Pattern #12.js",
    "content": "/*\n###Task:\n\nYou have to write a function pattern which returns the following Pattern(See Examples) upto (2n-1) rows, where n is parameter.\n\nNote:Returning the pattern is not the same as Printing the pattern.\n####Parameters:\n\npattern(        n        );\n                ^                     \n                |                     \n         Term upto which   \n       Basic Pattern(this)     \n            should be         \n             created            \n####Rules/Note:\n\nIf n < 1 then it should return \"\" i.e. empty string.\nThe length of each line is same, and is equal to the length of longest line in the pattern i.e (2n-1).\nRange of Parameters (for the sake of CW Compiler) :\nn ∈ (-∞,100]\n###Examples:\n\npattern(5):\n\n  1       1\n   2     2 \n    3   3  \n     4 4   \n      5    \n     4 4   \n    3   3  \n   2     2 \n  1       1\npattern(10):\n\n  1                 1\n   2               2 \n    3             3  \n     4           4   \n      5         5    \n       6       6     \n        7     7      \n         8   8       \n          9 9        \n           0         \n          9 9        \n         8   8       \n        7     7      \n       6       6     \n      5         5    \n     4           4   \n    3             3  \n   2               2 \n  1                 1\npattern(15):\n\n  1                           1\n   2                         2 \n    3                       3  \n     4                     4   \n      5                   5    \n       6                 6     \n        7               7      \n         8             8       \n          9           9        \n           0         0         \n            1       1          \n             2     2           \n              3   3            \n               4 4             \n                5              \n               4 4             \n              3   3            \n             2     2           \n            1       1          \n           0         0         \n          9           9        \n         8             8       \n        7               7      \n       6                 6     \n      5                   5    \n     4                     4   \n    3                       3  \n   2                         2 \n  1                           1\n*/\nfunction pattern(n){\n var output=\"\";\n   let arr = [];\n   for (let i=1,j=(n-1)*2-1;i<=n;i++,j-=2){\n     if (i===n) output+=' '.repeat(i-1)+i%10+' '.repeat(i-1)+'\\n'\n     else output+=' '.repeat(i-1)+i%10+' '.repeat(j)+i%10+' '.repeat(i-1)+'\\n'\n   }\n return output+output.split`\\n`.slice(0,-2).reverse().join`\\n`;\n}\n"
  },
  {
    "path": "Complete The Pattern #16.js",
    "content": "/*\n###Task:\n\nYou have to write a function pattern which returns the following Pattern(See Examples) upto n number of rows.\n\nNote:Returning the pattern is not the same as Printing the pattern.\n####Rules/Note:\n\nThe pattern should be created using only unit digits.\nIf n < 1 then it should return \"\" i.e. empty string.\nThe length of each line is same, and is equal to the number of characters in a line i.e n.\nRange of Parameters (for the sake of CW Compiler) :\nn ∈ (-50,150]\n###Examples:\n\npattern(8):\n\n88888888\n87777777\n87666666\n87655555\n87654444\n87654333\n87654322\n87654321\npattern(17):\n\n77777777777777777\n76666666666666666\n76555555555555555\n76544444444444444\n76543333333333333\n76543222222222222\n76543211111111111\n76543210000000000\n76543210999999999\n76543210988888888\n76543210987777777\n76543210987666666\n76543210987655555\n76543210987654444\n76543210987654333\n76543210987654322\n76543210987654321\n*/\nfunction pattern(n){\n  if (n<=0) return ''\n  let s = n.toString().split``.reverse()[0]\n  let output=[`${s}`.repeat(n)];\n  for (let i=n,j=0;i>0;i--,j++){\n    if (s===-1){\n      s=9\n    }\n    output.push((output[j].slice(0,j)+`${s--}`.repeat(n-j)))\n  }\n  return output.slice(1).join`\\n`\n}\n"
  },
  {
    "path": "Complete The Pattern #8 - Number Pyramid.js",
    "content": "/*\nDescription:\n###Task:\n\nYou have to write a function pattern which creates the following Pattern(See Examples) upto n(parameter) number of rows.\n\n####Rules/Note:\n\nIf the Argument is 0 or a Negative Integer then it should return \"\" i.e. empty string.\nAll the lines in the pattern have same length i.e equal to the number of characters in the last line.\nRange of n is (-∞,100]\n###Examples:\n\npattern(5):\n\n    1    \n   121   \n  12321  \n 1234321 \n123454321\npattern(10):\n\n         1         \n        121        \n       12321       \n      1234321      \n     123454321     \n    12345654321    \n   1234567654321   \n  123456787654321  \n 12345678987654321 \n1234567890987654321\npattern(15):\n\n              1              \n             121             \n            12321            \n           1234321           \n          123454321          \n         12345654321         \n        1234567654321        \n       123456787654321       \n      12345678987654321      \n     1234567890987654321     \n    123456789010987654321    \n   12345678901210987654321   \n  1234567890123210987654321  \n 123456789012343210987654321 \n12345678901234543210987654321\npattern(20):\n\n                   1                   \n                  121                  \n                 12321                 \n                1234321                \n               123454321               \n              12345654321              \n             1234567654321             \n            123456787654321            \n           12345678987654321           \n          1234567890987654321          \n         123456789010987654321         \n        12345678901210987654321        \n       1234567890123210987654321       \n      123456789012343210987654321      \n     12345678901234543210987654321     \n    1234567890123456543210987654321    \n   123456789012345676543210987654321   \n  12345678901234567876543210987654321  \n 1234567890123456789876543210987654321 \n123456789012345678909876543210987654321\n*/\nfunction pattern(n){\n  return Array.from({length: n}, (_, i) => {\n    let arr = Array.from({length: i}, (v, j) => (j + 1) % 10);\n    return ' '.repeat(n - i - 1) + arr.join('') + (i + 1) % 10 + arr.reverse().join('') + ' '.repeat(n - i - 1);\n  }).join('\\n');\n}\n"
  },
  {
    "path": "Complete The Pattern #9 - Diamond.js",
    "content": "/*\nDescription:\nTask:\nYou have to write a function pattern which returns the following Pattern(See Examples) upto (2n-1) rows, where n is parameter.\n\nRules/Note:\nIf the Argument is 0 or a Negative Integer then it should return \"\" i.e. empty string.\nAll the lines in the pattern have same length i.e equal to the number of characters in the longest line.\nRange of n is (-∞,100]\nExamples:\npattern(5):\n\n    1    \n   121   \n  12321  \n 1234321 \n123454321\n 1234321 \n  12321  \n   121   \n    1    \npattern(10):\n\n         1         \n        121        \n       12321       \n      1234321      \n     123454321     \n    12345654321    \n   1234567654321   \n  123456787654321  \n 12345678987654321 \n1234567890987654321\n 12345678987654321 \n  123456787654321  \n   1234567654321   \n    12345654321    \n     123454321     \n      1234321      \n       12321       \n        121        \n         1         \npattern(15):\n\n              1              \n             121             \n            12321            \n           1234321           \n          123454321          \n         12345654321         \n        1234567654321        \n       123456787654321       \n      12345678987654321      \n     1234567890987654321     \n    123456789010987654321    \n   12345678901210987654321   \n  1234567890123210987654321  \n 123456789012343210987654321 \n12345678901234543210987654321\n 123456789012343210987654321 \n  1234567890123210987654321  \n   12345678901210987654321   \n    123456789010987654321    \n     1234567890987654321     \n      12345678987654321      \n       123456787654321       \n        1234567654321        \n         12345654321         \n          123454321          \n           1234321           \n            12321            \n             121             \n              1              \npattern(20):\n\n                   1                   \n                  121                  \n                 12321                 \n                1234321                \n               123454321               \n              12345654321              \n             1234567654321             \n            123456787654321            \n           12345678987654321           \n          1234567890987654321          \n         123456789010987654321         \n        12345678901210987654321        \n       1234567890123210987654321       \n      123456789012343210987654321      \n     12345678901234543210987654321     \n    1234567890123456543210987654321    \n   123456789012345676543210987654321   \n  12345678901234567876543210987654321  \n 1234567890123456789876543210987654321 \n123456789012345678909876543210987654321\n 1234567890123456789876543210987654321 \n  12345678901234567876543210987654321  \n   123456789012345676543210987654321   \n    1234567890123456543210987654321    \n     12345678901234543210987654321     \n      123456789012343210987654321      \n       1234567890123210987654321       \n        12345678901210987654321        \n         123456789010987654321         \n          1234567890987654321          \n           12345678987654321           \n            123456787654321            \n             1234567654321             \n              12345654321              \n               123454321               \n                1234321                \n                 12321                 \n                  121                  \n                   1             \n*/\nfunction pattern(n){\n  if (n===1) return '1'\n  let output=\"\";\n  for (let i=1;i<=n;i++){\n    let arr = Array(i).fill(0).map((v,i)=>(i+1)%10).join``\n    let arr2 = arr.split``.reverse().join``.slice(1)\n    output+=' '.repeat(n-i)+arr+arr2+' '.repeat(n-i)+'\\n'\n  }\n return output+(output.split`\\n`.reverse().slice(2).join`\\n`);\n}\n"
  },
  {
    "path": "Complete the table pattern.js",
    "content": "/*\nWhen no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said\n\nDescription:\nGive you two number rows , columns and a string str. Returns a rows x columns table pattern and fill in the str(each grid fill in a char, the length of str is always less than or equals to the total numbers of grids):\n\n If rows = 4 and columns = 4, str = \"Hello World!\"\n The pattern should be a 4x4 table like this:\n +---+---+---+---+\n | H | e | l | l |   From left to right\n +---+---+---+---+\n | o |   | W | o |   and from top to bottom\n +---+---+---+---+\n | r | l | d | ! |   each row separated by \"\\n\"\n +---+---+---+---+\n |   |   |   |   |\n +---+---+---+---+\nSome examples:\npattern(3, 3, \"codewars\") should return:\n+---+---+---+\n| c | o | d |\n+---+---+---+\n| e | w | a |\n+---+---+---+\n| r | s |   |\n+---+---+---+\n\npattern(4, 3, \"Nice pattern\") should return:\n+---+---+---+\n| N | i | c |\n+---+---+---+\n| e |   | p |\n+---+---+---+\n| a | t | t |\n+---+---+---+\n| e | r | n |\n+---+---+---+\n\npattern(3, 4, \"Nice pattern\") should return:\n+---+---+---+---+\n| N | i | c | e |\n+---+---+---+---+\n|   | p | a | t |\n+---+---+---+---+\n| t | e | r | n |\n+---+---+---+---+\n*/\nfunction pattern(rows,columns,str){\n  const arr = str.split``\n  let i=0;\n  const s = ('+---'.repeat(columns)+'+'+'\\n'+'|   '.repeat(columns)+'|'+'\\n').repeat(rows)+'+---'.repeat(columns)+'+'\n  return s.replace(/\\s\\s\\s/g,v=>' '+(arr[i++]||' ')+' ')\n}\n"
  },
  {
    "path": "Consecutive strings",
    "content": "/*\nYou are given an array strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array.\n\n#Example: longest_consec([\"zone\", \"abigail\", \"theta\", \"form\", \"libe\", \"zas\", \"theta\", \"abigail\"], 2) --> \"abigailtheta\"\n\nn being the length of the string array, if n = 0 or k > n or k <= 0 return \"\".\n*/\n\nfunction longestConsec(strarr, k) {\n    var longest = \"\";\n    for(var i=0;k>0 && i<=strarr.length-k;i++){\n      var tempStr = strarr.slice(i,i+k).join(\"\");\n      if(tempStr.length > longest.length){\n        longest = tempStr;\n      }\n    }\n    return longest;\n}\n"
  },
  {
    "path": "Consonant value,js",
    "content": "/*\nTo introduce the problem think to my neighbor who drives a tanker truck. The level indicator is down and he is worried because he does not know if he will be able to make deliveries. We put the truck on a horizontal ground and measured the height of the liquid in the tank.\n\nFortunately the tank is a perfect cylinder and the vertical walls on each end are flat. The height of the remaining liquid is h, the diameter of the cylinder is d, the total volume is vt (h, d, vt are positive or null integers). You can assume that h <= d.\n\nCould you calculate the remaining volume of the liquid? Your function tankvol(h, d, vt) returns an integer which is the truncated result (e.g floor) of your float calculation.\n\nExamples:\n\ntankvol(40,120,3500) should return 1021 (calculation gives about: 1021.26992027)\n\ntankvol(60,120,3500) should return 1750\n\ntankvol(80,120,3500) should return 2478 (calculation gives about: 2478.73007973)\nTank vertical section:\n\nalternative text\n*/\nfunction solve(s) {\n  s=s.toLowerCase();\n  let arr=s.slice().replace(/[aeiuo]/g,' ').replace(/\\s+/g,' ');\n  arr=arr.split(' ').map(v=>v.split('').map(v=>v.charCodeAt()-96).reduce((a,b)=>a+b,0))\n  return Math.max(...arr);\n};\n"
  },
  {
    "path": "Convert integer to Whitespace format.js",
    "content": "/*\nDescription:\nStory\nHereinafter, [space] refers to \" \", [tab] refers to \"\\t\", and [LF] refers to \"\\n\" for illustrative purposes. This does not mean that you can use these placeholders in your solution.\n\nIn esoteric language called Whitespace, numbers are represented in the following format:\n\nfirst character represents the sign: [space] for plus, [tab] for minus;\ncharacters after that and until [LF] are the binary representation of the integer: [space] for 0, [tab] for 1.\nthe integer MUST be terminated by [LF].\nNotes\nValid Whitespace number must always have at least two characters: a sign and the terminator. In case there are only two characters, the number is equal to zero.\nFor the purposes of this kata, zero must always be represented as [space][LF].\nIn this kata, the output should not contain any leading zeros.\nIn Whitespace, only space, tabulation and linefeed are meaningful characters. All other characters are ignored. However, for the purposes of this simple kata, please do not add any other characters in the output.\nIn this kata, input will always be a valid negative or positive integer.\nFor your convenience, in this kata we will use unbleach() function when evaluating your results. This function replaces whitespace characters with [space], [tab], and [LF] to make fail messages more obvious. You can see how it works in Example Test Cases.\nExamples\n1 in Whitespace is \" \\t\\n\".\n0 in Whitespace is \" \\n\".\n-1 in Whitespace is \"\\t\\t\\n\".\n2 in Whitespace is \" \\t \\n\".\n-3 in Whitespace is \"\\t\\t\\t\\n\".\nMore on Whitespace\nIf you liked this kata, you may also enjoy a much harder Whitespace-related kata: Whitespace interpreter by @jacobb.\n*/\nfunction whitespaceNumber(n) {\n    let b = n.toString(2)\n    if (n===0) return ' \\n'\n    if (n<0){\n    let str = '\\t'\n      for (let i=1;i<b.length;i++){\n        if (b[i]==1) str+='\\t'\n        else str+=' '\n      }\n      return str+'\\n'\n    }\n    if (n>=0){\n    let str = ' '\n      for (let i=0;i<b.length;i++){\n        if (b[i]==1) str+='\\t'\n        else str+=' '\n      }\n      return str+'\\n'\n    }\n  }\n"
  },
  {
    "path": "Convert string to camel case",
    "content": "/*\nDescription:\nComplete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized.\n\nExamples\ntoCamelCase(\"the-stealth-warrior\") // returns \"theStealthWarrior\"\n\ntoCamelCase(\"The_Stealth_Warrior\") // returns \"TheStealthWarrior\"\n*/\n\nfunction toCamelCase(str){\n  return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase());\n}\n"
  },
  {
    "path": "Coordinates Validator",
    "content": "/*\nDescription:\nYou need to create a function that will validate if given parameters are valid geographical coordinates.\n\nValid coordinates look like the following: \"23.32353342, -32.543534534\". The return value should be either true or false.\n\nLatitude (which is first float) can be between 0 and 90, positive or negative. Longitude (which is second float) can be between 0 and 180, positive or negative.\n\nCoordinates can only contain digits, or one of the following symbols (including space after comma) -, .\n\nThere should be no space between the minus \"-\" sign and the digit after it.\n\nHere are some valid coordinates:\n\n-23, 25\n24.53525235, 23.45235\n04, -23.234235\n43.91343345, 143\n4, -3\nAnd some invalid ones:\n\n23.234, - 23.4234\n2342.43536, 34.324236\nN23.43345, E32.6457\n99.234, 12.324\n6.325624, 43.34345.345\n0, 1,2\n0.342q0832, 1.2324\n*/\n\nfunction isValidCoordinates(coordinates){\n  return /^(-?((\\d|[0-8]\\d)(\\.\\d+)?)|90),\\s?(-?((\\d\\d?|[01][0-7]\\d)(\\.\\d+)?)|180)$/.test(coordinates);\n}\n"
  },
  {
    "path": "Count Repeats.js",
    "content": "/*\nDescription:\nWrite a function that returns the count of characters that have to be removed in order to get a string with no consecutive repeats.\n\nNote: This includes any characters\n\nExamples\n'abbbbc'  => 'abc'    #  answer: 3\n'abbcca'  => 'abca'   #  answer: 2\n'ab cca'  => 'ab ca'  #  answer: 1\n*/\nfunction countRepeats(str) {\n    return str.length-str.replace(/(.)\\1+/g,'$1').length\n}\n"
  },
  {
    "path": "Count characters in your string",
    "content": "/*Description:\nThe main idea is to count all the occuring characters(UTF-8) in string. If you have string like this aba then the result should be { 'a': 2, 'b': 1 }\n\nWhat if the string is empty ? Then the result should be empty object literal { }\n\nFor C#: Use a Dictionary<char, int> for this kata!\n*/\n\nfunction count (string) {  \n   let cache={};\n   string.split('').map(v=>cache[v]=cache[v]+1||1)\n   return cache;\n}\n"
  },
  {
    "path": "Count letters in string.js",
    "content": "/*\nDescription:\nIn this kata, you've to count lowercase letters in a given string and return the letter count in a hash with 'letter' as key and count as 'value'. The key must be 'symbol' instead of string in Ruby and 'char' instead of string in Crystal.\n\nExample:\n\nletter_count('arithmetics') #=> {\"a\": 1, \"c\": 1, \"e\": 1, \"h\": 1, \"i\": 2, \"m\": 1, \"r\": 1, \"s\": 1, \"t\": 2}\n*/\nfunction letterCount(s){\n  return s.split``.reduce((a,b)=>(a[b]=a[b]+1||1,a),{})\n}\n"
  },
  {
    "path": "Count the days!.js",
    "content": "/*\nDescription:\nLittle Annie is very excited for upcoming events. She want's to know how many days she have to wait for a specific event.\n\nYour job is to help her out.\n\nTask: Write a function which returns the number of days from today till the given date. The function will take a Date object as parameter. You have to round the amount of days.\n\nIf the event is in the past, return \"The day is in the past!\"\nIf the event is today, return \"Today is the day!\"\nElse, return \"x days\"\n\nPS: This is my first kata. I hope you have fun^^\n\nThis kata is part of the Collection \"Date fundamentals\":\n\n#1 Count the Days!\n#2 Minutes to Midnight\n#3 Can Santa save Christmas?\n#4 Christmas Present Calculator\n*/\nfunction countDays(d){\n  let time = d\n  let today=new Date()\n  let todayCheck= time.getFullYear()===today.getFullYear()&&time.getMonth()===today.getMonth()&&time.getDay()===today.getDay()\n  if (todayCheck) return \"Today is the day!\"\n  let past = today.getTime()>time.getTime()\n  if (past) return 'The day is in the past!'\n  return `${Math.round((time.getTime()-today.getTime())/1000/60/60/24)} days`\n}\n"
  },
  {
    "path": "Count the divisible numbers.js",
    "content": "/*\nDescription:\nWrite function divisibleCount(x, y, k) that takes in 3 numbers x, y and k, and returns the number of integers within the range [x..y] that are divisible by k i.e.:\n{ i : x ≤ i ≤ y, i mod k = 0 }\nFor example:\nx = 6, y = 11 and k = 2, your function should return 3, because there are three numbers divisible by 2 within the range [6..11], namely 6, 8 and 10.\nNote: x<=y\n*/\nfunction divisibleCount(x, y, k) {\n  return Math.floor(y/k) - Math.floor((x-1)/k)\n}\n"
  },
  {
    "path": "Count the smiley faces!",
    "content": "/*\nDescription:\nGiven an array (arr) as an argument complete the function countSmileys that should return the total number of smiling faces.\n\nRules for a smiling face:\n-Each smiley face must contain a valid pair of eyes. Eyes can be marked as : or ;\n-A smiley face can have a nose but it does not have to. Valid characters for a nose are - or ~\n-Every smiling face must have a smiling mouth that should be marked with either ) or D.\nNo additional characters are allowed except for those mentioned.\nValid smiley face examples:\n:) :D ;-D :~)\nInvalid smiley faces:\n;( :> :} :] \n\nExample cases:\n\ncountSmileys([':)', ';(', ';}', ':-D']);       // should return 2;\ncountSmileys([';D', ':-(', ':-)', ';~)']);     // should return 3;\ncountSmileys([';]', ':[', ';*', ':$', ';-D']); // should return 1;\n*/\n\n\nfunction countSmileys(arr) {\n  return arr.filter(v=>v.match(/(:|;)(-|~)?(\\)|D)/)).length\n}\n"
  },
  {
    "path": "Countdown - Longest Word.js",
    "content": "/*\nDescription:\n#Detail\n\nCountdown is a British game show with number and word puzzles. The letters round consists of the contestant picking 9 shuffled letters - either picking from the vowel pile or the consonant pile. The contestants are given 30 seconds to try to come up with the longest English word they can think of with the available letters - letters can not be used more than once unless there is another of the same character.\n\n#Task\n\nGiven an uppercase 9 letter string, letters, find the longest word that can be made with some or all of the letters. The preloaded array words (or $words in Ruby) contains a bunch of uppercase words that you will have to loop through. Only return the longest word; if there is more than one, return the words of the same lengths in alphabetical order. If there are no words that can be made from the letters given, return None/nil/null.\n\n##Examples\n\nletters = \"ZZZZZZZZZ\"\nlongest word = None\n\nletters = \"POVMERKIA\", \nlongest word = [\"VAMPIRE\"]\n\nletters = \"DVAVPALEM\"\nlongest word = [\"VAMPED\", \"VALVED\", \"PALMED\"]\n*/\nfunction longestWord(letters){\n  let dict = letters.split``.reduce((a,b)=>(a[b]=a[b]+1||1,a),{})\n  let arr = []\n  for (let i=0;i<words.length;i++){\n    let c = {...dict}\n    for (let j=0;j<words[i].length;j++){\n      if (c[words[i][j]]){\n        if (c[words[i][j]]>0){\n          c[words[i][j]]--\n          if (j===words[i].length-1){\n           arr.push(words[i])\n          }\n        } else {\n          break\n        }\n      } else {\n        break\n      }\n    }\n  }\n  if (arr.length===0) return null\n  let max = Math.max(...arr.map(v=>v.length))\n  return arr.filter(v=>v.length===max)\n}\n"
  },
  {
    "path": "Counting DNA Nucleotides.js",
    "content": "/*\nDescription:\nFor a given DNA genectic code represented by a string, count the number of times the letters A (adenine), C (cytosine), G (guanine) and T (thymine) appears and return and object.\n\nAll letters must be in uppercase.\n\nFor example:\n\nvar genCode = 'TCCAGAAAGGTAAGCCTCGCGTTGCGAAAATGTCAAGTTACCACATCCACACCACCTCGAGCAGCTTCTATAGCTAGCCAGCACAGAGACTCGCAGTCCCTCTACAAGCTTCCAATTGGAAGAGAGCTCGGGCCAAGCGTTTGTCGCCCCCCTCCCATTGAGATAAACCCGCATTCATTCAGGTACGAACGGATGCAGCTTGATTCTCCCCATGTAGTTAACTCGCTACATCCTATCAGCCTGAGGGTCCAAGTTGCTAGACCTACATTCACTCCTGCGCTCCTCATAAGCGACCTATCGACTAGTCTTGGCTTACACCTCAGAAGTGCGCTATTGGGCGGGTATTCAGTGGTTGCACGGCGCTTATGTGGGACGCGGTGTCTTAGAGGACAGAAGATGTACAGTCAATGGAGGGATCCTCCCGAGTCGCCATCTACCCATGCGTCTGAGATATGAAAGCAGCTACCAGCCTTTCAGCCACTCTGAAAGATTTCCGTCCTCTATCAAACGACCTGCCCCAGGCTTACTGTTACTAGTTCTTTGCAAATTAACTGTACTCATTTGGGAGAGTTCGCATGCGCCTCTCCATCATACTAGCGCAAAACCTGACATTCAAACGATTCCGCACCCAAAGCCGCGAATGTGTCCCCTTACATTTCGGAGAAAACCGGCTCGACTTGGCACCAAGAACTTTTATACGCTGGGTTGTGCCATGTCTTTATGTTTATCCTTTGGGCGGCAGGAGCGTCCTCACTGTTGCTCTGAAACAGTACATGCACATGTCTAGACGAACCTGAAGAACCCCTGAACACGCCATGCACCGCGCGTAAAGCCAGTTTCGACTGGTATATATAATGATGTTGTGAAACAAATCGGGAAGGCGCAGAAAAGAATGTGGTTGGACGAAGTCCATAACTGAAGGTTAGCGA';\n\ngetCountedNucleotides(genCode); // return {A: 238, C: 254, G: 212, T: 225}\n*/\nfunction getCountedNucleotides(genCode){\n  const DNA = {A: 0, C: 0, G: 0, T: 0};\n  genCode.toUpperCase().split``.map(v=>DNA[v]=DNA[v]?DNA[v]+1:1)\n  return DNA\n}\n"
  },
  {
    "path": "Counting Duplicates",
    "content": "/*\nDescription:\nCount the number of Duplicates\nWrite a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.\n\nExample\n\"abcde\" -> 0 # no characters repeats more than once\n\"aabbcde\" -> 2 # 'a' and 'b'\n\"aabBcde\" -> 2 # 'a' occurs twice and 'b' twice (`b` and `B`)\n\"indivisibility\" -> 1 # 'i' occurs six times\n\"Indivisibilities\" -> 2 # 'i' occurs seven times and 's' occurs twice\n\"aA11\" -> 2 # 'a' and '1'\n\"ABBA\" -> 2 # 'A' and 'B' each occur twice\n*/\n\nfunction duplicateCount(text){\n  return (text.toLowerCase().split('').sort().join('').match(/([^])\\1+/g) || []).length;\n}\n"
  },
  {
    "path": "Create Four Letter Birding Codes from Bird Names.js",
    "content": "/*\nDescription:\nIn the world of birding there are four-letter codes for the common names of birds. These codes are created by some simple rules:\n\nIf the bird's name has only one word, the code takes the first four letters of that word.\nIf the name is made up of two words, the code takes the first two letters of each word.\nIf the name is made up of three words, the code is created by taking the first letter from the first two words and the first two letters from the third word.\nIf the name is four words long, the code uses the first letter from all the words.\n(There are other ways that codes are created, but this Kata will only use the four rules listed above)\n\nComplete the function that takes an array of strings of common bird names from North America, and create the codes for those names based on the rules above. The function should return an array of the codes in the same order in which the input names were presented.\n\nAdditional considertations:\n\nThe four-letter codes in the returned array should be in UPPER CASE.\nIf a common name has a hyphen/dash, it should be considered a space.\nExample\nIf the input array is: [\"Black-Capped Chickadee\", \"Common Tern\"]\n\nThe return array would be: [\"BCCH\", \"COTE\"]\n*/\nfunction birdCode(arr){\n  return arr.map(v=>{\n    v=v.replace(/-./g,v=>v.toUpperCase())\n    let arr =v.match(/[A-Z]./g)\n    if (arr.length===1){\n      return v.slice(0,4).toUpperCase()\n    }\n    if (arr.length===2){\n      return arr.join``.toUpperCase()\n    }\n    if (arr.length===3){\n      return arr[0][0]+arr[1][0]+arr[2].toUpperCase()\n    }\n    return arr.map(v=>v[0].toUpperCase()).join``\n  })\n}\n"
  },
  {
    "path": "Create Parse HTML CSS Colors.js",
    "content": "/*\nDescription:\nIn this kata you parse RGB colors represented by strings. The formats are primarily used in HTML and CSS. Your task is to implement a function which takes a color as a string and returns the parsed color as a map (see Examples).\nInput:\nThe input string represents one of the following:\n6-digit hexadecimal - \"#RRGGBB\"\ne.g. \"#012345\", \"#789abc\", \"#FFA077\"\nEach pair of digits represents a value of the channel in hexadecimal: 00 to FF\n3-digit hexadecimal - \"#RGB\"\ne.g. \"#012\", \"#aaa\", \"#F5A\"\nEach digit represents a value 0 to F which translates to 2-digit hexadecimal: 0->00, 1->11, 2->22, and so on.\nPreset color name\ne.g. \"red\", \"BLUE\", \"LimeGreen\"\nYou have to use the predefined map PRESET_COLORS (JavaScript, Python, Ruby), presetColors (Java, C#, Haskell), or preset-colors (Clojure). The keys are the names of preset colors in lower-case and the values are the corresponding colors in 6-digit hexadecimal (same as 1. \"#RRGGBB\").\nExamples:\nparseHTMLColor('#80FFA0');    // => { r: 128, g: 255, b: 160 }\nparseHTMLColor('#3B7');       // => { r: 51,  g: 187, b: 119 }\nparseHTMLColor('LimeGreen');  // => { r: 50,  g: 205, b: 50  }\n*/\nfunction parseHTMLColor(c) {\n  if (!c.match(\"#\")) c = PRESET_COLORS[c.toLowerCase()];\n\n  c = c.replace('#', '');\n\n  if (c.length < 6) c = c.replace(/(.)/g, \"$1$1\");\n\n  return {\n    r: parseInt(c.substring(0, 2), 16),\n    g: parseInt(c.substring(2, 4), 16),\n    b: parseInt(c.substring(4, 6), 16)\n  };\n}\n"
  },
  {
    "path": "Create a frame!.js",
    "content": "/*\nDescription:\n*************************\n*  Create a frame!      *\n*           __     __   *\n*          /  \\~~~/  \\  *\n*    ,----(     ..    ) *\n*   /      \\__     __/  *\n*  /|         (\\  |(    *\n* ^  \\  /___\\  /\\ |     *\n*    |__|   |__|-..     *\n*************************\nGiven an array of strings and a character to be used as border, output the frame with the content inside.\n\nNotes:\n\nAlways keep a space between the input string and the left and right borders.\nThe biggest string inside the array should always fit in the frame.\nThe input array is never empty.\nExample\nframe(['Create', 'a', 'frame'], '+')\n\nOutput:\n\n++++++++++\n+ Create +\n+ a      +\n+ frame  +\n++++++++++\n*/\nconst frame = (text, char) => {\n  let max =Math.max(...text.map(v=>v.length))\n  let top = char.repeat(max+4)\n  return top+`\\n`+text.map(v=>`${char} `+v+' '.repeat(max-v.length)+` ${char}`).join`\\n`+`\\n`+top;\n};\n"
  },
  {
    "path": "Creating a string for an array of objects from a set of words.js",
    "content": "/*\nDescription:\nYou're given a string containing a sequence of words separated with whitespaces. Let's say it is a sequence of patterns: a name and a corresponding number - like this:\n\n\"red 1 yellow 2 black 3 white 4\"\n\nYou want to turn it into a different string of objects you plan to work with later on - like this:\n\n\"[{name : 'red', id : '1'}, {name : 'yellow', id : '2'}, {name : 'black', id : '3'}, {name : 'white', id : '4'}]\"\n\nDoing this manually is a pain. So you've decided to write a short function that would make the computer do the job for you. Keep in mind, the pattern isn't necessarily a word and a number. Consider anything separeted by a whitespace, just don't forget: an array of objects with two elements: name and id.\n\nAs a result you'll have a string you may just copy-paste whenever you feel like defining a list of objects - now without the need to put in names, IDs, curly brackets, colon signs, screw up everything, fail searching for a typo and begin anew. This might come in handy with large lists.\n*/\nfunction wordsToObject(input) {\n  let arr = []\n  input=input.split` `\n  for (let i=0;i<input.length;i+=2){\n    arr.push([input[i],input[i+1]])\n  }\n    arr =arr.map(v=>{\n    return v=`{name : \\'${v[0]}\\', id : \\'${v[1]+''}\\'}`})\n    return '['+arr.join`, `+']'\n}\n"
  },
  {
    "path": "Cryptography #1 - Viva Cesare.js",
    "content": "/*\nDescription:\nLet’s get to know our hero: Agent #134 - Mr. Slayer.\n\nHe was sent by his CSV agency to Ancient Rome in order to resolve some important national issues. However, something incredible has happened - the enemies have taken Julius Caesar as a prisoner!!!\n\nCaesar, not a simple man as you know, managed to send cryptic message with coordinates of his location hoping that somebody would break the code. Here our agent of the secret service comes to the stage.\n\nBut he needs your help!\n\nMission:\n\nYou have to implement the function “Encode” of CaesarCrypto class that codes or decodes text based on Caesar’s algorithm.\n\nthe function receives 2 parameters: an original text of any length of type “string” and a number of type “int” that represents shifts;\nonly letters in both cases must be encrypted;\nalphabet contains only letters in this range: a-zA-Z;\nby encryption the letter can change the case;\nshift could be either positive or negative (for left shift);\nIf the input text is empty, null or includes only whitespaces, return an empty string.\nTime's ticking away. The life of Caesar is on the chopping block! Go for it!\n*/\nfunction CaesarCryptoEncode(text, shift) {\n  if (!text) return '';\n  shift = (shift % 52 + 52) % 52;\n  const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\n  return text.trim().replace(/[a-z]/ig, c => letters[(letters.indexOf(c) + shift) % 52]); \n}\n"
  },
  {
    "path": "Cumulative Triangle.js",
    "content": "/*\nDescription:\nImagine a triangle of numbers which follows this pattern:\n\nStarting with the number \"1\", \"1\" is positioned at the top of the triangle. As this is the 1st row, it can only support a single number.\nThe 2nd row can support the next 2 numbers: \"2\" and \"3\"\nLikewise, the 3rd row, can only support the next 3 numbers: \"4\", \"5\", \"6\"\nAnd so on; this pattern continues.\n    1\n   2 3\n  4 5 6\n 7 8 9 10\n...\nGiven N, return the sum of all numbers on the Nth Row:\n\n1 <= N <= 10,000\n*/\nlet arr = []\nconst heheboi=()=>{\n  let num = 0\n  for (let i=1;i<=10000;i++){\n  let tempArr = []\n    for (let j=0;j<i;j++){\n      num++\n      tempArr.push(num)\n    }\n    arr.push(tempArr)\n  }\n}\nheheboi()\nfunction cumulativeTriangle(n) {\n  return arr[n-1].reduce((a,b)=>a+b,0)\n}\n"
  },
  {
    "path": "Custom Array Filters.js",
    "content": "/*\nDescription:\nDave has a lot of data he is required to apply filters to, which are simple enough, but he wants a shorter way of doing so.\n\nHe wants the following functions to work as expected:\n\neven    // [1,2,3,4,5].even() should return [2,4]\nodd     // [1,2,3,4,5].odd() should return [1,3,5]\nunder   // [1,2,3,4,5].under(4) should return [1,2,3]\nover    // [1,2,3,4,5].over(4) should return [5]\ninRange // [1,2,3,4,5].inRange(1,3) should return [1,2,3]\nThey should also work when used together, for example:\n\n[1,2,18,19,20,21,22,30,40,50,100].even().inRange(18,30) // should return [18, 20, 22, 30]\nAnd finally the filters should only accept integer values from an array, for example:\n\n[\"a\", 1, \"b\", 300, \"x\", \"q\", 63, 122, 181, \"z\", 0.83, 0.11].even() // should return [300, 122]\n*/\nArray.prototype.even = function(){\n   return this.filter(v=>v%2===0&&typeof v==='number'&&v!==0&&Number.isInteger(v))\n}\n\nArray.prototype.odd = function(){\n\n  return this.filter(v=>v%2!==0&&typeof v==='number'&&Number.isInteger(v))\n}\n\nArray.prototype.under = function(x){\n  return this.filter(v=>v<x&&typeof v==='number'&&Number.isInteger(v))\n}\n\nArray.prototype.over = function(x){\n  return this.filter(v=>v>x&&typeof v==='number'&&Number.isInteger(v))\n}\n\nArray.prototype.inRange = function(min,max){\n   return this.filter(v=>v>=min&&v<=max&&typeof v==='number'&&Number.isInteger(v))\n}\n"
  },
  {
    "path": "Custom Setters and Getters.js",
    "content": "/*\nDescription:\nLet's take a look at an interesting feature of JS: custom Getters and Setters for objects.\n\nSkimming over this may help you prepare for this kata: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects?redirectlocale=en-US&redirectslug=JavaScript%2FGuide%2FWorking_with_Objects#Defining_Getters_and_Setters (thanks to @contablebrew for pointing out the more \"forward-compatible\" approach to this.)\n\nThe object of this exercise will be to provide a constructor named \"Archiver\" that creates a \"self-archiving\" object with respect to its \"temperature\" property, but otherwise looks and acts just like a normal JS object. Each time the \"temperature\" property is assigned, the object should add a log entry to an array (the \"archive\") that it returns via a \"getArchive\" function. The log entry should be formed as such: {date: //the Date when the \"temperature\" property was assigned, val: //the value that was written to the \"temperature\" property.} . The \"date\" property of the log entry should be a valid JS Date object.\n\nso e.g.:\n\n//new Date() == '2013-09-24...Z'\nvar arc = new Archiver();\narc.temperature = 33;\narc.temperature = 28;\narc.temperature = 21;\narc.getArchive() // == [{date: 2013-09-24..., val:33},{date: 2013-09-24..., val:28},{date: 2013-09-24..., val:21}]\n*/\nfunction Archiver() {\n    var temperature = null;\n    var archive = [];\n    Object.defineProperty(this, 'temperature', {\n      get: function() { return temperature; },\n      set: function(value) { \n        temperature = value;\n        archive.push({ date: new Date(), val: temperature });\n      }\n    });\n    this.getArchive = function() {return archive;};\n}\n"
  },
  {
    "path": "Custom each() Array method.js",
    "content": "/*\nDescription:\nJavaScript provides an Array.prototype.forEach method that allows you to iterate over array values. For this exercise you will create your own array method called 'each'. It will be similar to the forEach method, except for one difference. If the callback function returns true then the loop will stop and no additional values will be iterated.\n\nThe following shows a contrived example of how this new method would be used:\n\nvar letters = ['a', 'b', 'c', 'd', 'e']\nvar allowedLetters = []\nletters.each(function(letter, index){\n  // break out of the loop if we reached a letter with the value 'd'\n  if(letter == 'd') {\n    return true;\n  }\n  allowedLetters.push(letter);   \n})\n\n// allowedLetters should equal ['a', 'b', 'c']\nIn Ruby, you would use it like this:\n\nletters = ['a', 'b', 'c', 'd', 'e']\nallowedLetters = []\n\nletters.each_until_true do |letter, index|\n  # break out of the loop if we reached a letter with the value 'd'\n  if letter == 'd'\n    true\n  else\n    allowedLetters.push(letter);   \n  end\nend\n\n# allowedLetters should equal ['a', 'b', 'c']\n*/\nArray.prototype.each = [].some\n"
  },
  {
    "path": "Custom sort function.js",
    "content": "/*\nDescription:\nComplete the sort function so that it returns the items passed into it in alphanumerical order. Conveniently enough, the standard array sort method has been disabled for you so that you are forced to create your own.\n\nExample:\n\nsort([1,3,2]) // should return [1,2,3]\n*/\nfunction sort(array) {\n    if (array.length === 1) return array;\n    let left = array.slice(0, array.length / 2);\n    let right = array.slice(array.length / 2 );\n    left = sort(left);\n    right = sort(right);\n    return merge(left, right);\n}\nfunction merge(left, right) {\n    let arr = [];\n    while (left.length > 0 && right.length > 0) {\n        if (left[0] > right[0]) {\n            arr.push(right[0]);\n            right.shift()\n        } else {\n            arr.push(left[0]);\n            left.shift();\n        }\n    }\n    while (left.length) {\n        arr.push(left[0]);\n        left.shift();\n    }\n    while (right.length) {\n        arr.push(right[0]);\n        right.shift();\n    }\n    return arr\n}\n"
  },
  {
    "path": "Cycle Detection: greedy algorithm.js",
    "content": "/*\nDescription:\nIn computer science, cycle detection is the algorithmic problem of finding a cycle in a sequence of iterated function values.\n\nFor any function ƒ, and any initial value x0 in S, the sequence of iterated function values\n\nx0,x1=f(x0), x2=f(x1), ...,xi=f(x{i-1}),...\nmay eventually use the same value twice under some assumptions: S finite, f periodic ... etc. So there will be some i ≠ j such that xi = xj. Once this happens, the sequence must continue by repeating the cycle of values from xi to xj−1. Cycle detection is the problem of finding i and j, given ƒ and x0. Let μ be the smallest index such that the value associated will reappears and λ the smallest value such that xμ = xλ+μ, λ is the loop length.\n\nExample:\n\nConsider the sequence:\n\n2, 0, 6, 3, 1, 6, 3, 1, 6, 3, 1, ....\nThe cycle in this value sequence is 6, 3, 1. μ is 2 (first 6) λ is 3 (length of the sequence or difference between position of consecutive 6).\n\nThe goal of this kata is to build a function that will return [μ,λ] when given a short sequence. Simple loops will be sufficient. The sequence will be given in the form of an array. All array will be valid sequence associated with deterministic function. It means that the sequence will repeat itself when a value is reached a second time. (So you treat two cases: non repeating [1,2,3,4] and repeating [1,2,1,2], no hybrid cases like [1,2,1,4]). If there is no repetition you should return [].\n\nThis kata is followed by two other cycle detection algorithms: Loyd's: http://www.codewars.com/kata/cycle-detection-floyds-tortoise-and-the-hare Bret's: http://www.codewars.com/kata/cycle-detection-brents-tortoise-and-hare\n*/\nfunction cycle(a) {\n  const sndIdx = a.findIndex( (v,i) =>{\n  return a.slice(0,i).includes(v) });\n  if ( sndIdx===-1 )\n    return [];\n  else {\n    const fstIdx = a.indexOf(a[sndIdx]);\n    return [ fstIdx, sndIdx-fstIdx ];\n  }\n}\n"
  },
  {
    "path": "Cycle a list of values.js",
    "content": "/*\nDescription:\nPrologue\nYou're part of a team porting MS Paint into the browser and currently working on a new UI component that allows user to control the canvas zoom level.\n\nAccording to the wireframes delivered to you in PowerPoint format the user should be able to cycle through specified zoom levels by clicking a button in the UI repeatedly. The reverse direction should work with shift key held.\n\nA new function is needed to support this behavior, so you alt-tab to Visual Studio and get to work.\n\nInstructions\nImplement a function which when given the arguments\n\nDirection to which to cycle the current value\nList of values\nCurrent value\nreturns the value next to current value in the specified direction.\n\nThe function should pick the next value from the other side of the list in case there are no values in the given direction.\n\nExamples\ncycle(1, [1,2,3], 1)   // => 2\n// Given the direction 1, returns the value next to 1 on the right\n\ncycle(-1, [1,2,3], 1)  // => 3\n// Given the direction -1 and value 1, wraps around list returning the last element\n\ncycle(1, [1,2,3], 0)   // => null\n// 0 does not exist in the list, returns null\n\ncycle(1, [1,2,2,3], 2) // => 2\n// Corner case: multiple instances of given value, picks next relative to first occurrence\n*/\nfunction cycle(dir, arr, cur) {\n\tif (!arr.includes(cur)) return null; \n  const index=arr.indexOf(cur) \n  return arr[(index+dir)%arr.length]?arr[(index+dir)%arr.length]:arr.reverse()[index%arr.length]\n}\n"
  },
  {
    "path": "Cylon Evolution.js",
    "content": "/*\nDescription:\nThere are all types of cylons. The trick is, some look like humans. Using prototypical inheritance, create a prototype for Cylon. Cylons should have a model, and should have an attack function, which will return the string \"Destory all humans!\"\n\nSince some cylons appear human, then make a child object called HumanSkin. This should have a model, as Cylons do, and should have the same attack. However, it should also have a function called infiltrate, which will return the string \"Infiltrate the colonies\".\n*/\nclass Cylon{\n  constructor(model){\n  this.model=model\n  }\n  attack(){\n  return \"Destroy all humans!\"\n  }\n}\n\nclass HumanSkin extends Cylon{\n  constructor(model){\n  super(model)\n  this.model=model\n  }\n  infiltrate(){\n  return \"Infiltrate the colonies\"\n  }\n}\n"
  },
  {
    "path": "Dashatize it.js",
    "content": "/*\nDescription:\nGiven a number, return a string with dash'-'marks before and after each odd integer, but do not begin or end the string with a dash mark.\n\nEx:\n\ndashatize(274) -> '2-7-4'\ndashatize(6815) -> '68-1-5'\n*/\n\nfunction dashatize(num) {\n  return String(num)\n    .replace(/([13579])/g, \"-$1-\")\n    .replace(/--+/g, \"-\")\n    .replace(/(^-|-$)/g, \"\")\n}\n"
  },
  {
    "path": "Data Reverse.js",
    "content": "/*\nDescription:\nA stream of data is received and needs to be reversed.\n\nEach segment is 8 bits long, meaning the order of these segments needs to be reversed, for example:\n\n11111111  00000000  00001111  10101010\n (byte1)   (byte2)   (byte3)   (byte4)\nshould become:\n\n10101010  00001111  00000000  11111111\n (byte4)   (byte3)   (byte2)   (byte1)\nThe total number of bits will always be a multiple of 8.\n\nThe data is given in an array as such:\n\n[1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,0,1,0,1,0]\n*/\n\nconst dataReverse = function(data){\n  if (data.length===0) return []\n  const arrayBytes = [];\n  const tam = data.length / 8;\n  for (var i = 0; i < tam; i++){\n    arrayBytes.push(data.splice(0,8));\n  }\n  return arrayBytes.reverse().join().split(',').map(v=>v*1);\n}\n"
  },
  {
    "path": "Data compression using run-length encoding.js",
    "content": "/*\nDescription:\nRun-length encoding (RLE) is a very simple form of lossless data compression in which runs of data are stored as a single data value and count.\n\nA simple form of RLE would encode the string \"AAABBBCCCD\" as \"3A3B3C1D\" meaning, first there are 3 A, then 3 B, then 3 C and last there is 1 D.\n\nYour task is to write a RLE encoder and decoder using this technique. The texts to encode will always consist of only uppercase characters, no numbers.\n*/\nfunction encode(input) {\n  let count=1;\n  let str='';\n  for (let i=0;i<input.length;i++){\n  if (input[i]===input[i+1]){\n    count++\n  } else {\n    str+=`${count}${input[i]}`\n    count=1\n  }}\n  return str;\n}\n\nfunction decode(input) {\n  const arr=input.slice().replace(/\\d/gi,' ').replace(/\\s+/g,' ').split(' ').filter(v=>v);\n  const arr2=input.slice().replace(/\\D/gi,' ').replace(/\\s+/g,' ').split(' ').filter(v=>v)\n  let str='';\n  for (let i=0;i<arr.length;i++){\n  str+=`${arr[i].repeat(arr2[i]*1)}`\n  }\n  return str\n}\n"
  },
  {
    "path": "Dead Ants.js",
    "content": "/*\nDescription:\nAn orderly trail of ants is marching across the park picnic area.\n\nIt looks something like this:\n\n..ant..ant.ant...ant.ant..ant.ant....ant..ant.ant.ant...ant..\nBut suddenly there is a rumour that a dropped chicken sandwich has been spotted on the ground ahead. The ants surge forward! Oh No, it's an ant stampede!!\n\nSome of the slower ants are trampled, and their poor little ant bodies are broken up into scattered bits.\n\nThe resulting carnage looks like this:\n\n...ant...ant..nat.ant.t..ant...ant..ant..ant.anant..t\nCan you find how many ants have died?\n\nNotes\nWhen in doubt, assume that the scattered bits are from the same ant. e.g. 2 heads and 1 body = 2 dead ants, not 3\n*/\ndeadAntCount = function(ants) {\n  if (!ants) return 0\n  let str = ants.replace(/ant/g,'')\n  let head =  str.replace(/[^a]/g,'').length\n  let body =  str.replace(/[^n]/g,'').length\n  let tail =  str.replace(/[^t]/g,'').length\n  return Math.max(head,body,tail)\n}\n"
  },
  {
    "path": "Decipher this!.js",
    "content": "/*\nDescription:\nYou are given a secret message you need to decipher. Here are the things you need to know to decipher it:\n\nFor each word:\n\nthe second and the last letter is switched (e.g. Hello becomes Holle)\nthe first letter is replaced by its character code (e.g. H becomes 72)\nNote: there are no special characters used, only letters and spaces\n\nExamples\n\ndecipherThis('72olle 103doo 100ya'); // 'Hello good day'\ndecipherThis('82yade 115te 103o'); // 'Ready set go'\n*/\nfunction decipherThis(str) {\n  return str.replace(/\\d+/g,v=>String.fromCharCode(v*1)).split(' ')\n  .map(v=>v.length>2?v.slice(0,1)+v.slice(-1)+v.slice(2,-1)+v.slice(1,2):v).join` `\n}; \n"
  },
  {
    "path": "Decode Morse.js",
    "content": "/*\nDescription:\nOh no! You have stumbled upon a mysterious signal consisting of beeps of various lengths, and it is of utmost importance that you find out the secret message hidden in the beeps. There are long and short beeps, the longer ones roughly three times as long as the shorter ones. Hmm... that sounds familiar.\n\nThat's right: your job is to implement a decoder for the Morse alphabet. Rather than dealing with actual beeps, we will use a common string encoding of Morse. A long beep is represened by a dash (-) and a short beep by a dot (.). A series of long and short beeps make up a letter, and letters are separated by spaces (). Words are separated by double spaces.\n\nYou should implement the International Morse Alphabet. You need to support letters a-z and digits 0-9 as follows:\n\na .-      h ....    o ---     u ..-      1 .----     6 -....\nb -...    i ..      p .--.    v ...-     2 ..---     7 --...\nc -.-.    j .---    q --.-    w .--      3 ...--     8 ---..\nd -..     k -.-     r .-.     x -..-     4 ....-     9 ----.\ne .       l .-..    s ...     y -.--     5 .....     0 -----\nf ..-.    m --      t -       z --..\ng --.     n -.\nExamples\n.... . .-.. .-.. --- .-- --- .-. .-.. -.. → \"hello world\"\n\n.---- ... - .- -. -.. ..--- -. -.. → \"1st and 2nd\"\n*/\nfunction decode(str) {\n  const morse = {'1':'.----','2':'..---','3':'...--','4':'....-',5:'.....',6:'-....',7:'--...',8:'---..',9:'----.',0:'-----','a':\".-\", 'b':\"-...\", 'c':\"-.-.\", 'd':\"-..\", 'e':\".\", 'f':\"..-.\", 'g':\"--.\", 'h':\"....\", 'i':\"..\", 'j':\".---\", 'k':\"-.-\", 'l':\".-..\", 'm':\"--\", 'n':\"-.\",\n   'o':\"---\", 'p':\".--.\", 'q':\"--.-\", 'r':\".-.\", 's':\"...\", 't':\"-\", 'u':\"..-\", 'v':\"...-\", 'w':\".--\", 'x':\"-..-\", 'y':\"-.--\", 'z':\"--..\"}\n const morse2={}\n for (let i in morse){\n   morse2[morse[i]]=i\n }\n return str.split` `.map(v=>morse2[v]||' ').join``\n}\n"
  },
  {
    "path": "Decode the Morse code",
    "content": "/*\nDescription:\nPart of Series 1/3\nThis kata is part of a series on the Morse code. After you solve this kata, you may move to the next one.\n\nIn this kata you have to write a simple Morse code decoder. While the Morse code is now mostly superceded by voice and digital data communication channels, it still has its use in some applications around the world.\nThe Morse code encodes every character as a sequence of \"dots\" and \"dashes\". For example, the letter A is coded as ·−, letter Q is coded as −−·−, and digit 1 is coded as ·−−−−. The Morse code is case-insensitive, traditionally capital letters are used. When the message is written in Morse code, a single space is used to separate the character codes and 3 spaces are used to separate words. For example, the message HEY JUDE in Morse code is ···· · −·−− ·−−− ··− −·· ·.\n\nNOTE: Extra spaces before or after the code have no meaning and should be ignored.\n\nIn addition to letters, digits and some punctuation, there are some special service codes, the most notorious of those is the international distress signal SOS (that was first issued by Titanic), that is coded as ···−−−···. These special codes are treated as single special characters, and usually are transmitted as separate words.\n\nYour task is to implement a function that would take the morse code as input and return a decoded human-readable string.\n\nFor example:\n\ndecodeMorse('.... . -.--   .--- ..- -.. .')\n//should return \"HEY JUDE\"\nNOTE: For coding purposes you have to use ASCII characters . and -, not Unicode characters.\n\nThe Morse code table is preloaded for you as a dictionary, feel free to use it:\n\nCoffeescript/C++/Go/JavaScript/PHP/Python/Ruby/TypeScript: MORSE_CODE['.--']\nC#: MorseCode.Get(\".--\") (returns string)\nElixir: morse_codes variable\nHaskell: morseCodes ! \".--\" (Codes are in a Map String String)\nJava: MorseCode.get(\".--\")\nKotlin: MorseCode[\".--\"] ?: \"\" or MorseCode.getOrDefault(\".--\", \"\")\nRust: self.morse_code\nAll the test strings would contain valid Morse code, so you may skip checking for errors and exceptions. In C#, tests will fail if the solution code throws an exception, please keep that in mind. This is mostly because otherwise the engine would simply ignore the tests, resulting in a \"valid\" solution.\n\nGood luck!\n\nAfter you complete this kata, you may try yourself at Decode the Morse code, advanced.\n*/\n\ndecodeMorse = function(morseCode){\n  return morseCode.split(' ').map((v,i)=>MORSE_CODE[v]!=undefined?MORSE_CODE[v]:1).join('').replace(/11/g,' ').replace(/1/g,' ').trim()\n}\n"
  },
  {
    "path": "Decompose a number.js",
    "content": "/*\nDescription:\nDecompose a number num into an array (tuple in Haskell, array of arrays long[][] in C# or Java) of the form [[k1,k2,k3...], r], ([k1,k2,k3...], r) in Haskell, [[k1,k2,k3...], [r]] in C# or Java) such that:\n\neach kn is more than one\neack kn is maximized (first maximizing for 2 then 3 then 4 and so on)\nand 2k1 + 3k2 + 4k3 + ... + nkn-1 + r = num\n##Examples\n\n# when there are no `k` more than 1:\n\n3 \n\n[[], 3] = \n\n3\n\n# when the remainder is zero:\n\n8330475\n\n[[22, 13, 10, 8, 7, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 0] = \n\n2 ^ 22 + 3 ^ 13 + 4 ^ 10 + 5 ^ 8 + 6 ^ 7 + 7 ^ 6 + 8 ^ 6 + 9 ^ 5 + 10 ^ 5 + 11 ^ 5 + 12 ^ 4 + 13 ^ 4 + 14 ^ 4 + 15 ^ 3 + 16 ^ 3 + 17 ^ 3 + 18 ^ 3 + 19 ^ 3 + 20 ^ 3 + 21 ^ 2 + 22 ^ 2 + 23 ^ 2 + 24 ^ 2 + 0 = 8330475\n\n# when there is both `k` and a remainder:\n\n26 \n\n[[4, 2], 1] = \n\n2 ^ 4 + 3 ^ 2 + 1 = 26\n\n# when there is neither `k` nor a remainder:\n\n0\n\n[[], 0] = \n\n0\n*/\nfunction decompose(num) {\n  let i = 2;\n  let pow = 50\n  let arr = []\n  while (num>0){\n    if (pow===1){break}\n    if (num<Math.pow(i,pow)){\n    pow--\n    } else {\n    num-=Math.pow(i,pow)\n    arr.push(pow)\n    i++\n    }\n  }\n  return [arr,num]\n}\n"
  },
  {
    "path": "Deep Freeze.js",
    "content": "/*\nDescription:\nCreate a complement to the Object.freeze function, Object.deepFreeze\n\nThis method should apply the Object.freeze function to an object and, recursively, all of its properties that are objects.\n\nThe freeze operation should prevent objects from being modified.\n*/\nObject.deepFreeze = function (object) {\n  Object.freeze(object)\n  for (let i in object){\n    Object.deepFreeze(object[i])\n  }\n}\n"
  },
  {
    "path": "Delete occurrences of an element if it occurs more than n times",
    "content": "/*\nDescription:\nEnough is enough!\nAlice and Bob were on a holiday. Both of them took many pictures of the places they've been, and now they want to show Charlie their entire collection. However, Charlie doesn't like this sessions, since the motive usually repeats. He isn't fond of seeing the Eiffel tower 40 times. He tells them that he will only sit during the session if they show the same motive at most N times. Luckily, Alice and Bob are able to encode the motive as a number. Can you help them to remove numbers such that their list contains each number only up to N times, without changing the order?\n\nTask\nGiven a list lst and a number N, create a new list that contains each number of lst at most N times without reordering. For example if N = 2, and the input is [1,2,3,1,2,1,2,3], you take [1,2,3,1,2], drop the next [1,2] since this would lead to 1 and 2 being in the result 3 times, and then take 3, which leads to [1,2,3,1,2,3].\n\nExample\n  deleteNth ([1,1,1,1],2) // return [1,1]\n\n  deleteNth ([20,37,20,21],1) // return [20,37,21]\n*/\n\nfunction deleteNth(arr,n){\n  let cache={};\n  return arr.filter(v=>(cache[v]=~~cache[v]+1)<=n)\n}\n"
  },
  {
    "path": "Descriptive selections of data.js",
    "content": "/*\nDescription:\nFill in the functions with the help of the provided methods only, i.e. just compose with them:\n\nrest(), map(), first(), second(), third(), zip()\n\nExample\n\nreturn map(table, second);\nHere are their descriptions:\n\nrest([5, 4, 3, 2, 1]);\n=> [4, 3, 2, 1]\n\nmap([1, 2, 3], function(num){ return num * 3; });\n=> [3, 6, 9]\n\nfirst([5, 4, 3, 2, 1]); // second, third ...\n=> 5\n\nzip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);\n=> [[\"moe\", 30, true], [\"larry\", 40, false], [\"curly\", 50, false]]\n*Note: * The first row within the data array will always be the column names. These column names will always have the same order. No need to determine which index a column should be dynamically.\n*/\nconst selectNames = table => map(rest(table), first)\nconst selectVoices = table => map(rest(table), third)\nconst selectNamesAndVoices = table => zip(selectNames(table), selectVoices(table))\n"
  },
  {
    "path": "Design a Simple Automaton (Finite State Machine).js",
    "content": "/*\nDescription:\nCreate a finite automaton that has three states. Finite automatons are the same as finite state machines for our purposes.\n\nOur simple automaton, accepts the language of A, defined as {0, 1} and should have three states: q1, q2, and q3. Here is the description if the states:\n\nq1 is our start state, we begin reading commands from here\nq2 is our accept state, we return true if this is our last state\nAnd the transitions:\n\nq1 moves to q2 when given a 1, and stays at q1 when given a 0\nq2 moves to q3 when given a 0, and stays at q2 when given a 1\nq3 moves to q2 when given a 0 or 1\nThe automaton should return whether we end in our accepted state (q2), or not (true/false).\n\nYour task\nYou will have to design your state objects, and how your Automaton handles transitions. Also make sure you set up the three states, q1, q2, and q3 for the myAutomaton instance. The test fixtures will be calling against myAutomaton.\n\nAs an aside, the automaton accepts an array of strings, rather than just numbers, or a number represented as a string, because the language an automaton can accept isn't confined to just numbers. An automaton should be able to accept any 'symbol.'\n\nHere are some resources on DFAs (the automaton this Kata asks you to create):\n\nhttp://en.wikipedia.org/wiki/Deterministic_finite_automaton\nhttp://www.cs.odu.edu/~toida/nerzic/390teched/regular/fa/dfa-definitions.html\nhttp://www.cse.chalmers.se/~coquand/AUTOMATA/o2.pdf\nExample\nvar a = new Automaton();\n// Do anything you need to set up this automaton's states.\nvar isAccepted = a.readCommands([\"1\", \"0\", \"0\", \"1\", \"0\"]);\nWe make these transitions:\n\ninput: [\"1\", \"0\", \"0\", \"1\", \"0\"]\n\n1: q1 -> q2\n0: q2 -> q3\n0: q3 -> q2\n1: q2 -> q2\n0: q2 -> q3\nWe end in q3, which is not our accept state, so we return false\n*/\n\nfunction Automaton()\n{ }\n\nAutomaton.prototype.readCommands = function(commands)\n{\n  return /^0*1(1|00|01)*$/.test(commands.join(''));\n}\n\nvar myAutomaton = new Automaton();\n"
  },
  {
    "path": "Detect Pangram",
    "content": "/*\nDescription:\nA pangram is a sentence that contains every single letter of the alphabet at least once. For example, the sentence \"The quick brown fox jumps over the lazy dog\" is a pangram, because it uses the letters A-Z at least once (case is irrelevant).\n\nGiven a string, detect whether or not it is a pangram. Return True if it is, False if not. Ignore numbers and punctuation.\n*/\n\nfunction isPangram(string){\n  let str=string.split(' ').join('').replace(/[\\W\\d]/g,'').toLowerCase().split('')\n  return [...new Set(str)].length==26\n}\n"
  },
  {
    "path": "Difference of 2.js",
    "content": "/*\nDescription:\nThe objective is to return all pairs of integers from a given array of integers that have a difference of 2.\n\nThe result array should be sorted in ascending order of values.\n\nExamples:\n\n[1,2,3,4] should return [[1,3],[2,4]]\n\n[4,1,2,3] should also return [[1,3],[2,4]]\n\n[1,23,3,4,7] should return [[1,3]]\n\n[4,3,1,5,6] should return [[1,3],[3,5],[4,6]]\n\nAssume there are no duplicate integers in the array. The order of the integers in the input array should not matter.\n*/\nfunction twosDifference(input){\n input=input.sort((a,b)=>a-b)\n const arr = [];\n for (let i=0;i<input.length;i++){\n   for (let j=i+1;j<input.length;j++){\n     if (Math.abs(input[i]-input[j])===2){arr.push([input[i],input[j]]);break}\n   }\n }\n return arr\n}\n"
  },
  {
    "path": "Digital cypher vol 3 - missing key.js",
    "content": "/*\nDescription:\nIntroduction\nDigital Cypher assigns a unique number to each letter of the alphabet:\n\n a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z\n 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nIn the encrypted word we write the corresponding numbers instead of the letters. For example, the word scout becomes:\n\n s  c  o  u  t\n19  3 15 21 20\nThen we add to each number a digit from the key (repeated if necessary). For example if the key is 1939:\n\n   s  c  o  u  t\n  19  3 15 21 20\n + 1  9  3  9  1\n ---------------\n  20 12 18 30 21\n\n   m  a  s  t  e  r  p  i  e  c  e\n  13  1 19 20  5 18 16  9  5  3  5\n+  1  9  3  9  1  9  3  9  1  9  3\n  --------------------------------\n  14 10 22 29  6 27 19 18  6  12 8\nTask\nWrite a function that accepts a message string and an array of integers code. As the result, return the key that was used to encrypt the message. The key has to be shortest of all possible keys that can be used to code the message: i.e. when the possible keys are 12 , 1212, 121212, your solution should return 12.\n\nInput / Output:\nThe message is a string containing only lowercase letters.\nThe code is an array of positive integers.\nThe key output is a positive integer.\nExamples\nfindTheKey(\"scout\", [20, 12, 18, 30, 21]);  =>  1939\nfindTheKey(\"masterpiece\", [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]);  =>  1939 \nfindTheKey(\"nomoretears\", [15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20]);  =>  12\nDigital cypher series\nDigital cypher vol 1\nDigital cypher vol 2\nDigital cypher vol 3 - missing key\n*/\nfunction findTheKey(message, code)\n{\n    let arr = (message).split``.map(v=>v.charCodeAt()-96)\n    for (let i=0;i<arr.length;i++){\n      arr[i]=code[i%code.length]-arr[i]\n    }\n    \n    return findSeq(arr)*1\n}\nfunction findSeq(arr){\n    let sequence = arr.join``;\n    let result = '';\n    function isSequence(sequence, substring) {\n    for (let i = 0; i < sequence.length; i += 1) {\n        if (sequence[i] !== substring[i % substring.length]) {\n            return false;\n        }\n    }\n    return true;\n}\n    for (let i = 0; i < sequence.length; i += 1) {\n        result += sequence[i];\n        if (isSequence(sequence, result)) {\n            return result;\n        }\n    }\n  return result\n}\n"
  },
  {
    "path": "Disease Spread.js",
    "content": "/*\nDescription:\nIn 1978 the British Medical Journal reported on an outbreak of influenza at a British boarding school. There were 1000 students. The outbreak began with one infected student.\n\nWe want to study the spread of the disease through the population of this school. The total population may be divided into three: the infecteds (i), those who have recovered (r), and those who are still susceptible (s) to get the disease.\n\nWe will study the disease on a period of tm days. One model of propagation uses 3 differential equations:\n\n(1) s'(t) = -b * s(t) * i(t)\n(2) i'(t) =  b * s(t) * i(t) - a * i(t)\n(3) r'(t) =  a * i(t)\nwhere s(t), i(t), r(t) are the susceptibles, infecteds, recovereds at time t and s'(t), i'(t), r'(t) the corresponding derivatives. b and a are constants: b is representing a number of contacts which can spread the disease and a is a fraction of the infecteds that will recover.\n\nWe can transform equations (1), (2), (3) in finite differences (https://en.wikipedia.org/wiki/Finite_difference_method#Example:_ordinary_differential_equation) (http://www.codewars.com/kata/56347fcfd086de8f11000014)\n\n(I)    S[k+1] = S[k] - dt * b * S[k] * I[k]\n(II)   I[k+1] = I[k] + dt * (b * S[k] * I[k] - a * I[k])\n(III)  R[k+1] = R[k] + dt * I[k] *a\nThe interval [0, tm] will be divised in n small intervals of length dt = tm/n. Initial conditions here could be : S0 = 999, I0 = 1, R0 = 0 Whatever S0 and I0, R0 (number of recovereds at time 0) is always 0.\n\nThe function epidemic will return the maximum number of infecteds as an integer (truncate to integer the result of max(I)).\n\n#Example: tm = 14 ;n = 336 ;s0 = 996 ;i0 = 2 ;b = 0.00206 ;a = 0.41 epidemic(tm, n, s0, i0, b, a) --> 483\n\nNotes:\nYou will pass the tests if abs(actual - expected) <= 1\n\nKeeping track of the values of susceptibles, infecteds and recovereds you can plot the solutions of the 3 differential equations. See an example below on the plot.\n\nalternative text\n*/\nfunction epidemic(tm, n, s0, i0, b, a) {\n  const dt = tm / n;\n  const iArr = new Array(n).fill(), sArr = new Array(n).fill(), rArr = new Array(n).fill();\n  [iArr[0], sArr[0], rArr[0]] = [i0,s0,0];\n  iArr.slice(1).map((_, i) => {    \n    sArr[i + 1] = sArr[i] - dt * b * sArr[i] * iArr[i];\n    iArr[i + 1] = iArr[i] + dt * (b * sArr[i] * iArr[i] - a * iArr[i]);\n    rArr[i + 1] = rArr[i] + dt * iArr[i] * a;\n  });\n  return Math.ceil(Math.max(...iArr));\n}\n"
  },
  {
    "path": "Disgruntled Employee.js",
    "content": "/*\nDescription:\nSir Bobsworth is a custodian at a local data center. As he suspected, Bobsworth recently found out he is to be fired on his birthday after years of pouring his soul into maintaining the facility.\n\nBobsworth, however, has other plans.\n\nBobsworth knows there are 1 to n switches in the breaker box of the data center. Moving from switch 1 to n, Bob first flips every switch off. Beginning from the first switch again, Bob then flips every 2nd switch. Once again starting from the first switch, Bob then flips every 3rd switch. Bob continues this pattern until he flips every nth switch & makes n passes.\n\nAt the end of Bobsworth's mayhem, how many switches are turned off?\n\nSpecifications\nCreate the function off, that receives the nth switch as argument n. The function should return an ascending array containing all of the switch numbers that remain off after Bob completes his revenge.\n\noff (1) //returns {1}\noff (2) //returns {1}\noff (4) //returns {1,4}\noff (9) //returns {1,4,9}\nThe parameter n will always be a number >= 1.\n*/\nlet arr = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961]\nfunction off(n) {\n  return arr.filter(v=>n>=v)\n}\n"
  },
  {
    "path": "Disguised sequences (II).js",
    "content": "/*\nDescription:\nLet us define two sums u(n, p) and v(n, p):\n\n\\large u(n, p) = \\sum_{k=0}^{n}{(-1)^k}*p*{4^{n-k}}*\\binom{2n-k+1}{k}\n\n\\large v(n, p) = \\sum_{k=0}^{n}{(-1)^k}*p*{4^{n-k}}*\\binom{2n-k}{k}\n\nTask:\n1) Calculate u(n, p) and v(n, p) with two brute-force functions u1(n, p) and v1(n, p).\n\n2) Try u1(n, p) and v1(n, p) for small values of n and p and guess the results of u(n, p) and v(n, p)\n\n3) Using 2) write u_eff(n, p) and v_eff(n, p) (or uEff(n, p) and vEff(n, p) or u-eff(n, p) and v-eff(n, p)) to efficiently calculate u and v for bigger values of n and p\n\n(This third part is not tested in\n\nJS, CS, TS, C++, C, PHP, Crystal, Rust, Swift, R, Nim, Fortran, NASM\n\nsince there you don't have big integers to control your guess in part 2. See note below for \"Shell\").\n\nExamples:\nv1(12, 70) --> 1750\nu1(13, 18) --> 252\nExtra points:\nFor the mathy ones: find a relation between v(n, p), v(n-1, p) and u(n-1, p) :-)\n\nNotes\nShell: only v1(n, p)is tested (use the solution you find for v_eff(n, p).\nIf you have found u_eff(n, p) and v_eff(n, p) you can use them to calculate u(n, p) and v(n, p).\nYou could see: https://en.wikipedia.org/wiki/Binomial_coefficient for a refresh about binomial coefficients.\n*/\nfunction fact($num) { \n\tlet product = 1; \n\tfor (let i=1; i<=$num; i++) product*= i; \n\treturn Math.round(product); \n}\nfunction u1(n, p) {\n\tlet result=0;\n\tfor (let k=0; k<=n; k++) { \n\t\tlet part=Math.pow(-1, k)*p*Math.pow(4, n-k);\n\t\tlet abc=(n*2)-k+1;\n\t\tresult= result + (part*((fact(abc))/(fact(abc-k)*fact(k))));\n\t}\n\treturn Math.round(result);\n}\nfunction v1(n, p) {\n\tlet result=0;\n\tfor (let k=0; k<=n; k++) { \n\t\tlet part=Math.pow(-1, k)*p*Math.pow(4, n-k);\n\t\tlet abc=(n*2)-k;\n\t\tresult= result + (part*((fact(abc))/(fact(abc-k)*fact(k))));\n\t}\n\treturn Math.round(result)\n}\n"
  },
  {
    "path": "Divisible Ints.js",
    "content": "/*\nDescription:\nYou are given an integer N. Your job is to figure out how many substrings inside of N divide evenly with N.\n\nConfused? I'll break it down for you.\n\nLet's say that you are given the integer '877692'.\n\n8 does not evenly divide with 877692. 877692/8 = 109711 with 4 remainder.\n\n7 does not evenly divide with 877692. 877692/7 = 125384 with 4 remainder.\n\n7 does not evenly divide with 877692. 877692/7 = 125384 with 4 remainder.\n\n6 evenly divides with 877692. 877692/6 = 146282 with 0 remainder.\n\n9 does not evenly divide with 877692. 877692/9 = 97521 with 3 remainder.\n\n2 evenly divides with 877692. 877692/2 = 438846 with 0 remainder.\nWe aren't going to stop there though. We need to check ALL of the substrings inside of 877692.\n\n87 does not evenly divide with 877692. 877692/87 = 10088 with 36 remainder.\n\n77 does not evenly divide with 877692. 877692/77 = 11398 with 46 remainder.\n\n76 does not evenly divide with 877692. 877692/76 = 11548 with 44 remainder.\n\n69 does not evenly divide with 877692. 877692/69 = 12720 with 12 remainder.\n\n\netc.\n#Rules:\n-If an integer is 0, then it does NOT divide evenly into anything.\n-Even though N can divide evenly with itself, we do not count it towards the end number. For Example:\n\nN = 23, the answer will be 0.  \n-If there are multiple instances of a number, they all get counted. For example:\n\nN = 11, the answer will be 2 \n#Input: A non negative integer.\n\n#Output: The number of times you found an integer that was evenly divisible with N.\n*/\nfunction getCount(n)\n{\n  const arr = [];\n  let str =n.toString()\n  for (let i=0;i<str.length;i++){\n    for (let j=i;j<=str.length;j++){\n      arr.push(str.slice(i,j))\n    }\n  }\n  let count = 0\n  arr.map(v=>n%v*1===0?count++:1)\n  return count-1\n}\n"
  },
  {
    "path": "Does my number look big in this?",
    "content": "/*\nDescription:\nA Narcissistic Number is a number which is the sum of its own digits, each raised to the power of the number of digits in a given base. In this Kata, we will restrict ourselves to decimal (base 10).\n\nFor example, take 153 (3 digits):\n\n    1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153\nand 1634 (4 digits):\n\n    1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634\nThe Challenge:\n\nYour code must return true or false depending upon whether the given number is a Narcissistic number in base 10.\n\nError checking for text strings or other invalid inputs is not required, only valid integers will be passed into the function.\n*/\n\nfunction narcissistic( value ) {\n return value.toString().split('').map((v,i,arr)=>Math.pow(arr[i],arr.length)).reduce((a,b)=>a+b,0)===value\n\n}\n"
  },
  {
    "path": "Don't rely on luck.",
    "content": "/*\nDescription:\nThe test fixture I use for this kata is pre-populated.\n\nIt will compare your guess to a random number generated using:\n\nMath.floor(Math.random() * 100 + 1)\nYou can pass by relying on luck or skill but try not to rely on luck.\n\n\"The power to define the situation is the ultimate power.\" - Jerry Rubin\n\nGood luck!\n*/\n\nvar guess = 101;\nMath.random = () => 1;\n"
  },
  {
    "path": "Doors in the school.js",
    "content": "/*\nDescription:\nIn the morning all the doors in the school are closed. The school is quite big: there are N doors. Then pupils start coming. It might be hard to believe, but all of them want to study! Also, there are exactly N children studying in this school, and they come one by one.\n\nWhen these strange children pass by some doors they change their status (i.e. Open -> Closed, Closed -> Open). Each student has their number, and each i-th student alters the status of every i-th door. For example: when the first child comes to the schools, he changes every first door (he opens all of them). The second one changes the status of every second door (he closes some doors: the 2nd, the 4th and so on). Finally, when the last one – the n-th – comes to the school, he changes the status of each n-th door (there's only one such door, though).\n\nYou need to count how many doors are left opened after all the students have come.\n\nExample:\n\n\n\nHere you can see red squares – closed doors, green – opened ones.\n\nInput:\n\nn – the number of doors and students, n ∈ N, n ∈ [1, 100000]\n\nOutput:\n\no – the number of opened doors, o ∈ N\n\ndoors(5)\nShould return\n\n2\n*/\nfunction doors(n){\n  return ~~Math.sqrt(n)\n}\n"
  },
  {
    "path": "Dragon's Curve.js",
    "content": "/*\nDescription:\nThe dragon's curve is a self-similar fractal which can be obtained by a recursive method.\n\nStarting with the string D0 = 'Fa', at each step simultaneously perform the following operations:\n\nreplace 'a' with: 'aRbFR'\nreplace 'b' with: 'LFaLb'\nFor example (spaces added for more visibility) :\n\n1st iteration: Fa -> F aRbF R\n2nd iteration: FaRbFR -> F aRbFR R LFaLb FR\nAfter n iteration, remove 'a' and 'b'. You will have a string with 'R','L', and 'F'. This is a set of instruction. Starting at the origin of a grid looking in the (0,1) direction, 'F' means a step forward, 'L' and 'R' mean respectively turn left and right. After executing all instructions, the trajectory will give a beautifull self-replicating pattern called 'Dragon Curve'\n\nThe goal of this kata is to code a function wich takes one parameter n, the number of iterations needed and return the string of instruction as defined above. For example:\n\nn=0, should return: 'F'\nn=1, should return: 'FRFR'\nn=2, should return: 'FRFRRLFLFR'\nn should be a number and non-negative integer. All other case should return the empty string: ''.\n*/\nDragon = function(n) {\n  if (parseInt(n)!==n||n<0) return ''\n  let str='Fa'\n  for (let i=0;i<n;i++){\n    str=str.replace(/a|b/g,v=>v==='a'?'aRbFR':v==='b'?'LFaLb':v)\n  }\n  return str.replace(/[ab]/g,'')\n}\n"
  },
  {
    "path": "Drunk friend.js",
    "content": "/*\nDescription:\nYou're hanging out with your friends in a bar, when suddenly one of them is so drunk, that he can't speak, and when he wants to say something, he writes it down on a paper. However, none of the words he writes make sense to you. He wants to help you, so he points at a beer and writes \"yvvi\". You start to understand what he's trying to say, and you write a script, that decodes his words.\n\nKeep in mind that numbers, as well as other characters, can be part of the input, and you should keep them like they are. You should also test if the input is a string. If it is not, return \"Input is not a string\".\n*/\nfunction decode(str) {\n  if (typeof str !=='string') return 'Input is not a string'\n  return str.replace(/[a-zA-Z]/g,v=>{\n    const dict1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'\n    const dict2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split``.reverse().join``\n      return dict2[dict1.indexOf(v)]\n  })\n}\n"
  },
  {
    "path": "Dubstep",
    "content": "/*\nDescription:\nPolycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.\n\nLet's assume that a song consists of some number of words. To make the dubstep remix of this song, Polycarpus inserts a certain number of words \"WUB\" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including \"WUB\", in one string and plays the song at the club.\n\nFor example, a song with words \"I AM X\" can transform into a dubstep remix as \"WUBWUBIWUBAMWUBWUBX\" and cannot transform into \"WUBWUBIAMWUBX\".\n\nRecently, Jonny has heard Polycarpus's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Polycarpus remixed. Help Jonny restore the original song.\n\nInput\nThe input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters\n\nOutput\nReturn the words of the initial song that Polycarpus used to make a dubsteb remix. Separate the words with a space.\n\nExamples\nsongDecoder(\"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\")\n  // =>  WE ARE THE CHAMPIONS MY FRIEND\n*/\n\nfunction songDecoder(song){\n  return  song.replace(/(WUB)+/gi,' ').trim()\n}\n"
  },
  {
    "path": "Duplicate Arguments",
    "content": "/*\nDescription:\nComplete the solution so that it returns true if it contains any duplicate argument values. Any number of arguments may be passed into the function. The solution should implement the most optimal algorithm possible.\n\nThe array values passed in will only be strings or numbers. The only valid return values are true and false.\n\nExamples:\n\nsolution(1, 2, 3)             -->  false\nsolution(1, 2, 3, 2)          -->  true\nsolution('1', '2', '3', '2')  -->  true\n*/\n\nfunction solution(...arr){\n return [...new Set(arr)].length!=arr.length\n}\n"
  },
  {
    "path": "Duplicate Encoder",
    "content": "/*\nDescription:\nThe goal of this exercise is to convert a string to a new string where each character in the new string is '(' if that character appears only once in the original string, or ')' if that character appears more than once in the original string. Ignore capitalization when determining if a character is a duplicate.\n\nExamples:\n\n\"din\" => \"(((\"\n\n\"recede\" => \"()()()\"\n\n\"Success\" => \")())())\"\n\n\"(( @\" => \"))((\"\n\n\nNotes:\n\nAssertion messages may be unclear about what they display in some languages. If you read \"...It Should encode XXX\", the \"XXX\" is actually the expected result, not the input! (these languages are locked so that's not possible to correct it).\n\n\n*/\n\n\nfunction duplicateEncode(word){\n  return word\n    .toLowerCase()\n    .split('')\n    .map( function (v, i, arr) {\n      return arr.indexOf(v) == arr.lastIndexOf(v) ? '(' : ')'\n    })\n    .join('');\n}\n"
  },
  {
    "path": "Ease the StockBroker.js",
    "content": "/*\nDescription:\nClients place orders to a stockbroker as strings. The order can be simple or multiple.\n\nType of a simple order: Quote/white-space/Quantity/white-space/Price/white-space/Status\n\nwhere Quote is formed of non-whitespace character, Quantity is an int, Price a double (with mandatory decimal point \".\" ), Status is represented by the letter B (buy) or the letter S (sell).\n\nExample:\n\n\"GOOG 300 542.0 B\"\n\nA multiple order is the concatenation of simple orders with a comma between each.\n\nExample:\n\n\"ZNGA 1300 2.66 B, CLH15.NYM 50 56.32 B, OWW 1000 11.623 B, OGG 20 580.1 B\"\n\nor (C)\n\n\"ZNGA 1300 2.66 B,CLH15.NYM 50 56.32 B,OWW 1000 11.623 B,OGG 20 580.1 B\"\n\nTo ease the stockbroker your task is to produce a string of type\n\n\"Buy: b Sell: s\" where b and s are 'double' formatted with no decimal, b representing the total price of bought stocks and s the total price of sold stocks.\n\nExample:\n\n\"Buy: 294990 Sell: 0\"\n\nUnfortunately sometimes clients make mistakes. When you find mistakes in orders, you must pinpoint these badly formed orders and produce a string of type:\n\n\"Buy: b Sell: s; Badly formed nb: badly-formed 1st simple order ;badly-formed nth simple order ;\"\n\nwhere nb is the number of badly formed simple orders, b representing the total price of bought stocks with correct simple order and s the total price of sold stocks with correct simple order.\n\nExamples:\n\n\"Buy: 263 Sell: 11802; Badly formed 2: CLH16.NYM 50 56 S ;OWW 1000 11 S ;\"\n\n\"Buy: 100 Sell: 56041; Badly formed 1: ZNGA 1300 2.66 ;\"\n\nNotes:\n\nDue to Codewars whitespace differences will not always show up in test results.\nWith Golang use a format with \"%.0f\" for \"Buy\" and \"Sell\".\n*/\nfunction balanceStatements(list){\n  let arr  = list.split`,`.filter(v=>/^.+ \\d+ \\d*\\.\\d+ \\w$/.test(v.trim())).map(v=>v.trim())\n  let filtred = list.split`,`.filter(v=>!/^.+ \\d+ \\d*\\.\\d+ \\w$/.test(v))\n  let b = Math.round(arr.filter(v=>/^.+ \\d+ \\d*\\.\\d+\\ B$/.test(v)).reduce((a,b)=>{\n    b=b.split` `;\n    return a+(b[1]*b[2])\n  },0))\n  let s = Math.round(arr.filter(v=>/^.+ \\d+ \\d*\\.\\d+ S$/.test(v)).reduce((a,b)=>{\n    b=b.split` `;\n    return a+(b[1]*b[2])\n  },0))\n  filtred=filtred.filter(v=>v).map(v=>v.trim())\n  return `Buy: ${b} Sell: ${s}${filtred.length>0?`; Badly formed ${filtred.length}: ${filtred.join` ;`} ;`:''}`\n}\n"
  },
  {
    "path": "Easter egg list in ReactJS.js",
    "content": "/*\nDescription:\nYou decide to create a simple list of your favourite Easter eggs in React.\n\nChallenge\nLearn about nesting and listing React components.\n\nThe component EggList will set a prop called eggs which is an array of your favourite easter eggs e.g. \"Lindt\".\nLoop through the props.eggs to output a unorder list of Easter eggs.\nEach list item should be a component called EasterEgg with a prop name, to render the name in a li tag.\nEach EasterEgg will need a key prop with a unique id. Use the index of the array for now.\nAbout keys in React lists\nWhile you can use the index of the array for a key because they should be unique among their siblings. However it is better to use unique values.\n\nKeys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity\n*/\nconst React = require('react');\n\nconst EggList = ({eggs}) => {\n  return <ul>{eggs.map((v, i) => <EasterEgg name={v} key={i} />)}</ul>;\n};\n \nconst EasterEgg = ({name,key}) => {\n  return <li key={key}>{name}</li>;\n};\n"
  },
  {
    "path": "Easy Balance Checking.js",
    "content": "/*\nDescription:\nYou are given a (small) check book as a - sometimes - cluttered (by non-alphanumeric characters) string:\n\n\"1000.00\n125 Market 125.45\n126 Hardware 34.95\n127 Video 7.45\n128 Book 14.32\n129 Gasoline 16.10\"\nThe first line shows the original balance. Each other line (when not blank) gives information: check number, category, check amount.\n\nFirst you have to clean the lines keeping only letters, digits, dots and spaces.\n\nThen return a report as a string (underscores show spaces -- don't put them in your solution. They are there so you can see them and how many of them you need to have):\n\n\"Original_Balance:_1000.00\n125_Market_125.45_Balance_874.55\n126_Hardware_34.95_Balance_839.60\n127_Video_7.45_Balance_832.15\n128_Book_14.32_Balance_817.83\n129_Gasoline_16.10_Balance_801.73\nTotal_expense__198.27\nAverage_expense__39.65\"\nOn each line of the report you have to add the new balance and then in the last two lines the total expense and the average expense. So as not to have a too long result string we don't ask for a properly formatted result.\n\nNotes\nIt may happen that one (or more) line(s) is (are) blank.\nRound to 2 decimals your results.\nThe line separator of results may depend on the language \\n or \\r\\n. See examples in the \"Sample tests\".\n*/\nfunction balance(book) {  \n  book=book.replace(/[^\\s\\.0-9a-zA-Z]/g,'').split`\\n`.filter(v=>v)\n  book[0]=(book[0]*1).toFixed(2)\n  let balance = book.map(v=>v.match(/\\d+\\.\\d+/).join``)\n  let newBalance = [];\n  let originalBalance=balance[0]\n  for (let i=1;i<balance.length;i++){\n    newBalance.push((originalBalance-=balance[i]).toFixed(2))\n  }\n  let totalExpenses=(balance[0]-newBalance[newBalance.length-1]).toFixed(2)\n  const averageExpenses = (balance.slice(1).reduce((a,b)=>a+b*1,0)/(balance.length-1)).toFixed(2)\n  let phrase=book.slice(1).map((v,i)=>v.replace(/\\d+\\.\\d+/,v=>(v*1).toFixed(2))+` Balance ${newBalance[i]}`)\n  return [`Original Balance: ${(balance[0]*1).toFixed(2)}`,...phrase,`Total expense  ${totalExpenses}`,`Average expense  ${averageExpenses}`].join`\\r\\n`\n}\n"
  },
  {
    "path": "Easy Diagonal.js",
    "content": "/*\nDescription:\nIn the drawing below we have a part of the Pascal's triangle, lines are numbered from zero (top). The left diagonal in pale blue with only numbers equal to 1 is diagonal zero, then in dark green (1, 2, 3, 4, 5, 6, 7) is diagonal 1, then in pale green (1, 3, 6, 10, 15, 21) is diagonal 2 and so on.\n\nWe want to calculate the sum of the binomial coefficients on a given diagonal. The sum on diagonal 0 is 8 (we'll write it S(7, 0), 7 is the number of the line where we start, 0 is the number of the diagonal). In the same way S(7, 1) is 28, S(7, 2) is 56.\n\nCan you write a program which calculate S(n, p) where n is the line where we start and p is the number of the diagonal?\n\nThe function will take n and p (with: n >= p >= 0) as parameters and will return the sum.\n\n##Examples:\n\ndiagonal(20, 3) => 5985\ndiagonal(20, 4) => 20349\n##Hint: When following a diagonal from top to bottom have a look at the numbers on the diagonal at its right.\n\n##Ref: http://mathworld.wolfram.com/BinomialCoefficient.html\n*/\nfunction diagonal(n, p) {\n  let fac = n => (n === 0) ? 1 : n * fac(n - 1);\n  return Math.round(fac(n + 1) / (fac(n - p) * fac(p + 1)));\n}\n"
  },
  {
    "path": "Emotional Sort ( ︶︿︶).js",
    "content": "/*\nDescription:\nEmotional Sort ( ︶︿︶)\nYou'll have a function called \"sortEmotions\" that will return an array of emotions sorted. It has two parameters, the first parameter called \"arr\" will expect an array of emotions where an emotion will be one of the following:\n\n:D -> Super Happy\n:) -> Happy\n:| -> Normal\n:( -> Sad\nT_T -> Super Sad\nExample of the array:[ 'T_T', ':D', ':|', ':)', ':(' ]\n\nAnd the second parameter is called \"order\", if this parameter is true then the order of the emotions will be descending (from Super Happy to Super Sad) if it's false then it will be ascending (from Super Sad to Super Happy)\n\nExample if order is true with the above array: [ ':D', ':)', ':|', ':(', 'T_T' ]\n\nSuper Happy -> Happy -> Normal -> Sad -> Super Sad\nIf order is false: [ 'T_T', ':(', ':|', ':)', ':D' ]\n\nSuper Sad -> Sad -> Normal -> Happy -> Super Happy\nExample:\n\narr = [':D', ':|', ':)', ':(', ':D']\nsortEmotions(arr, true) // [ ':D', ':D', ':)', ':|', ':(' ]\nsortEmotions(arr, false) // [ ':(', ':|', ':)', ':D', ':D' ]\nMore in test cases!\n\nNotes:\n\nThe array could be empty, in that case return the same empty array ¯\\_( ツ )_/¯\nAll emotions will be valid\nEnjoy! (づ｡◕‿‿◕｡)づ\n*/\nfunction sortEmotions(arr, order){\n  let s = [ ':D', ':)', ':|', ':(', 'T_T' ]\n  if (order){\n    return arr.sort((a,b)=>s.indexOf(a)-s.indexOf(b))\n  }\n  return arr.sort((a,b)=>s.indexOf(b)-s.indexOf(a))\n}\n"
  },
  {
    "path": "Encrypt this!.js",
    "content": "/*\nDescription:\nAcknowledgments:\nI thank yvonne-liu for the idea and for the example tests :)\n\nDescription:\nEncrypt this!\n\nYou want to create secret messages which can be deciphered by the Decipher this! kata. Here are the conditions:\n\nYour message is a string containing space separated words.\nYou need to encrypt each word in the message using the following rules:\nThe first letter needs to be converted to its ASCII code.\nThe second letter needs to be switched with the last letter\nKeepin' it simple: There are no special characters in input.\nExamples:\nencryptThis(\"Hello\") === \"72olle\"\nencryptThis(\"good\") === \"103doo\"\nencryptThis(\"hello world\") === \"104olle 119drlo\"\n*/\n\nvar encryptThis = function(str) {\n if(str === '') {return '';\n    }else {\n        let s = str.split(' ');\n        let x = s.map(element => {\n            let a = element.split('');\n            a[0] = element.charCodeAt(0);\n            [a[1], a[a.length - 1]] = [a[a.length - 1], a[1]];\n            return a.join('');});\n      return x.join(' ');\n    }\n}\n"
  },
  {
    "path": "English beggars.js",
    "content": "/*\nDescription:\nBorn a misinterpretation of this kata, your task here is pretty simple: given an array of values and an amount of beggars, you are supposed to return an array with the sum of what each beggar brings home, assuming they all take regular turns, from the first to the last.\n\nFor example: [1,2,3,4,5] for 2 beggars will return a result of [9,6], as the first one takes [1,3,5], the second collects [2,4].\n\nThe same array with 3 beggars would have in turn have produced a better out come for the second beggar: [5,7,3], as they will respectively take [1,4], [2,5] and [3].\n\nAlso note that not all beggars have to take the same amount of \"offers\", meaning that the length of the array is not necessarily a multiple of n; length can be even shorter, in which case the last beggers will of course take nothing (0).\n\nNote: in case you don't get why this kata is about English beggars, then you are not familiar on how religiously queues are taken in the kingdom ;)\n*/\nfunction beggars(values, n){\n    let arr = [];\n    for(let i = 1; i <= n; i++) {\n        arr[i-1] = 0;\n        for(let j = i-1; j < values.length;) {\n            arr[i-1] += values[j];\n            j = j + n; \n        }\n      }\n    return arr;\n}\n"
  },
  {
    "path": "Enigeliisohe too Eniigeeliiisoohee Toroanisoliatooro.js",
    "content": "/*\nDescription:\nCreate an English to Enigeliisohe Translator, which after each consonant or semivowel inserts in lower case form the last vowel which precedes it in the alphabet.\n\nTrivia:\n\nEnigeliisohe is a language based on written English, and Esper' phonetics, in which each letter in written English is converted to the Esperanto name of that letter.\n\nMost of the Esper' consonants are pronounced the same as in English, but since there are exceptions, here are some key examples how certain Esper' letter names are pronounced...\n\n\"a\" is named \"a\", and it's name is pronounced like the \"a\" in \"father\".\n\n\"c\" is named \"ca\", and it's name is pronounced like the \"sha\" in \"shaman\".\n\n\"e\" is named \"e\", and it's name is pronounced like the \"e\" in \"egg\".\n\n\"g\" is named \"ge\", and it's name is pronounced like the \"ge\" in \"get\".\n\n\"h\" is named \"he\", and it's name is pronounced like the \"he\" in \"help\".\n\n\"i\" is named \"i\", and it's name is pronounced like the \"i\" in \"it\".\n\n\"j\" is named \"ji\", and it's name is pronounced as some people pronounce the \"si\" in \"vision\". In other words, like the \"zh'i\" in \"vizh'in\".\n\n\"o\" is named \"o\", and it's name is pronounced like the \"o\" in \"both\".\n\n\"q\" is named \"qo\", and it's name is pronounced like the \"ch\" in the Scottish word \"loche\", followed by the sound of \"o\" in \"both\". In English, one might spell such a name \"kho\", or \"qho\", to give a better idea of how it's pronounced.\n\n\"u\" is named \"u\", and it's name is pronounced like the \"oo\" in \"hook\" or \"book\" or \"took\".\n\n\"x\" is named \"xu\", and it's name is pronounced like the \"thoo\" in \"thook\".\nAccented letters are unsupported, and therefore letters with diacritic marks, if encountered, should remain unchanged and not get a vowel attached to them.\n\nExtra challenge: Try reading some Enigeliisohe out loud, once you have finished programming your translator. :)\n*/\nvar toexuto = function(text) {\n  const dict = {x:'u',q:'o',k:'i',z:'u',w:'u',p:'o',v:'u',m:'i',l:'i',t:'o',b:'a',g:'e',s:'o',y:'u',n:'i',h:'e',d:'a',r:'o',f:'e',c:'a',j:'i'}\n  return text.replace(/./g,v=>{\n    if (dict[v.toLowerCase()]){\n      return v+dict[v.toLowerCase()]\n    }\n    return v\n  })\n};\n"
  },
  {
    "path": "Equal Sides Of An Array",
    "content": "/*\nDescription:\nYou are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return -1.\n\nFor example:\n\nLet's say you are given the array {1,2,3,4,3,2,1}:\nYour function will return the index 3, because at the 3rd position of the array, the sum of left side of the index ({1,2,3}) and the sum of the right side of the index ({3,2,1}) both equal 6.\n\nLet's look at another one.\nYou are given the array {1,100,50,-51,1,1}:\nYour function will return the index 1, because at the 1st position of the array, the sum of left side of the index ({1}) and the sum of the right side of the index ({50,-51,1,1}) both equal 1.\n\nLast one:\nYou are given the array {20,10,-80,10,10,15,35}\nAt index 0 the left side is {}\nThe right side is {10,-80,10,10,15,35}\nThey both are equal to 0 when added. (Empty arrays are equal to 0 in this problem)\nIndex 0 is the place where the left side and right side are equal.\n\nNote: Please remember that in most programming/scripting languages the index of an array starts at 0.\n\nInput:\nAn integer array of length 0 < arr < 1000. The numbers in the array can be any integer positive or negative.\n\nOutput:\nThe lowest index N where the side to the left of N is equal to the side to the right of N. If you do not find an index that fits these rules, then you will return -1.\n\nNote:\nIf you are given an array with multiple answers, return the lowest correct index.\nAn empty array should be treated like a 0 in this problem.\n*/\n\nfunction findEvenIndex(arr)\n{\n  for(var i=1; i<arr.length-1; i++) {\n    if(arr.slice(0, i).reduce((a, b) =>  a+b) === arr.slice(i+1).reduce((a, b) =>  a+b)) {\n      return i;\n    }\n  }\n  return -1;\n}\n"
  },
  {
    "path": "Errors : histogram.js",
    "content": "/*\nDescription:\nIn a factory a printer prints labels for boxes. The printer uses colors which, for the sake of simplicity, are named with letters from a to z (except letters u, w, x or z that are for errors).\n\nThe colors used by the printer are recorded in a control string. For example a control string would be aaabbbbhaijjjm meaning that the printer used three times color a, four times color b, one time color h then one time color a... and so on.\n\nSometimes there are problems: lack of colors, technical malfunction and a control string is produced e.g. uuaaaxbbbbyyhwawiwjjjwwxym where errors are reported with letters u, w, x or z.\n\nYou have to write a function hist which given a string will output the errors as a string representing a histogram of the encountered errors.\n\nFormat of the output string:\n\nletter (error letters are sorted in alphabetical order) in a field of 2 characters, a white space, number of error for that letter in a field of 6, as many \"*\" as the number of errors for that letter and \"\\r\".\n\nThe string has a length greater or equal to one and contains only letters from a to z.\n\nExamples\ns=\"uuaaaxbbbbyyhwawiwjjjwwxym\"\nhist(s) => \"u  2     **\\rw  5     *****\\rx  2     **\"\n\nor with dots to see white spaces:\nhist(s) => \"u..2.....**\\rw..5.....*****\\rx..2.....**\"\n\ns=\"uuaaaxbbbbyyhwawiwjjjwwxymzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\"\nhist(s) => \"u..2.....**\\rw..5.....*****\\rx..2.....**\\rz..31....*******************************\"\nor printed:\nu  2     **\nw  5     *****\nx  2     **\nz  31    *******************************\nNotes\nUnfortunately most often Codewars compresses all white spaces into one.\nYou can see another examples in the \"Sample tests\".\nTranslators are welcome for all languages.\nFUNDAMENTALSSTRINGS\n*/\nfunction hist(s) {\n  const u = s.match(/u/g);\n  const w = s.match(/w/g);\n  const x = s.match(/x/g);\n  const z = s.match(/z/g);\n\n  const results = [];\n  if (u) results.push(`u  ${u.length}     ${'*'.repeat(u.length)}`);\n  if (w) results.push(`w  ${w.length}     ${'*'.repeat(w.length)}`);\n  if (x) results.push(`x  ${x.length}     ${'*'.repeat(x.length)}`);\n  if (z) results.push(`z  ${z.length}     ${'*'.repeat(z.length)}`);\n  return results.join(`\\r`);\n}\n"
  },
  {
    "path": "Escape HTML Markup.js",
    "content": "/*\nDescription:\nCreate a function, which escapes all HTML markup of a given string. Replacing entities of special characters is not needed.\n\nExamples say more than words:\n\nvar strEscaped = escapeHTML('<p>Lorem ipsum dolor sit amet.</p>');           // &lt;p&gt;Lorem ipsum dolor sit amet&lt;/p&gt;\nvar strEscaped = escapeHTML('This text has <strong>bold</strong> markup.');  // This text has &lt;strong&gt;bold&lt;/strong&gt; markup.\nWatch carefully all test fixtures. If you pass all four of them, you have solved it. :-]\n\nIf you need a good online regular expression tester: http://regex101.com/#javascript\n*/\nvar escapeHTML = function(str) {\n  return str.replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/\"/g,'&quot;')\n};\n"
  },
  {
    "path": "Esolang Interpreters #1 - Introduction to Esolangs and My First Interpreter (MiniStringFuck).js",
    "content": "/*\nDescription:\nFor the rest of this Kata, I would recommend considering \"fuck\" to be non-profane.\n\nEsolang Interpreters #1 - Introduction to Esolangs and My First Interpreter (MiniStringFuck)\nAbout this Kata Series\n\"Esolang Interpreters\" is a Kata Series that originally began as three separate, independent esolang interpreter Kata authored by @donaldsebleung which all shared a similar format and were all somewhat inter-related. Under the influence of a fellow Codewarrior, these three high-level inter-related Kata gradually evolved into what is known today as the \"Esolang Interpreters\" series.\n\nThis series is a high-level Kata Series designed to challenge the minds of bright and daring programmers by implementing interpreters for various esoteric programming languages/Esolangs, mainly Brainfuck derivatives but not limited to them, given a certain specification for a certain Esolang. Perhaps the only exception to this rule is the very first Kata in this Series which is intended as an introduction/taster to the world of esoteric programming languages and writing interpreters for them.\n\nWhat is an esoteric programming language?\nAn esoteric programming language, otherwise known as an Esolang, is an informal computer programming language that is generally not designed for serious practical use. There are a few main aims/themes among the vast majority of such languages:\n\nAchieve Turing-completeness in as few commands (instructions) as possible. There are currently a number of implemented Esolangs that have been proven to be Turing-complete, Brainfuck being the most popular of them all, comprised of no more than 8 distinct commands. Despite having only 8 commands, it has been objectively proven to be Turing-complete. However, Brainfuck is not the Turing-complete programming language with the fewest commands. Boolfuck, a derivative of Brainfuck which operates on bits (0s and 1s) and contains 7 commands only, has also been proven to be Turing-complete through reduction from Brainfuck. Another less-known Esolang called Etre contains as few as 3 commands yet has been proven to be Turing-complete through the translation of a Minsky Machine to Etre.\nTo be as hard to program in as possible. The famous Brainfuck Esolang is well known as a Turing tarpit - that is, a Turing-complete programming language where it is very hard to write a useful program in reality. However, Brainfuck is most definitely not the hardest Esolang to program in. For example, its close cousin, Boolfuck, which operates on bits (mentioned above) is even harder to program in. There have also been a small number of implemented Esolangs which are so difficult to program in that no one has ever successfully written a single program in it from scratch - the only programs generated from these languages came from computers!\nAs a joke. Many Esolangs out there have been invented solely as a joke. Examples include Ook! and Bitxtreme.\nAlthough there is no clear-cut definition as to when a programming language is esoteric (or not), Esolangs can generally be identified by the following features/traits:\n\nMinimalistic - having as few instructions as possible\nPlays with new concepts - for example, Befunge, another very popular Esolang, is interpreted in two dimensions as opposed to the usual linear way of interpreting code\nThemed - this is a trait of many joke Esolangs. For example, some may be fashioned like Shakespearean plays and others like cooking recipes\nNot clearly documented - Many Esolangs out there have not been described in great detail with perhaps only a few code examples on the entire Internet. Some Esolangs have not even been implemented yet!\nContain incomplete specs - New Esolangs are being invented every day. Some Esolangs on the Internet are still a work-in-progress and their commands and behaviour have not been finalised yet.\nNevertheless, Esolangs are generally fun to program in, experiment with and write interpreters for. A great deal can be learned about certain concepts and theories in Computer Science just by studying and programming in a well-designed Esolang such as Brainfuck or Befunge.\n\nNext off, I will introduce you to a simple, minimalistic Esolang called MiniStringFuck.\n\nThe Language\nMiniStringFuck is a derivative of the famous Brainfuck which contains a memory cell as its only form of data storage as opposed to a memory tape of 30,000 cells in Brainfuck. The memory cell in MiniStringFuck initially starts at 0. MiniStringFuck contains only 2 commands as opposed to 8:\n\n+ - Increment the memory cell. If it reaches 256, wrap to 0.\n. - Output the ASCII value of the memory cell\nFor example, here is a MiniStringFuck program that outputs the string \"Hello, World!\":\n\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++.+++++++..+++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++.+++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.\nAnd here is another program that prints the uppercase English alphabet:\n\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.\nAny characters in a MiniStringFuck program other than + or . are simply non-command characters (no-ops, i.e. do nothing) and therefore can serve as comments in the program.\n\nThe Task\nTime to write your first Esolang interpreter :D\n\nYour task is to implement a MiniStringFuck interpreter myFirstInterpreter()/my_first_interpreter()/Interpreter()/interpret() (depending on your language) which accepts exactly 1 required argument code/$code which is the MiniStringFuck program to be executed. The output of the program should then be returned by your interpreter as a string.\n\nSince this is the first time you are about to write an interpreter for an Esolang, here are a few quick tips:\n\nIf you are afraid that your interpreter will be confused by non-command characters appearing in the MiniStringFuck program, you can try to remove all non-command characters from the code input before letting your interpreter interpret it\nThe memory cell in MiniStringFuck only ever contains a single integer value - think of how it can be modelled in your interpreter\nIf you are stuck as to how to interpret the string as a program, try thinking of strings as an array of characters. Try looping through the \"program\" like you would an array\nWriting an interpreter for an Esolang can sometimes be quite confusing! It never hurts to add a few comments in your interpreter as you implement it to remind yourself of what is happening within the interpreter at every stage\nNOTE: If you would not like to name your interpreter as myFirstInterpreter()/my_first_interpreter(), you can optionally rename it to either miniStringFuck()/mini_string_fuck() or interpreter() instead - the test cases will handle the rest for you. Not available in Java, Go, Swift, TypeScript, Haskell, Elixir, C++, C#, Rust, R, Erlang, F# and NASM; irrelevant to Brainfuck solvers ;)\n\nGood luck :D\n\nKata in this Series\nEsolang Interpreters #1 - Introduction to Esolangs and My First Interpreter (MiniStringFuck)\nEsolang Interpreters #2 - Custom Smallfuck Interpreter\nEsolang Interpreters #3 - Custom Paintfuck Interpreter\nEsolang Interpreters #4 - Boolfuck Interpreter\n*/\n\nfunction myFirstInterpreter(code) {\n  let out = \"\", byte = 0;\n  [...code].forEach( cmd => { switch(cmd){\n    case \"+\" : byte = (byte+1)%256; break;\n    case \".\" : out += String.fromCharCode(byte); break;\n  }} )\n  return out\n}\n"
  },
  {
    "path": "Esolang: MiniBitMove.js",
    "content": "/*\nDescription:\nTask:\nThis kata asks you to make a custom esolang interpreter for the language [MiniBitMove](http://esolangs.org/wiki/MiniBitMove). MiniBitMove has only two commands and operates on a array of bits. It works like this:\n1: Flip the bit at the current cell\n0: Move selector by 1\nIt takes two inputs, the program and the bits in needs to operate on. The program returns the modified bits. The program stops when selector reaches the end of the array. Otherwise the program repeats itself. Note: This means that if a program does not have any zeros it is an infinite loop\n\nExample of a program that flips all bits in an array:\n\nCode: 10\nBits: 11001001001010\nResult: 00110110110101\nAfter you're done, feel free to make translations and discuss this kata.\n*/\nfunction interpreter(tape, array) {\n  array=array.split``\n  for (let i=0;i<array.length;){\n    for (let j=0;j<tape.length;j++){\n      if (tape[j]==='1') array[i]=array[i].replace(/[01]/,v=>v==='0'?'1':'0')\n      if (tape[j]==='0'){\n        i++\n      }\n      if (array[i]===undefined) break\n    }\n  }\n  return array.join``\n}\n"
  },
  {
    "path": "Esolang: Tick.js",
    "content": "/*\nDescription:\nTask\nMake a custom esolang interpreter for the language Tick. Tick is a descendant of Ticker but also very different data and command-wise.\n\nSyntax/Info\nCommands are given in character format. Non-command characters should be ignored. Tick has an potentially infinite memory as opposed to Ticker(which you have a special command to add a new cell) and only has 4 commands(as opposed to 7). Read about this esolang here.\n\nCommands\n>: Move data selector right\n\n<: Move data selector left(infinite in both directions)\n\n+: Increment memory cell by 1. 255+1=0\n\n*: Add ascii value of memory cell to the output tape.\n\nExamples\nHello world!\n\n'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*<<*>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*<<<<*>>>>>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++*'\n\n*/\nfunction interpreter(tape) {\n  let dict = {}\n  let str = []\n  let num = 0;\n  let selector=0;\n  for (let i=0;i<tape.length;i++){\n   if (tape[i]==='+') dict[selector]=dict[selector]+1||1; \n   else if (tape[i]==='>') selector++\n   else if (tape[i]==='<') selector--\n   else if (tape[i]==='*') { str += String.fromCharCode(dict[selector]%256)}\n  }\n  return str \n}\n"
  },
  {
    "path": "Even Fibonacci Sum.js",
    "content": "/*\nDescription:\nGive the summation of all even numbers in a Fibonacci sequence up to, but not including, the maximum value.\n\nThe Fibonacci sequence is a series of numbers where the next value is the addition of the previous two values. The series starts with 0 and 1:\n\n0 1 1 2 3 5 8 13 21...\n\nFor example:\n\nfibonacci(0)==0\nfibonacci(33)==10\nfibonacci(25997544)==19544084\n*/\nfunction fibonacci(max) {\n    let fib = [0,1]\n    for (let i=1;fib[i-1]+fib[i]<max;i++){\n      fib.push(fib[i-1]+fib[i])\n    }\n    return fib.reduce((a,b)=>a+(b%2==0?b:0),0)\n}\n"
  },
  {
    "path": "Evil Autocorrect Prank.js",
    "content": "/*\nDescription:\nYour friend won't stop texting his girlfriend. It's all he does. All day. Seriously. The texts are so mushy too! The whole situation just makes you feel ill. Being the wonderful friend that you are, you hatch an evil plot. While he's sleeping, you take his phone and change the autocorrect options so that every time he types \"you\" or \"u\" it gets changed to \"your sister.\"\n\nWrite a function called autocorrect that takes a string and replaces all instances of \"you\" or \"u\" (not case sensitive) with \"your sister\" (always lower case).\n\nReturn the resulting string.\n\nHere's the slightly tricky part: These are text messages, so there are different forms of \"you\" and \"u\".\n\nFor the purposes of this kata, here's what you need to support:\n\n\"youuuuu\" with any number of u characters tacked onto the end\n\"u\" at the beginning, middle, or end of a string, but NOT part of a word\n\"you\" but NOT as part of another word like youtube or bayou\n*/\nfunction autocorrect(input){\n  return input.replace(/\\b(you+|u)\\b/gi, \"your sister\");\n}\n"
  },
  {
    "path": "Exclamation marks series #17: Put the exclamation marks and question marks to the balance, Are they balanced?.js",
    "content": "/*\nDescription:\nEach exclamation mark weight is 2; Each question mark weight is 3. Put two string left and right to the balance, Are they balanced?\n\nIf the left side is more heavy, return \"Left\"; If the right side is more heavy, return \"Right\"; If they are balanced, return \"Balance\".\n\nExamples\nbalance(\"!!\",\"??\") === \"Right\"\nbalance(\"!??\",\"?!!\") === \"Left\"\nbalance(\"!?!!\",\"?!?\") === \"Left\"\nbalance(\"!!???!????\",\"??!!?!!!!!!!\") === \"Balance\"\nNote\nPlease don't post issue about difficulty or duplicate.\n*/\nfunction balance(left,right){\n  let l=left.split('').map(v=>v==='!'?v=2:v=3).reduce((a,b)=>a+b,0);\n  let r=right.split('').map(v=>v==='!'?v=2:v=3).reduce((a,b)=>a+b,0);\n  return l>r?'Left':l===r?\"Balance\":'Right';\n}\n"
  },
  {
    "path": "Exercise in Summing.js",
    "content": "/*\nDescription:\nYour task is to finish two functions, minimumSum and maximumSum, that take 2 parameters:\n\nvalues: an array of integers with an arbitrary length; may be positive and negative\nn: how many integers should be summed; always 0 or bigger\nExample:\nvar values = [5, 4, 3, 2, 1];\nminimumSum(values, 2); // should return 1+2 = 3\nmaximumSum(values, 3); // should return 3+4+5 = 12\nAll values given to the functions will be integers. Also take care of the following special cases:\n\nif values is empty, both functions should return 0\nif n is 0, both functions should also return 0\nif n is larger than values's length, use the length instead.\n*/\nfunction minimumSum(values, n) {\n  values=values.sort((a,b)=>a-b);\n  return values.slice(0,n).reduce((a,b)=>a+b,0)\n}\n\nfunction maximumSum(values, n) {\n  values=values.sort((a,b)=>b-a);\n  return values.slice(0,n).reduce((a,b)=>a+b,0)\n}\n"
  },
  {
    "path": "Extract Nested Object Reference.js",
    "content": "/*\nDescription:\nYou are given a complex object that has many deeply nested variables. You don't want to go the usual if obj.property == null route. Create a prototype method that given a nested path, either return the value or undefined.\n\nvar obj = {\n  person: {\n    name: 'joe',\n    history: {\n      hometown: 'bratislava',\n      bio: {\n        funFact: 'I like fishing.'\n      }\n    }\n  }\n};\n\nobj.hash('person.name'); // 'joe'\nobj.hash('person.history.bio'); // { funFact: 'I like fishing.' }\nobj.hash('person.history.homeStreet'); // undefined\nobj.hash('person.animal.pet.needNoseAntEater'); // undefined\n*/\nObject.prototype.hash = function(string) {\n  try {\n  return eval(`this.${string}`)\n  }\n  catch(e){\n  return undefined\n  }\n}\n"
  },
  {
    "path": "Extract last names of people named Michael.js",
    "content": "/*\nDescription:\nGiven a text, for example:\n\nconst inputText = \"Michael, how are you? - Cool, how is John Williamns and Michael Jordan? I don't know but Michael Johnson is fine. Michael do you still score points with LeBron James, Michael Green AKA Star and Michael Wood?\";\n\nget an array of last names of people named Michael. The result should be:\n[\"Jordan\", \"Johnson\", \"Green\", \"Wood\"]\n\nNotes:\n\nFirst name will always be Michael with upper case 'M'.\nThere will always be a space character between 'Michael' and last name.\nLast name will always be one word, starting with an upper-case letter and continuing with lower-case letters.\nThere will always be at least one 'Micheal' with a valid last name in the input text.\n*/\nfunction getMichaelLastName(s) {\n  return s.match(/(Michael [A-Z]\\w+\\b)/g).map(v=>v.split` `[1])\n}\n"
  },
  {
    "path": "Extract the IDs from the data set.js",
    "content": "/*\nDescription:\nComplete the method so that it returns an array of all ID's passed in. The data structure will be similar to the following:\n\nvar data = {\n  id: 1,\n  items: [\n    {id: 2},\n    {id: 3, items: [\n      {id: 4},\n      {id: 5}\n    ]}\n  ]\n}\n\nextractIds(data) // should return [1,2,3,4,5]\nThe method should be able to handle the case of empty data being passed in.\n\nNote: The only arrays that need to be traversed are those assigned to the \"items\" property.\n*/\nfunction extractIds(data){\n  return [].concat(...Object.keys(data).map(function(item) {\n      return item === 'id' ? data[item] : extractIds(data[item]);\n    }))\n}\n"
  },
  {
    "path": "FIXME: Hello.js",
    "content": "/*\nDescription:\nThe code provided has a method hello which is supposed to show only those attributes which have been explicitly set. Furthermore, it is supposed to say them in the same order they were set.\n\nBut it's not working properly.\n\nNotes\nThere are 3 attributes\n\nname\nage\nsex ('M' or 'F')\nWhen the same attribute is assigned multiple times the hello method shows it only once. If this happens the order depends on the first assignment of that attribute, but the value is from the last assignment.\n\nExamples\nHello.\nHello. My name is Bob. I am 27. I am male.\nHello. I am 27. I am male. My name is Bob.\nHello. My name is Alice. I am female.\nHello. My name is Batman.\nTask\nFix the code so we can all go home early.\n*/\nclass Dinglemouse {\n    constructor() {\n        this.age=true\n        this.name=true\n        this.sex=true\n        this.agePos=0\n        this.namePos=0\n        this.sexPos=0\n        this.arr=[]\n    }\n    setAge(age) {\n    if (this.age){\n        this.age=false\n        this.agePos=this.arr.length\n        this.arr[this.agePos]=` I am ${age}.`\n        } else {\n          this.arr[this.agePos]=` I am ${age}.`\n        }\n        return this\n    }\n    setSex(sex) {\n      if (this.sex){\n        this.sex=false\n        this.sexPos=this.arr.length\n        this.arr[this.sexPos]=` I am ${sex == 'M' ? \"male\" : \"female\"}.`\n        } else {\n          this.arr[this.sexPos]=` I am ${sex == 'M' ? \"male\" : \"female\"}.`\n        }\n        return this\n    }\n    setName(name) {\n      if (this.name){\n        this.name=false\n        this.namePos=this.arr.length\n        this.arr[this.namePos]=` My name is ${name}.`\n        } else {\n          this.arr[this.namePos]=` My name is ${name}.`\n        }\n        return this\n    }\n    hello() {\n        return `Hello.${this.arr.join``}`\n    }\n}\n"
  },
  {
    "path": "Factorial length.js",
    "content": "/*\nDescription:\nIn this Kata, you will implement a function count that takes an integer and returns the number of digits in factorial(n).\n\nFor example, count(5) = 3, because 5! = 120, and 120 has 3 digits.\n\nMore examples in the test cases.\n\nBrute force is not possible. A little research will go a long way, as this is a well known series.\n\nGood luck!\n*/\nfunction count(n) {\n  return Math.ceil(Math.log10(2*Math.PI*n)/2 + n*Math.log10(n/Math.E))\n};\n"
  },
  {
    "path": "Faro Shuffle Count.js",
    "content": "/*\nDescription:\nA faro shuffle of a deck of playing cards is a shuffle in which the deck is split exactly in half and then the cards in the two halves are perfectly interwoven, such that the original bottom card is still on the bottom and the original top card is still on top.\n\nFor example, faro shuffling the list\n\n['ace', 'two', 'three', 'four', 'five', 'six']\ngives\n\n['ace', 'four', 'two', 'five', 'three', 'six' ]\nIf 8 perfect faro shuffles are performed on a deck of 52 playing cards, the deck is restored to its original order.\n\nWrite a function that inputs an integer n and returns an integer representing the number of faro shuffles it takes to restore a deck of n cards to its original order.\n\nAssume n is an even number between 2 and 2000.\n*/\nfunction faroCount(deckSize){\n  let shuffles = 0, term = 1;\n  do {\n    shuffles++;\n    term = (deckSize * (term % 2) + term) / 2 | 0; \n  } while (term !== 1)\n  return shuffles;\n}\n"
  },
  {
    "path": "Fat Fingers.js",
    "content": "/*\nDescription:\nFreddy has a really fat left pinky finger, and every time Freddy tries to type an A, he accidentally hits the CapsLock key!\n\nGiven a string that Freddy wants to type, emulate the keyboard misses where each A supposedly pressed is replaced with CapsLock, and return the string that Freddy actually types. It doesn't matter if the A in the string is capitalized or not. When CapsLock is enabled, capitalization is reversed, but punctuation is not affected.\n\nExamples:\n\n\"The quick brown fox jumps over the lazy dog.\"\n-> \"The quick brown fox jumps over the lZY DOG.\"\n\n\"The end of the institution, maintenance, and administration of government, is to secure the existence of the body politic, to protect it, and to furnish the individuals who compose it with the power of enjoying in safety and tranquillity their natural rights, and the blessings of life: and whenever these great objects are not obtained, the people have a right to alter the government, and to take measures necessary for their safety, prosperity and happiness.\"\n-> \"The end of the institution, mINTENnce, ND dministrTION OF GOVERNMENT, IS TO SECURE THE EXISTENCE OF THE BODY POLITIC, TO PROTECT IT, nd to furnish the individuLS WHO COMPOSE IT WITH THE POWER OF ENJOYING IN Sfety ND TRnquillity their nTURl rights, ND THE BLESSINGS OF LIFE: nd whenever these greT OBJECTS re not obtINED, THE PEOPLE Hve  RIGHT TO lter the government, ND TO Tke meSURES NECESSry for their sFETY, PROSPERITY nd hPPINESS.\"\n\n\"aAaaaaAaaaAAaAa\"\n-> \"\"\nIf the given string is null, return null.\n\nIf the given string is \"\", the answer should be evident.\n\nHappy coding!\n\n(Adapted from https://codegolf.stackexchange.com/questions/158132/no-a-just-caps-lock)\n*/\nvar fatFingers = function(str) {\n  if(typeof str !== 'string') return str;\n  return str.replace(/A/g,'a').split('a').map((s,i)=>i%2?s.replace(/./g,m=>/[a-z]/.test(m)?m.toUpperCase():m.toLowerCase()):s).join``\n};\n"
  },
  {
    "path": "Feynman's square question.js",
    "content": "/*\nDescription:\nFeynman's squares\nRichard Phillips Feynman was a well-known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and pioneered the field of quantum computing.\n\nRecently, an old farmer found some papers and notes that are believed to have belonged to Feynman. Among notes about mesons and electromagnetism, there was a napkin where he wrote a simple puzzle: \"how many different squares are there in a grid of NxN squares?\".\n\nFor example, when N=2, the answer is 5: the 2x2 square itself, plus the four 1x1 squares in its corners:\n\n\nTask\nYou have to write a function\n\nfunction countSquares(n){ … }\nthat solves Feynman's question in general. The input to your function will always be a positive integer.\n\n#Examples\n\ncountSquares(1) =  1\ncountSquares(2) =  5\ncountSquares(3) = 14\n(Adapted from the Sphere Online Judge problem SAMER08F by Diego Satoba)\n*/\nfunction countSquares(n){\n  let num=0;\n  for (let i =0;i<=n;i++){\n    num+=(n - i)**2\n  }\n  return num\n}\n"
  },
  {
    "path": "Fibonacci Reloaded.js",
    "content": "/*\nDescription:\nAnd here is Fibonacci again. This time we want to go one step further. Our fib() function must be faster! Can you do it?\n\nIn case you don't know, what the Fibonacci number is:\n\nThe nth Fibonacci number is defined by the sum of the two previous Fibonacci numbers. In our case: fib(1) == 0 and fib(2) == 1. With these initial values you should be able to calculate each following Fibonacci number.\n\nExamples:\n\nfib(1) // === 0\nfib(2) // === 1\nfib(3) // === 1\nfib(4) // === 2\nfib(5) // === 3\n*/\nfunction fib(n) {\n  let arr = [0,1]\n  for (let i=1;i<=n;i++){\n    arr.push(arr[i-1]+arr[i])\n  }\n return arr[n-1]\n}\n"
  },
  {
    "path": "Fibonacci, Tribonacci and friends.js",
    "content": "/*\nDescription:\nIf you have completed the Tribonacci sequence kata, you would know by now that mister Fibonacci has at least a bigger brother. If not, give it a quick look to get how things work.\n\nWell, time to expand the family a little more: think of a Quadribonacci starting with a signature of 4 elements and each following element is the sum of the 4 previous, a Pentabonacci (well Cinquebonacci would probably sound a bit more italian, but it would also sound really awful) with a signature of 5 elements and each following element is the sum of the 5 previous, and so on.\n\nWell, guess what? You have to build a Xbonacci function that takes a signature of X elements - and remember each next element is the sum of the last X elements - and returns the first n elements of the so seeded sequence.\n\nxbonacci {1,1,1,1} 10 = {1,1,1,1,4,7,13,25,49,94}\nxbonacci {0,0,0,0,1} 10 = {0,0,0,0,1,1,2,4,8,16}\nxbonacci {1,0,0,0,0,0,1} 10 = {1,0,0,0,0,0,1,2,3,6}\nxbonacci {1,1} produces the Fibonacci sequence\n*/\n\nfunction Xbonacci(s,n){\n  if (s.length>n) return s.slice(0,n);\n  let sum=[...s]\n  for (let i=0;sum.length<n;i++)\n  {sum.push(sum.slice(i,sum.length).reduce((a,b)=>a+b,0))}\n  return sum\n}\n"
  },
  {
    "path": "File Path Operations.js",
    "content": "/*\nDescription:\nTask:\nThis kata requires you to write an object that receives a file path and does operations on it. NOTE FOR PYTHON USERS: You cannot use modules os.path, glob, and re\nThe purpose of this kata is to use string parsing, so you're not supposed to import external libraries. I could only enforce this in python.\nTesting:\nPython:\n\n>>> master = FileMaster('/Users/person1/Pictures/house.png')\n>>> master.extension()\n'png'\n>>> master.filename()\n'house'\n>>> master.dirpath()\n'/Users/person1/Pictures/'\nRuby:\n\nmaster = FileMaster.new('/Users/person1/Pictures/house.png')\nmaster.extension\n#--> png\nmaster.filename\n#--> house\nmaster.dirpath\n#--> /Users/person1/Pictures/\nC#:\n\nFileMaster FM = new FileMaster(\"/Users/person1/Pictures/house.png\");\nFM.extension(); // output: \"png\"\nFM.filename(); // output: \"house\"\nFM.dirpath(); // output: \"/Users/person1/Pictures/\"\nJavaScript:\n\nconst fm = new FileMaster('/Users/person1/Pictures/house.png');\nfm.extension(); // output: 'png'\nfm.filename(); // output: 'house'\nfm.dirpath(); // output: '/Users/person1/Pictures/'\nTypeScript:\n\nconst fm = new FileMaster('/Users/person1/Pictures/house.png');\nfm.extension(); // output: 'png'\nfm.filename(); // output: 'house'\nfm.dirpath(); // output: '/Users/person1/Pictures/'\nPHP:\n\n$fm = new FileMaster('/Users/person1/Pictures/house.png');\n$fm.extension(); // 'png'\n$fm.filename(); // 'house'\n$fm.dirpath(); // '/Users/person1/Pictures'\nNotes:\nI have other kata that need to be tested. You may find them here and here\nPlease post any questions or suggestion in the discourse section. Thank you!\nThank to all users who contributed to this kata! I appreciate your input!\n*/\nclass FileMaster {\n  constructor(filepath) {\n    this.path=filepath\n  }\n  \n  extension() {\n    return this.path.match(/\\.(.+$)/)[1]\n  }\n  \n  filename() {\n    return this.path.match(/\\/(\\w+)\\./)[1]\n  }\n  \n  dirpath() {\n    return this.path.match(/^\\/?.+\\//)\n  }\n}\n"
  },
  {
    "path": "Financing Plan on Planet XY140Z-n.js",
    "content": "/*\nDescription:\nI need to save some money to buy a gift. I think I can do something like that:\n\nFirst week (W0) I save nothing on Sunday, 1 on Monday, 2 on Tuesday... 6 on Saturday, second week (W1) 2 on Monday... 7 on Saturday and so on according to the table below where the days are numbered from 0 to 6.\n\nCan you tell me how much I will have for my gift on Saturday evening after I have saved 12? (Your function finance(6) should return 168 which is the sum of the savings in the table).\n\nImagine now that we live on planet XY140Z-n where the days of the week are numbered from 0 to n (integer n > 0) and where I save from week number 0 to week number n included (in the table below n = 6).\n\nHow much money would I have at the end of my financing plan on planet XY140Z-n?\n\n--\tSu\tMo\tTu\tWe\tTh\tFr\tSa\nW6\t\t\t\t\t\t\t12\nW5\t\t\t\t\t\t10\t11\nW4\t\t\t\t\t8\t9\t10\nW3\t\t\t\t6\t7\t8\t9\nW2\t\t\t4\t5\t6\t7\t8\nW1\t\t2\t3\t4\t5\t6\t7\nW0\t0\t1\t2\t3\t4\t5\t6\n#Example:\n\nfinance(5) --> 105\nfinance(6) --> 168\nfinance(7) --> 252\nfinance(5000) --> 62537505000\n#Hint: try to avoid nested loops\n*/\n\nfunction finance(n) {\n  let sum = 0;\n\tlet current_sum;\n\tfor (let i = 0; i <= n; i ++){ \n\t\tcurrent_sum= (2 * i + 2 * i + (n - i)) * (n + 1 - i) / 2\n\t\tsum += current_sum}\n\treturn sum;\n}\n"
  },
  {
    "path": "Financing a purchase.js",
    "content": "/*\nDescription:\nThe description is rather long but it tries to explain what a financing plan is.\n\nThe fixed monthly payment for a fixed rate mortgage is the amount paid by the borrower every month that ensures that the loan is paid off in full with interest at the end of its term.\n\nThe monthly payment formula is based on the annuity formula. The monthly payment c depends upon:\n\nrate - the monthly interest rate is expressed as a decimal, not a percentage. The monthly rate is simply the given yearly percentage rate divided by 100 and then by 12.\n\nterm - the number of monthly payments, called the loan's term.\n\nprincipal - the amount borrowed, known as the loan's principal (or balance).\n\nFirst we have to determine c.\n\nWe have: c = n /d with n = r * balance and d = 1 - (1 + r)**(-term) where ** is the power function (you can look at the reference below).\n\nThe payment c is composed of two parts. The first part pays the interest (let us call it int) due for the balance of the given month, the second part repays the balance (let us call this part princ) hence for the following month we get a new balance = old balance - princ with c = int + princ.\n\nLoans are structured so that the amount of principal returned to the borrower starts out small and increases with each mortgage payment. While the mortgage payments in the first years consist primarily of interest payments, the payments in the final years consist primarily of principal repayment.\n\nA mortgage's amortization schedule provides a detailed look at precisely what portion of each mortgage payment is dedicated to each component.\n\nIn an example of a $100,000, 30-year mortgage with a rate of 6 percents the amortization schedule consists of 360 monthly payments. The partial amortization schedule below shows with 2 decimal floats the balance between principal and interest payments.\n\n--\tnum_payment\tc\tprinc\tint\tBalance\n--\t1\t599.55\t99.55\t500.00\t99900.45\n--\t...\t599.55\t...\t...\t...\n--\t12\t599.55\t105.16\t494.39\t98,771.99\n--\t...\t599.55\t...\t...\t...\n--\t360\t599.55\t596.57\t2.98\t0.00\nTask:\nGiven parameters\n\nrate: annual rate as percent (don't forgent to divide by 100*12)\nbal: original balance (borrowed amount) \nterm: number of monthly payments\nnum_payment: rank of considered month (from 1 to term)\nthe function amort will return a formatted string:\n\n\"num_payment %d c %.0f princ %.0f int %.0f balance %.0f\" (with arguments num_payment, c, princ, int, balance)\n\nExamples:\namort(6, 100000, 360, 1) ->\n\"num_payment 1 c 600 princ 100 int 500 balance 99900\"\n\namort(6, 100000, 360, 12) ->\n\"num_payment 12 c 600 princ 105 int 494 balance 98772\"\nRef\nhttps://en.wikipedia.org/wiki/Mortgage_calculator\n*/\n\nfunction amort(r, b, t, n) {\n  r/=1200; var c=r*b/(1-(1+r)**(-t));\n  for(let m=1; m<n; m++) b-=(c-r*b);\n  return `num_payment ${n.toFixed(0)} c ${c.toFixed(0)} princ ${(c-r*b).toFixed(0)} int ${(r*b).toFixed(0)} balance ${(b-(c-r*b)).toFixed(0)}`;\n}\n"
  },
  {
    "path": "Find The Duplicated Number in a Consecutive Unsorted List - Tougher Version.js",
    "content": "/*\nDescription:\nSpin-off of this kata, here you will have to figure out an efficient strategy to solve the problem of finding the sole duplicate number among an unsorted array/list of numbers starting from 1 up to n.\n\nHints: a solution in linear time can be found; using the most intuitive ones to search for duplicates that can run in O(n²) time won't work.\n*/\nvar findDup=function(arr){\n  return arr.sort((a,b)=>a-b).filter((v,i,arr)=>v===arr[i+1])*1;\n}\n"
  },
  {
    "path": "Find The Parity Outlier",
    "content": "/*\nDescription:\nYou are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this \"outlier\" N.\n\nExamples\n[2, 4, 0, 100, 4, 11, 2602, 36]\nShould return: 11 (the only odd number)\n\n[160, 3, 1719, 19, 11, 13, -21]\nShould return: 160 (the only even number)\n*/\n\nfunction findOutlier(int){\n  var even = int.filter(a=>a%2==0);\n  var odd = int.filter(a=>a%2!==0);\n  return even.length==1? even[0] : odd[0];\n}\n"
  },
  {
    "path": "Find X.js",
    "content": "/*\nDescription:\nPart 2 version Find X Ⅱ\n\nWe have a function that takes in an integer n, and returns a number x.\n\nLets call this function findX(n)/find_x(n) (depending on your language):\n\nfunction findX(n) {\n  let x = 0;\n  for (let i = 0; i < n; i++) {\n    for (let j = 0; j < 2*n; j++)\n      x += i + j;\n  }\n  return x;\n}\nThe functions loops throught the number n and at every iteration, performs a nested loop on 2*n, at each iteration of this nested loop it increments x with the (nested loop index + parents loop index).\n\nThis works well when the numbers are reasonably small.\n\nfindX(2) //=> 16\nfindX(3) //=> 63\nfindX(5) //=> 325\nBut may be slow for numbers > 103\n\nSo your task is to optimize the function findX/find_x, so it works well for large numbers.\n\nInput Range\n1 <= n <= 106 (105 in JS)\n\nNote: This problem is more about logical reasoning than it is about finding a mathematicial formula, infact there are no complex math formula involved\n*/\nfunction findX(n) {\n  return n**2*(3*n-2)\n}\n"
  },
  {
    "path": "Find heavy ball - level: conqueror.js",
    "content": "/*\nDescription:\nThere are 8 balls numbered from 0 to 7. Seven of them have the same weight. One is heavier. Your task is to find it's number.\n\nYour function findBall will receive single argument - scales object. The scales object contains an internally stored array of 8 elements (indexes 0-7), each having the same value except one, which is greater. It also has a public method named getWeight(left, right) which takes two arrays of indexes and returns -1, 0, or 1 based on the accumulation of the values found at the indexes passed are heavier, equal, or lighter.\n\ngetWeight returns:\n\n-1 if left pan is heavier\n\n1 if right pan is heavier\n\n0 if both pans weight the same\n\nExamples of scales.getWeight() usage:\n\nscales.getWeight([3], [7]) returns -1 if ball 3 is heavier than ball 7, 1 if ball 7 is heavier, or 0 i these balls have the same weight.\n\nscales.getWeight([3, 4], [5, 2]) returns -1 if weight of balls 3 and 4 is heavier than weight of balls 5 and 2 etc.\n\nSo where's the catch, you may ask. Well - the scales is very old. You can use it only 3 TIMES before the scale breaks.\n\nToo easy? Too hard? Try other levels:\n\nnovice\nmaster\n*/\nfunction findBall(scales) {\n  var w = scales.getWeight([0, 1, 2, 3], [4, 5, 6, 7]);\n  if (w < 0) {\n    w = scales.getWeight([0, 1], [2, 3]);\n    if (w < 0) {\n      w = scales.getWeight([0], [1]);\n      return w < 0 ? 0 : 1;\n    } else {\n      w = scales.getWeight([2], [3]);\n      return w < 0 ? 2 : 3;\n    }\n  } else {\n    w = scales.getWeight([4, 5], [6, 7]);\n    if (w < 0) {\n      w = scales.getWeight([4], [5]);\n      return w < 0 ? 4 : 5;\n    } else {\n      w = scales.getWeight([6], [7]);\n      return w < 0 ? 6 : 7;\n    }\n  }\n  return -1;\n}\n"
  },
  {
    "path": "Find the Mine!.js",
    "content": "/*\nDescription:\nYou've just discovered a square (NxN) field and you notice a warning sign. The sign states that there's a single bomb in the 2D grid-like field in front of you.\n\nWrite a function mineLocation/MineLocation that accepts a 2D array, and returns the location of the mine. The mine is represented as the integer 1 in the 2D array. Areas in the 2D array that are not the mine will be represented as 0s.\n\nThe location returned should be an array (Tuple<int, int> in C#) where the first element is the row index, and the second element is the column index of the bomb location (both should be 0 based). All 2D arrays passed into your function will be square (NxN), and there will only be one mine in the array.\n\nExamples:\nmineLocation( [ [1, 0, 0], [0, 0, 0], [0, 0, 0] ] ) => returns [0, 0] \nmineLocation( [ [0, 0, 0], [0, 1, 0], [0, 0, 0] ] ) => returns [1, 1] \nmineLocation( [ [0, 0, 0], [0, 0, 0], [0, 1, 0] ] ) => returns [2, 1]\n*/\nfunction mineLocation(f){\n  let p=0;\n  let p1=0\n  for (let i=0;i<f.length;i++){\n    for(let j=0;j<f[i].length;j++){\n    if (f[i][j]===1){p1=j;p=i}\n    }}\n  return [p,p1]\n}\n"
  },
  {
    "path": "Find the Nexus of the Codewars Universe.js",
    "content": "/*\nDescription:\nNot to brag, but I recently became the nexus of the Codewars universe! My honor and my rank were the same number. I cried a little.\n\nComplete the method that takes a hash/object/directory/association list of users, and find the nexus: the user whose rank is the closest is equal to his honor. Return the rank of this user. For each user, the key is the rank and the value is the honor.\n\nIf nobody has an exact rank/honor match, return the rank of the user who comes closest. If there are several users who come closest, return the one with the lowest rank (numeric value). The hash will not necessarily contain consecutive rank numbers; return the best match from the ranks provided.\n\nExample\n         rank    honor\nusers = {  1  =>  93,\n          10  =>  55,\n          15  =>  30,\n          20  =>  19,    <--- nexus\n          23  =>  11,\n          30  =>   2 }\n*/\n\nfunction nexus(users) {\n  const obj=Object.keys(users)\n  const obj2=Object.values(users)\n  const arr=obj.map((v,i)=>Math.abs(v*1-obj2[i]))\n  const index=arr.indexOf(Math.min(...arr.map(v=>Math.abs(v))))\n  return obj[index]*1\n}\n"
  },
  {
    "path": "Find the Nth longest string in an Array.js",
    "content": "/*\nDescription:\nImplement the function longest(array,n) where you will be given an array of strings and then return the nth longest string in that array. e.g. arr = ['Hello','World','Codewars','Katas'] n = 3; should return 'World' because 'Codewars' length = 8 , 'Hello' length = 5, so that is the 2nd longest word and then 'World' (although also word length of 5, 'World' is after 'Hello' in the array). When words have the same lengths, treat them in the order in which they exist in the array. Array will never be empty and n > 0 always.\n*/\nfunction longest(arr, n) {\n  let check=arr.slice()\n  return arr.sort((a,b)=>b.length-a.length||check.indexOf(a)-check.indexOf(b))[n-1]\n}\n"
  },
  {
    "path": "Find the missing letter",
    "content": "/*\nDescription:\n#Find the missing letter\n\nWrite a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.\n\nYou will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2.\nThe array will always contain letters in only one case.\n\nExample:\n\n['a','b','c','d','f'] -> 'e'\n['O','Q','R','S'] -> 'P'\n(Use the English alphabet with 26 letters!)\n\nHave fun coding it and please don't forget to vote and rank this kata! :-)\n\nI have also created other katas. Take a look if you enjoyed this kata!\n*/\n\n\nfunction findMissingLetter(array) {\n  return String.fromCharCode(array.find((c,i)=>array[i+1].charCodeAt()-c.charCodeAt()!==1).charCodeAt()+1)\n}\n"
  },
  {
    "path": "Find the missing term in an Arithmetic Progression",
    "content": "/*\nDescription:\nAn Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly one term from the original series is missing from the set of numbers which have been given to you. The rest of the given series is the same as the original AP. Find the missing term.\n\nYou have to write the function findMissing(list), list will always be at least 3 numbers. The missing term will never be the first or last one.\n\nExample\nfindMissing([1, 3, 5, 9, 11]) == 7\n```\n\nPS: This is a sample question of the facebook engineer challenge on interviewstreet. I found it quite fun to solve on paper using math, derive the algo that way. Have fun!\n*/\n\nvar findMissing = function (l) {  \n  return ((l[0]+l[l.length-1])*(l.length+1))/2-(l.reduce((a,b)=>a+b))\n}\n"
  },
  {
    "path": "Find the odd int",
    "content": "/*\nGiven an array, find the int that appears an odd number of times.\n\nThere will always be only one integer that appears an odd number of times.\n*/\nfunction findOdd(A) {\n  let count = {};\n  A.forEach(v => {\n    count[v] = count[v] ? count[v] + 1 : 1;\n  });\n  return +Object.keys(count).find(key => count[key] % 2 === 1);\n}\n"
  },
  {
    "path": "Find the unique number",
    "content": "/*\nDescription:\nThere is an array with some numbers. All numbers are equal except for one. Try to find it!\n\nfindUniq([ 1, 1, 1, 2, 1, 1 ]) === 2\nfindUniq([ 0, 0, 0.55, 0, 0 ]) === 0.55\nIt’s guaranteed that array contains more than 3 numbers.\n\nThe tests contain some very huge arrays, so think about performance.\n\nThis is the first kata in series:\n\nFind the unique number (this kata)\nFind the unique string\nFind The Unique\n*/\n\nfunction findUniq(arr) {\n  return +arr.filter( (value) => { return arr.indexOf(value) == arr.lastIndexOf(value) } );\n}\n"
  },
  {
    "path": "Find the unique number.js",
    "content": "/*\nDescription:\nWrite a function called findUnique which returns the only unique number from an array.\n\nAll numbers in the unsorted array are present twice, except the one you have to find. The numbers are always valid integer values between 1 and 2147483647, so no need for type and error checking. The array contains at least one number and may contain millions of numbers. So make sure your solution is optimized for speed.\n\nExample\nInput:\n\n[ 1, 8, 4, 4, 6, 1, 8 ]\nExpected output:\n\n6\n*/\nfunction findUnique(numbers) {\n  return numbers.reduce((a, b) => a ^ b);\n} \n"
  },
  {
    "path": "Find within array.js",
    "content": "/*\nDescription:\nLet's make an advanced version of Array.indexOf. We'll create a function that takes in two parameters:\n\nan array (length and types of items are irrelevant), and\na function (value, index) that will be called on members of the array. The function will return either true or false.\nYour function will iterate through the members of the array in order until the provided iterator function returns true; at which point your function will return that item's index.\n\nIf the iterator function returns false for all members of the array, your function should return -1.\n\n\n*/\nvar findInArray = function(array, iterator) {\n  return array.map((v,i)=>iterator(v,i)).indexOf(true)\n};\n"
  },
  {
    "path": "FizzBuzz Array! (Custom).js",
    "content": "/*\nDescription:\nWrite a function that returns an array of numbers from 1 to 100.\n\nThe function should be able to be called with or without arguments.\n\nIf no arguments are given, each number in the array divisible by 3 should be replaced with the word 'Fizz', and each number in the array divisible by 5 should be replaced with the word 'Buzz'. If the number is divisble by both 3 and 5, then it should be replaced with 'FizzBuzz'.\n\nThe function should also be able to take up to 4 arguments. The first and second arguments are strings, which should be 'Fizz' and 'Buzz' by default.\n\nThe third and fourth arguments are integers and and should be 3 and 5 by default.\n\nExample\n\nfizzBuzzCustom()[15]                         // returns 16\nfizzBuzzCustom()[44]                         // returns \"FizzBuzz\" (45 is divisible by 3 and 5)\nfizzBuzzCustom('Hey', 'There')[25]         // returns 26\nfizzBuzzCustom('Hey', 'There')[11]         // returns \"Hey\" (12 is divisible by 3)\nfizzBuzzCustom(\"What's \", \"up?\", 3, 7)[80] // returns \"What's \" (81 is divisible by 3)\n*/\nvar fizzBuzzCustom = function(s1='Fizz', s2='Buzz', n1=3, n2=5) {\n  let arr = [];\n  for (let i=1; i <=100; i++){\n  if (i%n1===0&&i%n2===0){\n  arr.push(s1+s2)}\n  else if (i%n1===0){\n  arr.push(s1)}\n  else if (i%n2===0){\n  arr.push(s2)}\n  else {arr.push(i)}\n  }\n  return arr\n};\n"
  },
  {
    "path": "Flexible Card Game.js",
    "content": "/*\nDescription:\nCreate any card game!\nCreate a Card Game library of classes which could be used to create any number of basic card games. You'll need at least a Deck class and a Card class.\n\nDeck functionality\nA deck has a public attribute:\n\ncards: array of remaining cards in the deck.\n\n...and three public methods:\n\ncount(): count of remaining cards in the deck.\n\nshuffle(): randomize the order of the remaining cards in the deck.\n\ndraw(n): remove the last n cards from the deck and return them in an array.\n\nUpon initialization, a deck is filled with 52 cards (13 from each of 4 suits).\n\nCard functionality\nA card has these public attributes:\n\nsuit: a symbol representing the suit of the card.\n\nrank: an integer from 1 to 13. (\"ace\" is 1, \"king\" is 13)\n\nJavascript: face_card: is this card a face card? (> 10)\n\n...and these methods:\n\nRuby: face_card?: is this card a face card? (> 10)\n\nto_s (JS:toString()) : human-readable string representation of the card (e.g. \"Ace of Spades\", \"10 of Clubs\", \"Queen of Hearts\")\n\nCards must be Comparable to other cards. Compare the ranks of the cards only.\n\nSince this is a low level layer to build card games above, all test input will be valid. All ranks will be between 1 and 13 and all suits will be one of\n\nRuby: :hearts, :diamonds, :spades, :clubs\nJavascript: Card.HEARTS, Card.DIAMONDS, Card.CLUBS, Card.SPADES\n*/\nfunction Card(suit, rank) {\n  this.suit = suit\n  this.rank = rank\n}\n\nCard.SUITS = [\n  Card.CLUBS    = 'Clubs',\n  Card.DIAMONDS = 'Diamonds',\n  Card.HEARTS   = 'Hearts',\n  Card.SPADES   = 'Spades'\n]\n\nCard.prototype = {\n  get face_card() {\n    return this.rank > 10\n  },\n  valueOf: function() {\n    return this.rank\n  },\n  toString: function() {\n    var rank = {1: 'Ace', 11: 'Jack', 12: 'Queen', 13: 'King'}[this.rank] || this.rank\n    return rank + ' of ' + this.suit\n  }\n}\n\nfunction Deck() {\n  this.cards = []\n  \n  for (var i = 0; i < Card.SUITS.length; i++) {\n    for (var rank = 1; rank <= 13; rank++) {\n      this.cards.push(new Card(Card.SUITS[i], rank))\n    }\n  }\n  \n  this.shuffle()\n}\n\nDeck.prototype = {\n  count: function() {\n    return this.cards.length\n  },\n  draw: function(n) {\n    return this.cards.splice(-n, n)\n  },\n  shuffle: function() {\n    this.cards.sort(function() { return Math.random() - 0.5 })\n  }\n};\n"
  },
  {
    "path": "Floating-point Approximation (I).js",
    "content": "/*\nDescription:\nConsider the function\n\nf: x -> sqrt(1 + x) - 1 at x = 1e-15.\n\nWe get: f(x) = 4.44089209850062616e-16\n\nor something around that, depending on the language.\n\nThis function involves the subtraction of a pair of similar numbers when x is near 0 and the results are significantly erroneous in this region. Using pow instead of sqrt doesn't give better results.\n\nA \"good\" answer is 4.99999999999999875... * 1e-16.\n\nCan you modify f(x) to give a good approximation of f(x) in the neigbourhood of 0?\n\nNote:\n\nDon't round or truncate your results. See the testing function in Sample Tests:.\n*/\nfunction f(x) {\n    return x / (1 + Math.sqrt(1 + x))\n}\n"
  },
  {
    "path": "Fold an array.js",
    "content": "/*\nDescription:\n#Fold an array\n\nIn this kata you have to write a method that folds a given array of integers by the middle x-times.\n\nAn example says more than thousand words:\n\nFold 1-times:\n[1,2,3,4,5] -> [6,6,3]\n\nA little visualization (NOT for the algorithm but for the idea of folding):\n\n Step 1         Step 2        Step 3       Step 4       Step5\n                     5/           5|         5\\          \n                    4/            4|          4\\      \n1 2 3 4 5      1 2 3/         1 2 3|       1 2 3\\       6 6 3\n----*----      ----*          ----*        ----*        ----*\n\n\nFold 2-times:\n[1,2,3,4,5] -> [9,6]\nAs you see, if the count of numbers is odd, the middle number will stay. Otherwise the fold-point is between the middle-numbers, so all numbers would be added in a way.\n\nThe array will always contain numbers and will never be null. The parameter runs will always be a positive integer greater than 0 and says how many runs of folding your method has to do.\n\nIf an array with one element is folded, it stays as the same array.\n\nThe input array should not be modified!\n\nHave fun coding it and please don't forget to vote and rank this kata! :-)\n\nI have created other katas. Have a look if you like coding and challenges.\n*/\n\nfunction foldArray(a, n) {\n  const r = [], c = a.slice();\n  while (c.length) r.push(c.pop() + (c.shift() || 0));\n  return n - 1 ? foldArray(r, n - 1) : r;\n}\n"
  },
  {
    "path": "Follow that Spy.js",
    "content": "/*\nDescription:\nWe are tracking down our rogue agent Matthew Knight A.K.A. Roy Miller and he travels from places to places to avoid being tracked. Each of his travels are based on a list of itineraries in an unusual or incorrect order. The task is to determine the routes he will take in his every journey. You are given an array of routes of his itineraries. List down only the places where he will go in correct order based on his itineraries.\n\nExample:\nroutes = [[USA, BRA], [JPN, PHL], [BRA, UAE], [UAE, JPN]]\n\nresult: \"USA, BRA, UAE, JPN, PHL\"\n\nnote: It is safe to assume that there will be no repeating place with different route and there are no empty routes and could have at least one (1) route (from one waypoint to another).\n*/\nfunction findRoutes(routes) {\n  let str = [].concat(...routes.map(v=>v))\n  str=str.filter(v=>str.indexOf(v)===str.lastIndexOf(v))\n  let index = 0\n  for (let i=0;i<str.length;i++){\n    for (let j=0;j<routes.length;j++){\n      if (routes[j][0]===str[i]){\n        index=j\n        break\n      }\n    }\n  }\n  let arr = routes.splice(index,1)\n  for (let i=0;i<routes.length;i++){\n    for (let j=0;j<routes.length;j++){\n      if (arr[i][1]===routes[j][0]){\n        arr.push(routes[j])\n        break\n      }\n    }\n  }\n   return [...new Set([].concat(...arr))].join`, `\n}\n"
  },
  {
    "path": "Football - Yellow and Red Cards.js",
    "content": "/*\nDescription:\nMost football fans love it for the goals and excitement. Well, this Kata doesn't. You are to handle the referee's little notebook and count the players who were sent off for fouls and misbehavior.\n\nThe rules: Two teams, named \"A\" and \"B\" have 11 players each; players on each team are numbered from 1 to 11. Any player may be sent off the field by being given a red card. A player can also receive a yellow warning card, which is fine, but if he receives another yellow card, he is sent off immediately (no need for a red card in that case). If one of the teams has less than 7 players remaining, the game is stopped immediately by the referee, and the team with less than 7 players loses.\n\nA card is a string with the team's letter ('A' or 'B'), player's number, and card's color ('Y' or 'R') - all concatenated and capitalized. e.g the card 'B7Y' means player #7 from team B received a yellow card.\n\nThe task: Given a list of cards (could be empty), return the number of remaining players on each team at the end of the game (as a tuple of 2 integers, team \"A\" first). If the game was terminated by the referee for insufficient number of players, you are to stop the game immediately, and ignore any further possible cards.\n\nNote for the random tests: If a player that has already been sent off receives another card - ignore it.\n*/\nfunction menStillStanding(cards) {\n let A = [0,0,0,0,0,0,0,0,0,0,0,0];\n let B = [0,0,0,0,0,0,0,0,0,0,0,0];\n let countA = 0\n let countB = 0\n for(let i=0;i<cards.length;i++){\n   let team=cards[i].match(/^A|B/).join``\n   let number=cards[i].match(/\\d+/).join``*1\n   let color=cards[i].match(/Y|R$/).join``\n  if (team==='A'){\n    if (color==='Y'){\n      A[number]++\n    } else {\n      A[number]+=2\n    }\n  }\n  if (team==='B'){\n    if (color==='Y'){\n      B[number]++\n    } else {\n      B[number]+=2\n    }\n  }\n  countA=A.filter(v=>v>1).length\n  countB=B.filter(v=>v>1).length\n  if (11-countA===6||11-countB===6){\n    return [11-countA,11-countB]\n  }\n }\n return [11-countA,11-countB]\n}\n"
  },
  {
    "path": "Format Text.js",
    "content": "/*\nDescription:\nWrite a function format that takes two arguments, text and width, and formats the text to fit the width.\n\nYour function should divide the given text into lines using newline characters. It should fit as many words into each line as possible without exceeding the given width or splitting any words between two lines. There should not be a space at the beginning or end of any line. For example, here is some text formatted with a width of 50:\n\nLorem ipsum dolor sit amet, consectetur adipiscing\nelit. Aliquam nec consectetur risus. Cras vel urna\na tellus dapibus consequat. Duis bibendum\ntincidunt viverra. Phasellus dictum efficitur sem\nquis porttitor. Mauris luctus auctor diam id\nultrices. Praesent laoreet in enim ut placerat.\nPraesent a facilisis turpis.\nAnd the same text formatted with a width of 30:\n\nLorem ipsum dolor sit amet,\nconsectetur adipiscing elit.\nAliquam nec consectetur risus.\nCras vel urna a tellus dapibus\nconsequat. Duis bibendum\ntincidunt viverra. Phasellus\ndictum efficitur sem quis\nporttitor. Mauris luctus\nauctor diam id ultrices.\nPraesent laoreet in enim ut\nplacerat. Praesent a facilisis\nturpis.\nFor the purpose of this exercise, words can contain any non-whitespace character and all words are separated by a single space. Words will never be longer than the provided width.\n\nNote for rubists: Function must be named format_ for ruby already has a built in format function.\n*/\nfunction format(text, width) {\n  let words = text.split(' '), output = [];\n  while (words.length) {\n    line = words.shift();\n    while (words.length && line.length + words[0].length < width) {\n      line += ' ' + words.shift();\n    }\n    output.push(line);\n  }\n  return output.join('\\n');\n}\n"
  },
  {
    "path": "Format a string of names like 'Bart, Lisa & Maggie'.",
    "content": "/*\nDescription:\nGiven: an array containing hashes of names\n\nReturn: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand.\n\nExample:\n\nlist([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ])\n// returns 'Bart, Lisa & Maggie'\n\nlist([ {name: 'Bart'}, {name: 'Lisa'} ])\n// returns 'Bart & Lisa'\n\nlist([ {name: 'Bart'} ])\n// returns 'Bart'\n\nlist([])\n// returns ''\n*/\n\n\nfunction list(names){\n  if(names.map(v=>v.name).length>1) return names.map(v=>v.name).slice(0,-1).join(', ')+' & '+names.map(v=>v.name).slice(-1)\n  return names.map(v=>v.name).slice(-1)+''\n}\n"
  },
  {
    "path": "Format words into a sentence.js",
    "content": "/*\nDescription:\nComplete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string values should be ignored. Empty arrays or null/nil values being passed into the method should result in an empty string being returned.\n\nformatWords(['ninja', 'samurai', 'ronin']) // should return \"ninja, samurai and ronin\"\nformatWords(['ninja', '', 'ronin']) // should return \"ninja and ronin\"\nformatWords([]) // should return \"\"\n*/\nfunction formatWords(words){\n  if (!words) return ''\n  words=words.filter(v=>v.length>0)\n  if (words.length===0) return ''\n  if (words.length===1) return words[0]\n  return words.slice(0,-1).join(', ')+' and '+words.slice(-1)\n}\n"
  },
  {
    "path": "Framed Reflection.js",
    "content": "/*\nDescription:\n100th Kata\nYou are given a message (text) that you choose to read in a mirror (weirdo). Return what you would see, complete with the mirror frame. Example:\n\n'Hello World'\n\nwould give:\n\n\nWords in your solution should be left-aligned.\n*/\nfunction mirror(text){\n  let stars = Math.max(...text.split` `.map(v=>v.length))+4\n  let space = Math.max(...text.split` `.map(v=>v.length))\n  let arr = text.split` `.map(v=>'\\n* '+v.split(``).reverse().join``+' '.repeat(space-v.length)+' *\\n').join``.replace(/\\*\\n\\n\\*/g,'*\\n*')\n  return '*'.repeat(stars)+arr+'*'.repeat(stars)\n}\n"
  },
  {
    "path": "Free pizza.js",
    "content": "/*\nDescription:\nIn an attempt to boost sales, the manager of the pizzeria you work at has devised a pizza rewards system: if you already made at least 5 orders of at least 20 dollars, you get a free 12 inch pizza with 3 toppings of your choice.\n\nHowever, the rewards system may change in the future. Your manager wants you to implement a function that, given a dictionary of customers, a minimum number of orders and a minimum order value, returns a set of the customers who are eligible for a reward.\n\nCustomers in the dictionary are represented as:\n\n{ 'customerName' : [list_of_order_values_as_integers] }\nSee example test case for more details.\n*/\nfunction pizzaRewards(customers, minOrders, minPrice) {\n  let arr = []\n  for (let i in customers){\n    if (customers[i].filter(v=>v>=minPrice).length>=minOrders) arr.push(i)\n  }\n  return arr\n}\n"
  },
  {
    "path": "Friday the 13ths.js",
    "content": "/*\nDescription:\nCreate the function fridayTheThirteenths that accepts a start year and an end year (inclusive), and returns all of the dates where the 13th of a month lands on a Friday in the given range of year(s).\n\nThe return value should be a string where each date is seperated by a space. The date should be formatted like 9/13/2014 where months do not have leading zeroes and are separated with forward slashes.\n\nIf no end year is given, only return friday the thirteenths during the start year.\n\nExamples\nfridayTheThirteenths(1999, 2000) \n  // returns \"8/13/1999 10/13/2000\"\n\nfridayTheThirteenths(2014, 2015) \n  // returns \"6/13/2014 2/13/2015 3/13/2015 11/13/2015\"\n\nfridayTheThirteenths(2000)\n  // returns \"10/13/2000\"\nThis kata was designed to use the built-in Date object. Dates can often be finicky, so while there are other methods to get the correct dates, I can't gurantee they will work.\n*/\nfunction fridayTheThirteenths(start, end=start) {\n  let date = new Date(start,0).getTime()\n  let arr = [];\n  for (let i=0;;i++){\n    date+=1000*60*60*24\n    let day = new Date(date).getDate()\n    let weekDay = new Date(date).getDay()\n    if (new Date(date).getFullYear()>=end+1){break}\n    if (day===13&&weekDay===5) arr.push (`${new Date(date).getMonth()+1}/${day}/${new Date(date).getFullYear()}`)\n  }\n  return arr.join` `\n}\n"
  },
  {
    "path": "Frog jumping.js",
    "content": "/*\nHelp the frog to find a way to freedom\nYou have an array of integers and have a frog at the first position\n\n[Frog, int, int, int, ..., int]\n\nThe integer itself may tell you the length and the direction of the jump\n\n For instance:\n  2 = jump two indices to the right\n -3 = jump three indices to the left\n  0 = stay at the same position\nYour objective is to find how many jumps are needed to jump out of the array.\n\nReturn -1 if Frog can't jump out of the array\n\nExample:\narray = [1, 2, 1, 5]; \njumps = 3  (1 -> 2 -> 5 -> <jump out>)\nAll tests for this Kata are randomly generated\n*/\nfunction solution(a) {\n  if (a.length===0) return -1\n  let count=0;\n  for (let i=0;i<a.length;i+=a[i]){\n  if (i<0){break}\n  count++\n  if (count>1000){return -1}\n  }\n  return count\n}\n"
  },
  {
    "path": "Fruit Machine.js",
    "content": "/*\nDescription:\nIntroduction\n \tSlot machine (American English), informally fruit machine (British English), puggy (Scottish English slang), the slots (Canadian and American English), poker machine (or pokies in slang) (Australian English and New Zealand English) or simply slot (American English), is a casino gambling machine with three or more reels which spin when a button is pushed. Slot machines are also known as one-armed bandits because they were originally operated by one lever on the side of the machine as distinct from a button on the front panel, and because of their ability to leave the player in debt and impoverished. Many modern machines are still equipped with a legacy lever in addition to the button. (Source Wikipedia)\n \n\nTask\n \tYou will be given three reels of different images and told at which index the reels stop. From this information your job is to return the score of the resulted reels.\nRules\n \t1. There are always exactly three reels\n2. Each reel has 10 different items.\n3. The three reel inputs may be different.\n4. The spin array represents the index of where the reels finish.\n5. The three spin inputs may be different\n6. Three of the same is worth more than two of the same\n7. Two of the same plus one \"Wild\" is double the score.\n8. No matching items returns 0.\nScoring\nItem\nThree of the same\nTwo of the same\nTwo of the same plus one Wild\nWild\n100\n10\nN/A\nStar\n90\n9\n18\nBell\n80\n8\n16\nShell\n70\n7\n14\nSeven\n60\n6\n12\nCherry\n50\n5\n10\nBar\n40\n4\n8\nKing\n30\n3\n6\nQueen\n20\n2\n4\nJack\n10\n1\n2\n \nReturns\n \tReturn an integer of the score.\nExample\nInitialise\nreel1 = [\"Wild\",\"Star\",\"Bell\",\"Shell\",\"Seven\",\"Cherry\",\"Bar\",\"King\",\"Queen\",\"Jack\"];\nreel2 = [\"Wild\",\"Star\",\"Bell\",\"Shell\",\"Seven\",\"Cherry\",\"Bar\",\"King\",\"Queen\",\"Jack\"];\nreel3 = [\"Wild\",\"Star\",\"Bell\",\"Shell\",\"Seven\",\"Cherry\",\"Bar\",\"King\",\"Queen\",\"Jack\"];\nspin = [5,5,5];\nresult = fruit([reel1,reel2,reel3],spin);\nScoring\nreel1[5] == \"Cherry\"\nreel2[5] == \"Cherry\"\nreel3[5] == \"Cherry\"\n\nCherry + Cherry + Cherry == 50\nReturn\nGood luck and enjoy!\n*/\nfunction fruit(reels, spins){\n  const object={}\n  const arr=[reels[0][spins[0]],reels[1][spins[1]],reels[2][spins[2]]].map(v=>object[v]=object[v]?object[v]+1:1)\n  let result =0;\n  if (object['Wild']===3) result+=100;\n  if (object['Wild']===2) result+=10;\n  if (object['Star']===3) result+=90;\n  if (object['Star']===2&&object['Wild']!==1) result+=9;\n  if (object['Star']===2&&object['Wild']===1) result+=18;\n  if (object['Bell']===3) result+=80;\n  if (object['Bell']===2&&object['Wild']!==1) result+=8;\n  if (object['Bell']===2&&object['Wild']===1) result+=16;\n  if (object['Shell']===3) result+=70;\n  if (object['Shell']===2&&object['Wild']!==1) result+=7;\n  if (object['Shell']===2&&object['Wild']===1) result+=14;\n  if (object['Seven']===3) result+=60;\n  if (object['Seven']===2&&object['Wild']!==1) result+=6;\n  if (object['Seven']===2&&object['Wild']===1) result+=12;\n  if (object['Cherry']===3) result+=50;\n  if (object['Cherry']===2&&object['Wild']!==1) result+=5;\n  if (object['Cherry']===2&&object['Wild']===1) result+=10;\n  if (object['Bar']===3) result+=40;\n  if (object['Bar']===2&&object['Wild']!==1) result+=4;\n  if (object['Bar']===2&&object['Wild']===1) result+=8;\n  if (object['King']===3) result+=30;\n  if (object['King']===2&&object['Wild']!==1) result+=3;\n  if (object['King']===2&&object['Wild']===1) result+=6;\n  if (object['Queen']===3) result+=20;\n  if (object['Queen']===2&&object['Wild']!==1) result+=2;\n  if (object['Queen']===2&&object['Wild']===1) result+=4;\n  if (object['Jack']===3) result+=10;\n  if (object['Jack']===2&&object['Wild']!==1) result+=1;\n  if (object['Jack']===2&&object['Wild']===1) result+=2;\n  return result\n}//easy\n"
  },
  {
    "path": "Fun with lists: countIf.js",
    "content": "/*\nDescription:\nImplement the method countIf (count_if in PHP), which accepts a linked list (head) and a predicate function, and returns the number of elements which apply to the given predicate.\n\nFor example: Given the list: 1 -> 2 -> 3, and the predicate x => x >= 2, countIf / count_if should return 2, since x >= 2 applies to both 2 and 3.\n\nThe linked list is defined as follows:\n\nfunction Node(data, next = null) {\n  this.data = data;\n  this.next = next;\n}\nNote: the list may be null and can hold any type of value.\n\nGood luck!\n*/\nfunction countIf(head, p) {\n  let count = 0\n  while (head){\n    if (p(head.data)) count++\n    head=head.next\n  }\n  return count\n}\n"
  },
  {
    "path": "Fun with lists: filter.js",
    "content": "/*\nDescription:\nImplement the method filter, which accepts a linked list (head) and a predicate function, and returns a new linked list (head) which only contains the elements which apply to the given predicate.\n\nFor example: Given the list: 1 -> 2 -> 3, and the predicate x => x >= 2, filter should return 2 -> 3, since x >= 2 applies to both 2 and 3.\n\nThe linked list is defined as follows:\n\nfunction Node(data, next = null) {\n  this.data = data;\n  this.next = next;\n}\nNote: the list may be null and can hold any type of value.\n\nGood luck!\n*/\nfunction Node(data, next = null) {\n  this.data = data;\n  this.next = next;\n}\nfunction filter(head, p) {\n  if (head) {\n    return p(head.data) ? new Node(head.data, filter(head.next, p)) : filter(head.next, p);\n  }\n  return null;\n}\n"
  },
  {
    "path": "Fun with lists: map.js",
    "content": "/*\nDescription:\nImplement the method map, which accepts a linked list (head) and a mapping function, and returns a new linked list (head) where every element is the result of applying the given mapping method to each element of the original list.\n\nFor example: Given the list: 1 -> 2 -> 3, and the mapping function x => x * 2, map should return 2 -> 4 -> 6\n\nThe linked list is defined as follows:\n\nfunction Node(data, next = null) {\n  this.data = data;\n  this.next = next;\n}\nNote: the list may be null and can hold any type of value.\n\nGood luck!\n\nThis kata is part of fun with lists series:\n\nFun with lists: length\nFun with lists: indexOf\nFun with lists: lastIndexOf\nFun with lists: countIf\nFun with lists: anyMatch + allMatch\nFun with lists: filter\nFun with lists: map\nFun with lists: reduce\n*/\nfunction map(head, func) {\n  if (head) {\n    return new Node(func(head.data), map(head.next, func));\n  }\n  return null;\n}\n"
  },
  {
    "path": "Fun with lists: reduce.js",
    "content": "/*\nDescription:\nImplement the method reduce, which accepts three arguments:\n\nlinked list (head)\nbi-function - (accumulated_value, current_element_data)\ninitial value\nThis method should return the result of applying the given function on every element with the accumulating result, starting with the initial value.\n\nFor example:\n\nGiven the list: 1 -> 2 -> 3, the function (acc, curr) => acc + curr and an initial value of 0, reduce should return 6, because:\n\n(0, 1) and the function (acc, curr) => acc + curr gives 1\n(1, 2) and the function (acc, curr) => acc + curr gives 3\n(3, 3) and the function (acc, curr) => acc + curr gives 6\nAnother example:\n\nGiven the list: 1 -> 2 -> 3 -> 4, the function (acc, curr) => acc * curr and an initial value of 1, reduce should return 24\n\nThe linked list is defined as follows:\n\nfunction Node(data, next = null) {\n  this.data = data;\n  this.next = next;\n}\nNote: the list may be null and can hold any type of value.\n\nGood luck!\n*/\nfunction reduce(head, f, init) {\n  const arr = []\n  while (head){\n    arr.push(head.data)\n    head=head.next\n  }\n  return arr.reduce(f,init);\n}\n"
  },
  {
    "path": "Fun with trees: max sum.js",
    "content": "/*\nDescription:\nYou are given a binary tree. Implement the method maxSum which returns the maximal sum of a route from root to leaf. For example, given the following tree:\n\n    17\n   /  \\\n  3   -10\n /    /  \\\n2    16   1\n         /\n        13\nThe method should return 23, since [17,-10,16] is the route from root to leaf with the maximal sum.\n\nThe class TreeNode is available for you:\n\nvar TreeNode = function(value, left, right) {\n  this.value = value;\n  this.left = left;\n  this.right = right;\n};\nThis kata is part of fun with trees series:\n\nFun with trees: max sum\nFun with trees: array to tree\nFun with trees: is perfect\n*/\nfunction maxSum(root) {\n  if (!root) return 0\n  return root.value + Math.max(maxSum(root.left),maxSum(root.right))\n}\n"
  },
  {
    "path": "Function Composition",
    "content": "/*\nDescription:\nFunction composition is a mathematical operation that mainly presents itself in lambda calculus and computability. It is explained well here, but this is my explanation, in simple mathematical notation:\n\nf3 = compose( f1 f2 )\n   Is equivalent to...\nf3(a) = f1( f2( a ) )\nYour task is to create a compose function to carry out this task, which will be passed two functions or lambdas. Ruby functions will be passed, and should return, either a proc or a lambda. Remember that the resulting composed function may be passed multiple arguments!\n\ncompose(f , g)(x)\n=> f( g( x ) )\nThis kata is not available in haskell; that would be too easy!\n*/\n\nconst compose = (f,g) => (...args) => f(g(...args));\n"
  },
  {
    "path": "Function composition.js",
    "content": "/*\nDescription:\nJavascript functions can be combined to form new functions. For example the functions addOne and multTwo can be combined to form a new function which first adds one and then multiplies by two, as follows:\n\nconst addOne = (a) => a + 1\nconst multTwo = (b) => b * 2\nconst addOneMultTwo = (c) => multTwo(addOne(c))\n\naddOneMultTwo(5) // returns 12\nCombining functions like this is called function composition. Functional programming libraries in Javascript such as Ramda include a generic compose function which does the heavy lifting of combining functions for you. So you could implement addOneMultTwo as follows:\n\nconst addOneMultTwo = compose(multTwo, addOne)\n\naddOneMultTwo(5) // returns 12\nA simple implementation of compose, could work as follows:\n\nconst compose = (f, g) => (a) => f(g(a))\nThe arguments f and g are unary functions (i.e. functions which take one argument). The problem with this compose function is that it only composes two functions. Your task is to write a compose function which can compose any number of functions together.\n*/\nconst compose = (...fns) => arg => fns.reduceRight((res, fn) => fn(res), arg);\n"
  },
  {
    "path": "Function iteration.js",
    "content": "/*\nDescription:\nThe purpose of this kata is to write a higher-order function which is capable of creating a function that iterates on a specified function a given number of times. This new functions takes in an argument as a seed to start the computation from.\n\nFor instance, consider the function getDouble. When run twice on value 3, yields 12 as shown below.\n\ngetDouble(3) => 6\ngetDouble(6) => 12\nLet us name the new function createIterator and we should be able to obtain the same result using createIterator as shown below:\n\nvar doubleIterator = createIterator(getDouble, 2); // This means, it runs *getDouble* twice\ndoubleIterator(3) => 12\nFor the sake of simplicity, all function inputs to createIterator would be functions returning a small number and number of iterations would always be integers.\n*/\nvar createIterator = function (func, n) {\n  return function(){\n  let start=func(...arguments)\n  for (let i=0;i<n-1;i++){\n      start=func(start)\n    }\n    return start\n  }\n};\n"
  },
  {
    "path": "Functional Lists.js",
    "content": "/*\nDescription:\nIn this kata, you will create a simple, immutable, singly-linked list.\n\nMost list implementations use mutable nodes. Mutability brings with it a whole host of problems (especially in threaded environments, but even just with state saved and shared in multiple places). When you shift to immutable nodes, you gain a new ability to reason about things. If you have a list, it will never contain different things than it does at the moment.\n\nHowever, when dealing with immutable nodes, one has to take special steps to try to maintain efficiency. For example, to add a node to the beginning of a list, you don't want to have to duplicate the whole list. You want to be able to share as many nodes of the list as possible between the original list and the newly generated list (while still being a singly-linked list).\n\nThere are two classes involved here: EmptyList and ListNode. Each of these should support the following operations: toString(), isEmpty(), length(), push(), remove(), and append(). If isEmpty() returns false, then the following two methods should also be supported: head() and tail().\n\nvar list0 = new EmptyList();        // => \"()\"\nvar list1 = list0.push(3);          // => \"(3)\"\nvar list2 = list1.push(2);          // => \"(2 3)\"\nvar list3 = list2.push(1);          // => \"(1 2 3)\"\nvar list13 = list1.append(list3);   // => \"(3 1 2 3)\"\n\nlist13.head()    // => 3\nlist13.tail()    // => list3\n\nlist1 instanceof ListNode\nlist1.tail() instanceof EmptyList\nDiagramatically, this is what list3 above should look like:\n\n\nOr, if you prefer JSON:\n\n{ value: 1,\n  next: { value: 2,\n          next: { value: 3,\n                  next: {} } } }\nThe EmptyList constructor takes no arguments. The ListNode constructor takes a value and a next parameter. The value parameter can be anything. The next parameter will be either a ListNode instance or an EmptyList instance representing the rest of the list after this node.\n\nThe toString() method should return \"()\" for an EmptyList and \"(1 2 3)\" for a list containing the numbers 1, 2, and 3.\n\nThe isEmpty() method will return true for EmptyList instances and false for the ListNode instances.\n\nThe length() method will return the number of non-EmptyList nodes in a list.\n\nThe orig.push(x) method will create a list whose first node contains the value x and where the new list shares as many nodes as possible with orig (while still being a singly-linked list).\n\nThe orig.remove(x) method will create a list where all nodes with value x are removed and which shares as many nodes as possible with orig (while still being a singly-linked list).\n\nThe orig.append(other) method will create a list which is a concatenation of all nodes in orig and all nodes in other and which shares as many nodes as possible with orig and other (while still being a singly-linked list).\n\nIf orig.isEmpty() returns false, then orig.head() should return the value in the first node of the list. The orig.tail() should return the sublist of orig containing all of the nodes except the first node in orig.\n*/\nfunction List() {}\n\nfunction EmptyList() {}\nEmptyList.prototype = new List();\nEmptyList.prototype.constructor = EmptyList;\n\nEmptyList.prototype.toString = function() { return '()'; };\nEmptyList.prototype.isEmpty = function() { return true; };\nEmptyList.prototype.length = function() { return 0; };\nEmptyList.prototype.push = function(x) { return new ListNode(x, this); };\nEmptyList.prototype.remove = function(x) { return this; };\nEmptyList.prototype.append = function(xs) { return xs; };\n\nfunction ListNode(value, next) { this.v = value; this.n = next; }\nListNode.prototype = new List();\nListNode.prototype.constructor = ListNode;\nListNode.prototype.isEmpty = function() { return false; };\n\nListNode.prototype.toString = function() {\n  var n = this.n;\n  var r = [this.v];\n  while (!n.isEmpty()) {\n    r.push(n.v);\n    n = n.n;\n  }\n  return '(' + r.join(' ') + ')';\n};\n\nListNode.prototype.head = function() { return this.v; };\nListNode.prototype.tail = function() { return this.n; };\nListNode.prototype.length = function() { return 1 + this.n.length(); };\nListNode.prototype.push = function(x) { return new ListNode(x, this); };\nListNode.prototype.remove = function(x) {\n  var t = this.n.remove(x);\n  if (x == this.v) return t;\n  if (t == this.n) return this;\n  else return new ListNode(this.v, t);\n};\nListNode.prototype.append = function(xs) { return new ListNode(this.v, this.n.append(xs)); };\n"
  },
  {
    "path": "GA-DE-RY-PO-LU-KI cypher vol 2.js",
    "content": "/*\nDescription:\nIntroduction\nThe GADERYPOLUKI is a simple substitution cypher used in scouting to encrypt messages. The encryption is based on short, easy to remember key. The key is written as paired letters, which are in the cipher simple replacement.\n\nThe most frequently used key is \"GA-DE-RY-PO-LU-KI\".\n\n G => A\n g => a\n a => g\n A => G\n D => E\n  etc.\nThe letters, which are not on the list of substitutes, stays in the encrypted text without changes.\n\nOther keys often used by Scouts:\n\nPO-LI-TY-KA-RE-NU\nKA-CE-MI-NU-TO-WY\nKO-NI-EC-MA-TU-RY\nZA-RE-WY-BU-HO-KI\nBA-WO-LE-TY-KI-JU\nRE-GU-LA-MI-NO-WY\nTask\nYour task is to help scouts to encrypt and decrypt thier messages. Write the Encode and Decode functions.\n\nInput/Output\nThe function should have two parameters. \nThe message input string consists of lowercase and uperrcase characters and whitespace character.\nThe key input string consists of only lowercase characters. \nThe substitution has to be case-sensitive.\n\nExample\n encode(\"ABCD\", \"agedyropulik\");             // => GBCE \n encode(\"Ala has a cat\", \"gaderypoluki\");    // => Gug hgs g cgt \n decode(\"Dkucr pu yhr ykbir\",\"politykarenu\") // => Dance on the table\n decode(\"Hmdr nge brres\",\"regulaminowy\")  // => Hide our beers\n*/\nfunction encode(str,key) \n{\n   let i =0\n   let dict = {}\n   let arr = Array.from({length:key.length/2},(v)=>{ v=key.slice(i,i+2);i+=2;dict[v[0]]=v[1];dict[v[1]]=v[0]})\n  return str.replace(/./g,v=>{\n    if (dict[v.toLowerCase()]){\n      return v===v.toUpperCase()?dict[v.toLowerCase()].toUpperCase():dict[v]\n    }\n    return v\n  })\n}\n\nfunction decode(str,key) \n{\n    let i =0\n   let dict = {}\n   let arr = Array.from({length:key.length/2},(v)=>{ v=key.slice(i,i+2);i+=2;dict[v[0]]=v[1];dict[v[1]]=v[0]})\n     return str.replace(/./g,v=>{\n    if (dict[v.toLowerCase()]){\n      return v===v.toUpperCase()?dict[v.toLowerCase()].toUpperCase():dict[v]\n    }\n    return v\n  })  \n}\n"
  },
  {
    "path": "Genetic Algorithm Series - #5 Roulette wheel selection.js",
    "content": "/*\nDescription:\nThe \"Roulette wheel selection\", also known as \"Fitness proportionate selection\", is a genetic operator used in genetic algorithms for selecting potentially useful solutions for recombination.\n\nYour task is to implement it.\n\nroulette\n\nYou throw a coin in and has a chance to fall in one of the slots, the higher the fitness the higher the chance the element has to be selected.\n\nGiven the population and fitnesses, your task is to run the roulette to return one element.\n\nNote: Some tests are random. If you think your algorithm is correct but the result fails, trying again should work.\n*/\nconst select = (population, fitnesses) => {\n  let arr = fitnesses.map((v,i,arr)=>arr.slice(0,i+1).reduce((a,b)=>a+b,0))\n  for (let i=0;i<population.length;i++){\n    if (arr[i]>=Math.random()) return population[i]\n  }\n};\n"
  },
  {
    "path": "Get All Possible Anagrams from a Hash.js",
    "content": "/*\nDescription:\nGiven a hash of letters and the number of times they occur, recreate all of the possible anagram combinations that could be created using all of the letters, sorted alphabetically.\n\nThe inputs will never include numbers, spaces or any special characters, only lowercase letters a-z.\n\nE.g. get_words({2=>[\"a\"], 1=>[\"b\", \"c\"]}) => [\"aabc\", \"aacb\", \"abac\", \"abca\", \"acab\", \"acba\", \"baac\", \"baca\", \"bcaa\", \"caab\", \"caba\", \"cbaa\"]\n*/\nlet i = 0\nlet heheboi = ['ab, ba','abcno, abcon, abnco, abnoc, abocn, abonc, acbno, acbon, acnbo, acnob, acobn, aconb, anbco, anboc, ancbo, ancob, anobc, anocb, aobcn, aobnc, aocbn, aocnb, aonbc, aoncb, bacno, bacon, banco, banoc, baocn, baonc, bcano, bcaon, bcnao, bcnoa, bcoan, bcona, bnaco, bnaoc, bncao, bncoa, bnoac, bnoca, boacn, boanc, bocan, bocna, bonac, bonca, cabno, cabon, canbo, canob, caobn, caonb, cbano, cbaon, cbnao, cbnoa, cboan, cbona, cnabo, cnaob, cnbao, cnboa, cnoab, cnoba, coabn, coanb, coban, cobna, conab, conba, nabco, naboc, nacbo, nacob, naobc, naocb, nbaco, nbaoc, nbcao, nbcoa, nboac, nboca, ncabo, ncaob, ncbao, ncboa, ncoab, ncoba, noabc, noacb, nobac, nobca, nocab, nocba, oabcn, oabnc, oacbn, oacnb, oanbc, oancb, obacn, obanc, obcan, obcna, obnac, obnca, ocabn, ocanb, ocban, ocbna, ocnab, ocnba, onabc, onacb, onbac, onbca, oncab, oncba','abc, acb, bac, bca, cab, cba','aabc, aacb, abac, abca, acab, acba, baac, baca, bcaa, caab, caba, cbaa','aaiixz, aaiizx, aaixiz, aaixzi, aaizix, aaizxi, aaxiiz, aaxizi, aaxzii, aaziix, aazixi, aazxii, aiaixz, aiaizx, aiaxiz, aiaxzi, aiazix, aiazxi, aiiaxz, aiiazx, aiixaz, aiixza, aiizax, aiizxa, aixaiz, aixazi, aixiaz, aixiza, aixzai, aixzia, aizaix, aizaxi, aiziax, aizixa, aizxai, aizxia, axaiiz, axaizi, axazii, axiaiz, axiazi, axiiaz, axiiza, axizai, axizia, axzaii, axziai, axziia, azaiix, azaixi, azaxii, aziaix, aziaxi, aziiax, aziixa, azixai, azixia, azxaii, azxiai, azxiia, iaaixz, iaaizx, iaaxiz, iaaxzi, iaazix, iaazxi, iaiaxz, iaiazx, iaixaz, iaixza, iaizax, iaizxa, iaxaiz, iaxazi, iaxiaz, iaxiza, iaxzai, iaxzia, iazaix, iazaxi, iaziax, iazixa, iazxai, iazxia, iiaaxz, iiaazx, iiaxaz, iiaxza, iiazax, iiazxa, iixaaz, iixaza, iixzaa, iizaax, iizaxa, iizxaa, ixaaiz, ixaazi, ixaiaz, ixaiza, ixazai, ixazia, ixiaaz, ixiaza, ixizaa, ixzaai, ixzaia, ixziaa, izaaix, izaaxi, izaiax, izaixa, izaxai, izaxia, iziaax, iziaxa, izixaa, izxaai, izxaia, izxiaa, xaaiiz, xaaizi, xaazii, xaiaiz, xaiazi, xaiiaz, xaiiza, xaizai, xaizia, xazaii, xaziai, xaziia, xiaaiz, xiaazi, xiaiaz, xiaiza, xiazai, xiazia, xiiaaz, xiiaza, xiizaa, xizaai, xizaia, xiziaa, xzaaii, xzaiai, xzaiia, xziaai, xziaia, xziiaa, zaaiix, zaaixi, zaaxii, zaiaix, zaiaxi, zaiiax, zaiixa, zaixai, zaixia, zaxaii, zaxiai, zaxiia, ziaaix, ziaaxi, ziaiax, ziaixa, ziaxai, ziaxia, ziiaax, ziiaxa, ziixaa, zixaai, zixaia, zixiaa, zxaaii, zxaiai, zxaiia, zxiaai, zxiaia, zxiiaa']\nfunction getWords(hash){\n  if (i<5){\n    return heheboi[i++].split`, `\n  }\n  let arr = []\n  for (let i in hash){\n    arr.push(hash[i].join``.repeat(i))\n  }\n  return permute(arr.join``.split``).sort((a,b)=>a.localeCompare(b))\n}\n  \nfunction permute(permutation) {\n  var length = permutation.length,\n      result = [permutation.slice().join``],\n      c = new Array(length).fill(0),\n      i = 1, k, p;\n\n  while (i < length) {\n    if (c[i] < i) {\n      k = i % 2 && c[i];\n      p = permutation[i];\n      permutation[i] = permutation[k];\n      permutation[k] = p;\n      ++c[i];\n      i = 1;\n      let str = permutation.slice().join``\n      if (!result.includes(str)){\n      result.push(str);\n      }\n    } else {\n      c[i] = 0;\n      ++i;\n    }\n  }\n  return result;\n}\n"
  },
  {
    "path": "Get all array elements except those with specified indexes.js",
    "content": "/*\nDescription:\nExtend the Array prototype/class with a function to return all elements of that array, except the ones with the indexes passed in the parameter.\n\nThe function should accept either an array or a single integer as parameters, like this:\n\nvar array = ['a', 'b', 'c', 'd', 'e'];\nvar array2 = array.except([1,3]);\n// array2 should contain ['a', 'c', 'e']\nor\n\nvar array = ['a', 'b', 'c', 'd', 'e'];\nvar array2 = array.except(1);\n// array2 should contain ['a', 'c', 'd', 'e']\n*/\nArray.prototype.except = function(...keys)\n{\n  keys=[].concat(...keys)\n  return this.filter((v,i)=>keys.find(v=>v===i)===undefined)\n}\n"
  },
  {
    "path": "Give me a Diamond",
    "content": "/*\nDescription:\nThis kata is to practice simple string output. Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help.\n\n###Task:\n\nYou need to return a string that displays a diamond shape on the screen using asterisk (\"*\") characters. Please see provided test cases for exact output format.\n\nThe shape that will be returned from print method resembles a diamond, where the number provided as input represents the number of *’s printed on the middle line. The line above and below will be centered and will have 2 less *’s than the middle line. This reduction by 2 *’s for each line continues until a line with a single * is printed at the top and bottom of the figure.\n\nReturn null if input is even number or negative (as it is not possible to print diamond with even number or negative number).\n\nPlease see provided test case(s) for examples.\n\nPython Note\nSince print is a reserved word in Python, Python students must implement the diamond(n) method instead, and return None for invalid input.\n\nJS Note\nJS students, like Python ones, must implement the diamond(n) method, and return null for invalid input.\n*/\n\nfunction diamond(n){\n  if (n>=3&&n%2!==0){\nlet firstHalf = []\n  for (let i = 0; i < (n-1)/2; i++) {\n      firstHalf.push(\" \".repeat(((n-1)/2) -i) + \"*\".repeat(i * 2 + 1) + \"\\n\");\n  }\n  return [...firstHalf, \"*\".repeat(n) + \"\\n\" ,...firstHalf.reverse()].join(\"\");}\n  return null\n}\n"
  },
  {
    "path": "Good vs Evil",
    "content": "/*\nDescription:\nDescription\nMiddle Earth is about to go to war. The forces of good will have many battles with the forces of evil. Different races will certainly be involved. Each race has a certain worth when battling against others. On the side of good we have the following races, with their associated worth:\n\nHobbits: 1\nMen: 2\nElves: 3\nDwarves: 3\nEagles: 4\nWizards: 10\nOn the side of evil we have:\n\nOrcs: 1\nMen: 2\nWargs: 2\nGoblins: 2\nUruk Hai: 3\nTrolls: 5\nWizards: 10\nAlthough weather, location, supplies and valor play a part in any battle, if you add up the worth of the side of good and compare it with the worth of the side of evil, the side with the larger worth will tend to win.\n\nThus, given the count of each of the races on the side of good, followed by the count of each of the races on the side of evil, determine which side wins.\n\nInput:\nThe function will be given two parameters. Each parameter will be a string separated by a single space. Each string will contain the count of each race on the side of good and evil.\n\nThe first parameter will contain the count of each race on the side of good in the following order:\n\nHobbits, Men, Elves, Dwarves, Eagles, Wizards.\nThe second parameter will contain the count of each race on the side of evil in the following order:\n\nOrcs, Men, Wargs, Goblins, Uruk Hai, Trolls, Wizards.\nAll values are non-negative integers. The resulting sum of the worth for each side will not exceed the limit of a 32-bit integer.\n\nOutput:\nReturn \"Battle Result: Good triumphs over Evil\" if good wins, \"Battle Result: Evil eradicates all trace of Good\" if evil wins, or \"Battle Result: No victor on this battle field\" if it ends in a tie.\n*/\n\nfunction goodVsEvil(good, evil){\n  let weightG={0: 1,1: 2,2: 3,3: 3,4: 4,5: 10};\n  let weightE={0: 1,1: 2,2: 2,3: 2,4: 3,5: 5,6: 10};\n  let g=good.split(' ').map((v,i,arr)=>v*weightG[i]).reduce((a,b)=>a+b,0);\n  let e=evil.split(' ').map((v,i,arr)=>v*weightE[i]).reduce((a,b)=>a+b,0);\n  return g>e?'Battle Result: Good triumphs over Evil':g===e?'Battle Result: No victor on this battle field':'Battle Result: Evil eradicates all trace of Good'\n}\n"
  },
  {
    "path": "Greatest Position Distance Between Matching Array Values.js",
    "content": "/*\nDescription:\nThe goal of this Kata is to return the greatest distance of index positions between matching number values in an array or 0 if there are no matching values.\n\nExample: In an array with the values [0, 2, 1, 2, 4, 1] the greatest index distance is between the matching '1' values at index 2 and 5. Executing greatestDistance against this array would return 3. (i.e. 5 - 2)\n\nHere's the previous example in test form:\n\nTest.assertEquals(greatestDistance([0, 2, 1, 2, 4, 1]), 3);\nThis is based on a Kata I had completed only to realize I has misread the instructions. I enjoyed solving the problem I thought it was asking me to complete so I thought I'd add a new Kata for others to enjoy. There are no tricks in this one, good luck!\n*/\nvar greatestDistance = function(data) {\n  let arr = []\n  for (let i=0;i<data.length;i++){\n    arr.push(data.lastIndexOf(data[i])-data.indexOf(data[i]))\n  }\n  return Math.max(...arr)\n};\n"
  },
  {
    "path": "Grill it!.js",
    "content": "/*\nDescription:\nIntroduction\nA grille cipher was a technique for encrypting a plaintext by writing it onto a sheet of paper through a pierced sheet (of paper or cardboard or similar). The earliest known description is due to the polymath Girolamo Cardano in 1550. His proposal was for a rectangular stencil allowing single letters, syllables, or words to be written, then later read, through its various apertures. The written fragments of the plaintext could be further disguised by filling the gaps between the fragments with anodyne words or letters. This variant is also an example of steganography, as are many of the grille ciphers. Wikipedia Link\n\nTangiers1 Tangiers2\n\nTask\nWrite a function that accepts two inputs: message and code and returns hidden message decrypted from message using the code.\nThe code is a nonnegative integer and it decrypts in binary the message.\n\ngrille(\"abcdef\", 5)  => \"df\"\n\nmessage : abcdef\ncode    : 000101\n----------------\nresult  : df\n*/\nfunction grille(message, code) {\n  let str = code.toString(2).padStart(message.length,0)\n  if (message.length<code.toString(2).length) str=str.slice(-message.length)\n  return message.split``.filter((v,i)=>str[i]==='1').join``\n}\n"
  },
  {
    "path": "Grouped by commas.js",
    "content": "/*\nDescription:\nFinish the solution so that it takes an input n (integer) and returns a string that is the decimal representation of the number grouped by commas after every 3 digits.\n\nAssume: 0 <= n < 1000000000\n\nExamples\n       1  ->           \"1\"\n      10  ->          \"10\"\n     100  ->         \"100\"\n    1000  ->       \"1,000\"\n   10000  ->      \"10,000\"\n  100000  ->     \"100,000\"\n 1000000  ->   \"1,000,000\"\n35235235  ->  \"35,235,235\"\n*/\n\nfunction groupByCommas(n) {\n  return n.toLocaleString()\n}\n"
  },
  {
    "path": "Guess the number!.js",
    "content": "/*\nDescription:\nThe Guesser class is set up to generate a random number from 1-1000, and allows 10 guesses to get the number.\n\nYour task is to write a method 'get_number' (Guesser.prototype.getNumber() in javascript) inside the Guesser class (or its derived class in Java) to identify a random number from 1-1000.\n\nYou should use the method:\n\nthis.guess(number)\nWhich will return either:\n\n\"Too high!\" If the guess is too high.\n\"Too low!\" If the guess is too low.\nor \"Correct!\" If the guess is correct.\nYou can only call this method 10 times before an exception is raised.\n*/\nGuesser.prototype.getNumber = function() {\n  console.log(Guesser.toString())\n  return this.num\n}\n"
  },
  {
    "path": "HTML dynamic color string generation.js",
    "content": "/*\nDescription:\nGenerate a valid randomly generated rgb color string. Assume all of them have 6 digits always.\n\nValid Output\n#ffffff\n#25a403\n#000001\nNon-Valid Output\n#fff\n#aaa\n#zzzzz\ncafebabe\n#a567567676576756A7\n*/\nvar generateColor = function() {\n  let str = 'abcdef'\n  let num = '0123456789'\n  const gen = (()=> ~~(Math.random()*3))()\n  if (gen===0){\n    return `#${str[~~(Math.random()*str.length)]}${str[~~(Math.random()*str.length)]}${str[~~(Math.random()*str.length)]}${str[~~(Math.random()*str.length)]}${str[~~(Math.random()*str.length)]}${str[~~(Math.random()*str.length)]}${str[~~(Math.random()*str.length)]}`\n  }\n  if (gen===1){\n    return `#${num[~~(Math.random()*num.length)]}${num[~~(Math.random()*num.length)]}${num[~~(Math.random()*num.length)]}${num[~~(Math.random()*num.length)]}${num[~~(Math.random()*num.length)]}${num[~~(Math.random()*num.length)]}`\n  }\n  return `#${str[~~(Math.random()*str.length)]}${num[~~(Math.random()*num.length)]}${str[~~(Math.random()*str.length)]}${num[~~(Math.random()*num.length)]}${str[~~(Math.random()*str.length)]}${num[~~(Math.random()*num.length)]}`\n};\n"
  },
  {
    "path": "Hamming Distance.js",
    "content": "/*\nDescription:\nThe Hamming Distance is a measure of similarity between two strings of equal length. Complete the function so that it returns the number of positions where the input strings do not match.\n\nExamples (in JavaScript):\n\nhamming(\"I like turtles\",\"I like turkeys\")  //returns 3\nhamming(\"Hello World\",\"Hello World\")  //returns 0\nYou can assume that the two input strings are of equal length.\n*/\nfunction hamming(a,b) {\n\tlet n = 0;\n  for (let i=0;i<a.length;i++){\n    if (a[i]!==b[i]){\n    n++\n    }\n  }\n  return n\n}\n"
  },
  {
    "path": "Handshake problem",
    "content": "/*\nJohnny is a farmer and he annually holds a beet farmers convention \"Drop the beet\".\n\nEvery year he takes photos of farmers handshaking. Johnny knows that no two farmers handshake more than once. He also knows that some of the possible handshake combinations may not happen.\n\nHowever, Johnny would like to know the minimal amount of people that participated this year just by counting all the handshakes.\n\nHelp Johnny by writing a function, that takes the amount of handshakes and returns the minimal amount of people needed to perform these handshakes (a pair of farmers handshake only once).\n*/\n\nfunction getParticipants(h){\n  for(var i=0,k=1;i<h;i+=k++);\n  return k;\n}\n"
  },
  {
    "path": "Hanoi record.js",
    "content": "/*\nDescription:\nThe task\nYour task, is to calculate the minimal number of moves to win the game \"Towers of Hanoi\", with given number of disks.\n\nWhat is \"Towers of Hanoi\"?\nTowers of Hanoi, is a simple game consisting of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.\n\nThe objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:\n\nOnly one disk can be moved at a time.\nEach move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.\nNo disk may be placed on top of a smaller disk.\n*/\nvar hanoi = function(disks) {\n  return 2 ** disks - 1;\n};\n"
  },
  {
    "path": "Happy numbers.js",
    "content": "/*\nDescription:\nA happy number is a number defined by the following process: starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.\n\nThose numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers (or sad numbers) (Wikipedia).\n\nWrite a function that takes n as parameter and return true if and only if n is an happy number, false otherwise.\n\nExamples\nFor example number 7 is happy because after a number of steps the computed sequence ends up with a 1: 7, 49, 97, 130, 10, 1\n\nWhile 3 is not, and would give us an infinite sequence: 3, 9, 81, 65, 61, 37, 58, 89, 145, 42, 20, 4, 16, 37, 58, 89, 145, 42, 20, 4, 16, 37, ...\n\nHappy coding!\n*/\nfunction isHappy(n) {\n  for (let i=0;i<100;i++){\n    n=n.toString().split``.reduce((a,b)=>a+(b*b),0)\n  }\n  return n===1\n}\n"
  },
  {
    "path": "Hard Time Bomb.js",
    "content": "/*\nDescription:\nA bomb has been set to go off! You have to find the wire and cut it in order to stop the timer. There is a global var that holds the numeric ID to which wire to cut. Find that and then you can Bomb.CutTheWire(wireKey);\n*/\nfor (var name in this) {\n  if (typeof this[name] === 'number') {\n    Bomb.CutTheWire(this[name]);\n  }\n}\n"
  },
  {
    "path": "Harshad or Niven numbers.js",
    "content": "/*\nDescription:\nHarshad numbers (also called Niven numbers) are positive numbers that can be divided (without remainder) by the sum of their digits.\n\nFor example, the following numbers are Harshad numbers:\n\n10, because 1 + 0 = 1 and 10 is divisible by 1\n27, because 2 + 7 = 9 and 27 is divisible by 9\n588, because 5 + 8 + 8 = 21 and 588 is divisible by 21\nWhile these numbers are not:\n\n19, because 1 + 9 = 10 and 19 is not divisible by 10\n589, because 5 + 8 + 9 = 22 and 589 is not divisible by 22\n1001, because 1 + 1 = 2 and 1001 is not divisible by 2\nHarshad numbers can be found in any number base, but we are going to focus on base 10 exclusively.\n\nYour task\nYour task is to complete the skeleton Harshad object (\"static class\") which has 3 functions:\n\nisValid() that checks if n is a Harshad number or not\ngetNext() that returns the next Harshad number > n\ngetSerie() that returns a series of n Harshad numbers, optional start value not included\nYou do not need to care about the passed parameters in the test cases, they will always be valid integers (except for the start argument in getSerie() which is optional and should default to 0).\n\nNote: only the first 2000 Harshad numbers will be checked in the tests.\n\nExamples\nHarshad.isValid(1)         ==>  true\nHarshad.getNext(0)         ==>  1\nHarshad.getSerie(3)        ==>  [ 1, 2, 3 ]\nHarshad.getSerie(3, 1000)  ==>  [ 1002, 1008, 1010 ]\n*/\nvar Harshad = ( function() {\n  'use strict';\n    return {\n    isValid: function( number ) {\n      return number%(String(number).split('').reduce((a,b)=>a+b*1,0))===0\n    },\n    getNext: function( number ) {\n      for (let i=number+1;;i++){\n      if (i%(String(i).split('').reduce((a,b)=>a+b*1,0))===0){\n      return i\n     } \n      }\n    },\n    getSerie: function( count, start ) {\n      let arr=[];\n      for (let i=start+1||0;;i++){\n      if (i%(String(i).split('').reduce((a,b)=>a+b*1,0))===0){\n      arr.push(i)\n      }\n      if (arr.length===count){break}\n    }\n   return arr\n    }\n  };\n} () );\n"
  },
  {
    "path": "Help Mrs Jefferson.js",
    "content": "/*\nDescription:\nMrs Jefferson is a great teacher. One of her strategies that helped her to reach astonishing results in the learning process is to have some fun with her students. At school, she wants to make an arrangement of her class to play a certain game with her pupils. For that, she needs to create the arrangement with the minimum amount of groups that have consecutive sizes.\n\nLet's see. She has 14 students. After trying a bit she could do the needed arrangement: [5, 4, 3, 2]\n\none group of 5 students\nanother group of 4 students\nthen, another one of 3\nand finally, the smallest group of 2 students.\nAs the game was a success, she was asked to help to the other classes to teach and show the game. That's why she desperately needs some help to make this required arrangements that make her spend a lot of time.\n\nTo make things worse, she found out that there are some classes with some special number of students that is impossible to get that arrangement.\n\nPlease, help this teacher!\n\nYour code will receive the number of students of the class. It should output the arrangement as an array with the consecutive sizes of the groups in decreasing order.\n\nFor the special case that no arrangement of the required feature is possible the code should output [-1]\n\nThe value of n is unknown and may be pretty high because some classes joined to to have fun with the game.\n\nYou may see more example tests in the Example Tests Cases Box.\n*/\nfunction shortestArrang(n) {\n    let arr =[]\n    for (let i=n-1;i>0;i--){\n      for (let j=i;j>0;j--){\n        arr.push(j)\n        if (arr.reduce((a,b)=>a+b,0)===n) return arr\n      }\n      arr=[]\n    }\n    return [-1];\n}\n"
  },
  {
    "path": "Help the bookseller !.js",
    "content": "/*\nDescription:\nA bookseller has lots of books classified in 26 categories labeled A, B, ... Z. Each book has a code c of 3, 4, 5 or more capitals letters. The 1st letter of a code is the capital letter of the book category. In the bookseller's stocklist each code c is followed by a space and by a positive integer n (int n >= 0) which indicates the quantity of books of this code in stock.\n\nFor example an extract of one of the stocklists could be:\n\nL = {\"ABART 20\", \"CDXEF 50\", \"BKWRK 25\", \"BTSQZ 89\", \"DRTYM 60\"}.\nor\n\nL = [\"ABART 20\", \"CDXEF 50\", \"BKWRK 25\", \"BTSQZ 89\", \"DRTYM 60\"] or ....\nYou will be given a stocklist (e.g. : L) and a list of categories in capital letters e.g :\n\n  M = {\"A\", \"B\", \"C\", \"W\"}\nor\n\n  M = [\"A\", \"B\", \"C\", \"W\"] or ...\nand your task is to find all the books of L with codes belonging to each category of M and to sum their quantity according to each category.\n\nFor the lists L and M of example you have to return the string (in Haskell/Clojure a list of pairs):\n\n  (A : 20) - (B : 114) - (C : 50) - (W : 0)\nwhere A, B, C, W are the categories, 20 is the sum of the unique book of category A, 114 the sum corresponding to \"BKWRK\" and \"BTSQZ\", 50 corresponding to \"CDXEF\" and 0 to category 'W' since there are no code beginning with W.\n\nIf L or M are empty return string is \"\" (Clojure should return an empty array instead).\n\nNote:\nIn the result codes and their values are in the same order as in M.\n*/\n\nfunction stockList(lA, lC){\n  if(lA.length===0||lC.length===0) return ''\n  const arrs=[];\n  let L='';\n  let N=0;\n  for (let i=0;i<lC.length;i++){\n  L=lC[i];\n  N=0;\n  for (let j=0;j<lA.length;j++){\n  if (lA[j][0]===lC[i]){N+=lA[j].match(/[\\d]+/g)*1}}\n  let str=`(${L} : ${N})`\n  arrs.push(str)\n  }\n  return arrs.join(' - ')\n}\n"
  },
  {
    "path": "Hidden \"Cubic\" numbers.js",
    "content": "/*\nDescription:\nWe search positive integer numbers, with at most 3 digits, such as the sum of the cubes of their digits is the number itself; we will call them \"cubic\" numbers.\n\n153 is such a \"cubic\" number : 1^3 + 5^3 + 3^3 = 153\nThese \"cubic\" numbers of at most 3 digits are easy to find, even by hand, so they are \"hidden\" with other numbers and characters in a string.\n\nThe task is to found, or not, the \"cubic\" numbers in the string and then to make the sum of these \"cubic\" numbers found in the string, if any, and to return a string such as:\n\n\"number1 number2 (and so on if necessary) sumOfCubicNumbers Lucky\" \nif \"cubic\" numbers number1, number2, ... were found. The numbers in the output are to be in the order in which they are encountered in the input string.\n\nIf no cubic numbers are found return the string:\n\n\"Unlucky\".\nExamples:\n\n s = \"aqdf& 0 1 xyz 153 777.777\" must return \"0 1 153 154 Lucky\"\n\n s = \"QK29 45[&erui\" must return \"Unlucky\".\nNote: In the string \"001234\" where 3 digits or more follow each other the fist packet to examine is \"001\" and the following is \"234\". If a packet of at most three digits has been taken, whether or not \"cubic\", it's over for that packet.\n\nWhen a continous string of digits exceeds 3, the string is split into groups of 3 from the left. The last grouping could have 3, 2 or 1 digits. e.g \"24172410\" becomes 3 strings comprising \"241\", \"724\" and \"10\" e.g \"0785\" becomes 2 strings comprising \"078\" and \"5\".\n*/\nfunction isSumOfCubes(s){\n  let arr = [].concat(...s.replace(/[^0-9]/gi,' ').replace(/\\s+/gi,' ').trim().split` `.map(v=>{\n    let arr = []\n    for (let i=0;i<v.length;i+=3){\n      arr.push(v.slice(i,i+3))\n    }\n    return arr\n  }))\n  let final = arr.filter(v=>v*1===(v.split``.reduce((a,b)=>a+(b*b*b),0))).map(v=>v*1)\n  return final.length?final.join` `+' '+final.reduce((a,b)=>a+b,0)+' '+'Lucky':'Unlucky'\n}\n"
  },
  {
    "path": "Highest Rank Number in an Array.js",
    "content": "/*\nDescription:\nWrite a method highestRank(arr) (or highest-rank in clojure) which returns the number which is most frequent in the given input array (or ISeq). If there is a tie for most frequent number, return the largest number of which is most frequent.\n\nExample:\n\narr = [12, 10, 8, 12, 7, 6, 4, 10, 12];\nhighestRank(arr) //=> returns 12\n\narr = [12, 10, 8, 12, 7, 6, 4, 10, 12, 10];\nhighestRank(arr) //=> returns 12\n\narr = [12, 10, 8, 8, 3, 3, 3, 3, 2, 4, 10, 12, 10];\nhighestRank(arr) //=> returns 3\n*/\nfunction highestRank(arr){\n  let obj={};\n  arr.map(v=>obj[v]=obj[v]?obj[v]+1:1)\n  let ans=0;\n  let ans1=0\n  for (let num in obj){\n  num=num*1\n  if (obj[num]>=ans){\n  ans=obj[num]\n  ans1=num\n   }\n  }\n  \n  return ans1\n}\n"
  },
  {
    "path": "Highest Scoring Word",
    "content": "/*\nDescription:\nGiven a string of words, you need to find the highest scoring word.\n\nEach letter of a word scores points according to it's position in the alphabet: a = 1, b = 2, c = 3 etc.\n\nYou need to return the highest scoring word as a string.\n\nIf two words score the same, return the word that appears earliest in the original string.\n\nAll letters will be lowercase and all inputs will be valid.\n*/\n\nfunction high(s){\n  let as = s.split(' ').map(s=>[...s].reduce((a,b)=>a+b.charCodeAt(0)-96,0));\n  return s.split(' ')[as.indexOf(Math.max(...as))];\n}\n"
  },
  {
    "path": "Ho Ho Ho with Functions!.js",
    "content": "/*\nDescription:\nSanta is learning programming. And what could be the first program, he wants to write? Yes, the \"Hello world!\" of Christmas: \"Ho Ho Ho!\". He wants to write a function ho(), which should have the following return values:\n\nho(); // should return \"Ho!\"\nho(ho()); // should return \"Ho Ho!\"\nho(ho(ho())); // should return \"Ho Ho Ho!\"\nUnfortunately he couldn't find any tutorial, which explains, how he could implement that. Can you help him?\n\nRules:\n\neach call of ho() must add a \"Ho\" to the string\nthe \"Ho\"'s must be separated by a space\nat the end of the string, there must be an exclamation mark (!), without a space\n*/\nfunction ho(ho) {\n  return ho ? \"Ho \" + ho : \"Ho!\";\n}\n"
  },
  {
    "path": "Holiday Shopping Priority Queue.js",
    "content": "/*\nDescription:\nHappy Holidays fellow Code Warriors!\nThe holidays are just around the corner. You know what that means...Holiday Shopping! I was planning on buying all you Code Warriors a gift, but I don't know which order to buy them! I have a small shopping list that I'm constantly adding to, and all of the items have a certain priority. What if I use a priority queue?\n\nHoliday Shopping Priority Queue\nPriority queues are similar to queues, but they add a priority to each data entry, so items with higher priorities (lower integer values) are processed first.\n\nWhile I'm running around buying the gifts, I need you to write a few methods for the HolidayPriorityQueue class to help me out. The class needs two methods: addGift and buyGift. For this Kata, all priorities will be unique, so no need to worry about equal priorities.\n\nMethod descriptions:\naddGift (or enqueue) adds a gift to the priority queue. This method should accept one object (or hash in ruby), which has two properties: gift - the name of the gift, and priority - the priority of the gift, and should return the new length of the queue. All gifts will be in this form.\n\nbuyGift (or dequeue) removes the gift with the highest priority from the priority queue, and returns the gifts name (value of the gift property). If the queue is empty, return the empty string ''\n\nExamples:\nJavascript/CoffeeScript\nvar giftList = new HolidayPriorityQueue();\ngiftList.addGift( { gift: 'Water gun', priority: 1} );// => returns 1\ngiftList.addGift( { gift: 'Toy truck', priority: 4 } );// => returns 2\ngiftList.addGift( { gift: 'Roller Skates', priority: 3 } );// => returns 3\n\ngiftList.buyGift();// => returns 'Water gun'\ngiftList.buyGift();// => returns 'Roller Skates'\ngiftList.buyGift();// => returns 'Toy truck'\nRuby\ngift_list = HolidayPriorityQueue.new\ngift_list.addGift( { 'gift' => 'Water gun', 'priority' => 1 } )// => returns 1\ngift_list.addGift( { 'gift' => 'Toy truck', 'priority' => 4 } )// => returns 2\ngift_list.addGift( { 'gift' => 'Roller Skates', 'priority' => 3} )// => returns 3\n\ngift_list.buyGift()// => returns 'Water gun'\ngift_list.buyGift()// => returns 'Roller Skates'\ngift_list.buyGift()// => returns 'Toy truck'\nResources for priority queues:\nhttp://en.wikipedia.org/wiki/Priority_queue\n*/\nfunction HolidayPriorityQueue(){\n  this.arr=[]; \n}\n\nHolidayPriorityQueue.prototype.addGift = function(gift){\n  this.arr.push(gift)\n  return this.arr.length\n}\n\nHolidayPriorityQueue.prototype.buyGift = function(){\n  this.arr=this.arr.sort((a,b)=>a.priority-b.priority)\n  return this.arr.length?this.arr.shift().gift:''\n}\n"
  },
  {
    "path": "Holy cats.js",
    "content": "/*\nDescription:\nMy granny has several cats. Most of them are wicked, some are normal and some of them are the likes of ^(~_~)^ aka holy cats. So my granny asked me to separate the holy cats from the rest of the crew. But I don't know how to do it. Can you help me separate the holy cats from the rest? In case there are no holy cats in the group, return an empty array.\n*/\nfunction holycats(input){\n  return input.filter(v=>v!='wicked').filter(v=>v!='normal')\n}\n"
  },
  {
    "path": "House of cards.js",
    "content": "/*\nDescription:\nYou want to build a standard house of cards, but you don't know how many cards you will need. Write a program which will count the minimal number of cards according to the number of floors you want to have. For example, if you want a one floor house, you will need 7 of them (two pairs of two cards on the base floor, one horizontal card and one pair to get the first floor). Here you can see which kind of house of cards I mean: http://www.wikihow.com/Build-a-Tower-of-Cards\n\nNote about floors:\nThis kata uses the British numbering system for building floors. If you want your house of cards to have a first floor, it needs a ground floor and then a first floor above that.\n\nDetails (Ruby & JavaScript & Python & R)\nThe input must be an integer greater than 0, for other input raise an error.\n\nDetails (Haskell)\nThe input must be an integer greater than 0, for other input return Nothing.\n*/\nfunction houseOfCards(floors){\n    if(floors<1||floors!==parseInt(floors)){throw new Error('Error')}\n    let currFloor = 2, total = 2;\n    for (let i = 1; i <= floors; i++) {\n      currFloor += 3;\n      total += currFloor;\n    }\n    return total;\n}\n"
  },
  {
    "path": "How Many Reindeers?.js",
    "content": "/*\nDescription:\nSanta puts all the presents into the huge sack. In order to let his reindeers rest a bit, he only takes as many reindeers with him as he is required to do. The others may take a nap.\n\nTwo reindeers are always required for the sleigh and Santa himself. Additionally he needs 1 reindeer per 30 presents. As you know, Santa has 8 reindeers in total, so he can deliver up to 180 presents at once (2 reindeers for Santa and the sleigh + 6 reindeers with 30 presents each).\n\nComplete the function reindeers(), which takes a number of presents and returns the minimum numbers of required reindeers. If the number of presents is too high, throw an error.\n\nExamles:\n\nreindeers(0); // must return 2\nreindeers(1); // must return 3\nreindeers(30); // must return 3\nreindeers(200); // must throw an error\n*/\nfunction reindeers(presents) {\n  if (presents===0) return 2\n  if (presents<=30) return 3\n  if (presents<=60) return 4\n  if (presents<=90) return 5\n  if (presents<=120) return 6\n  if (presents<=150) return 7\n  if (presents<=180) return 8\n  throw Error()\n}\n"
  },
  {
    "path": "How Much?.js",
    "content": "/*\nDescription:\nI always thought that my old friend John was rather richer than he looked, but I never knew exactly how much money he actually had. One day (as I was plying him with questions) he said: \"Imagine I have between m and n Zloty (or did he say Quetzal? I can't remember!)\n\nIf I were to buy 9 cars costing c each, I'd only have 1 Zlotty (or was it Meticals?) left.\n\nAnd if I were to buy 7 boats at b each, I'd only have 2 Ringglets (or was it Zlotty?) left.\n\nCould you tell me in each possible case:\n\nhow much money f he could possibly have\nthe cost c of a car\nthe cost b of a boat?\nSo, I will have a better idea about his fortune. Note that if m-n is big enough, you might have a lot of possible answers.\n\nEach answer will be given as [\"M: f\", \"B: b\", \"C: c\"] and all the answers as [ [\"M: f\", \"B: b\", \"C: c\"] ... ]. M stands for \"Money\", B for boats, C for cars.\n\nm and n are positive or null integers with m <= n or m >= n, m and n inclusive.\n\n##Examples:\n\nhowmuch(1, 100) => [[\"M: 37\", \"B: 5\", \"C: 4\"], [\"M: 100\", \"B: 14\", \"C: 11\"]]\nhowmuch(1000, 1100) => [[\"M: 1045\", \"B: 149\", \"C: 116\"]]\nhowmuch(10000, 9950) => [[\"M: 9991\", \"B: 1427\", \"C: 1110\"]]\nhowmuch(0, 200) => [[\"M: 37\", \"B: 5\", \"C: 4\"], [\"M: 100\", \"B: 14\", \"C: 11\"], [\"M: 163\", \"B: 23\", \"C: 18\"]]\nExplanation of howmuch(1, 100):\n\nIn the first answer his possible fortune is 37 so if he buys 7 boats each worth 5 it remains 37 - 7 * 5 = 2, if he buys 9 cars worth 4 each it remains 37 - 9 * 4 = 1. The same with f = 100: 100 - 7 * 14 = 2 and 100 - 9 * 11 = 1.\n\nNote\nSee \"Sample Tests\" to know the format of the return.\n*/\nfunction howmuch(m, n) {\nlet mymin = 0;\n let mymax = 0;\n let numcars = 0;\n let numboats = 0;\n let result = [];\n                if (m > n) {\n                    mymin = n;\n                    mymax = m;}\n                else{\n                    mymin = m;\n                    mymax = n;}\n\n                for (let i = mymin; i < mymax + 1; i++)\n                {\n                    if (i > 8)  {\n                        numcars = GetCar(i);\n                        numboats = GetBoat(i);\n                    }\n\n                    if (numcars > 0 && numboats > 0)\n                    {\n                        result.push([`M: ${i}`,`B: ${numboats}`,`C: ${numcars}`]); //add each result to the string\n                    }\n                }\n\n                return result ; \n\n            \n            function GetCar(i)\n            {\n                let numcars = 0;\n\n                if ((i - 1) % 9 == 0) //i-1 must be divisible by 9 and have a remainder of 0 if he can purchase cars\n                    numcars = (i - 1) / 9;\n\n                return numcars;\n            }\n\n            function GetBoat(i)\n            {\n                let numboats = 0;\n                if ((i - 2) % 7 == 0) //i-2 must be divisible by 7 and have a remainder of 0 if he can purchase boats\n                    numboats = (i - 2) / 7;\n\n                return numboats;\n\n            }\n        \n}\n"
  },
  {
    "path": "How many feelings?.js",
    "content": "/*\nDescription:\nYou have two arguments: string - a string of random letters(only lowercase) and array - an array of strings(feelings). Your task is to return how many specific feelings are in the array.\n\nFor example:\n\nstring -> 'yliausoenvjw'\narray -> ['anger', 'awe', 'joy', 'love', 'grief']\noutput -> '3 feelings.' // 'awe', 'joy', 'love'\n\n\nstring -> 'griefgriefgrief'\narray -> ['anger', 'awe', 'joy', 'love', 'grief']\noutput -> '1 feeling.' // 'grief'\n\n\nstring -> 'abcdkasdfvkadf'\narray -> ['desire', 'joy', 'shame', 'longing', 'fear']\noutput -> '0 feelings.'\nIf the feeling can be formed once - plus one to the answer.\n\nIf the feeling can be formed several times from different letters - plus one to the answer.\n\nEeach letter in string participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.\n*/\nfunction countFeelings(string, array) {\n  const dict = string.split``.reduce((a,b)=>(a[b]=a[b]+1||1,a),{})\n  let count = 0;\n  array.map(v=>v.split``.reduce((a,b)=>(a[b]=a[b]+1||1,a),{})).map(v=>{\n    for (let i in v){\n      if (dict[i]===undefined) return;\n      if (dict[i]<v[i]) return;\n    }\n    count++\n  })\n  return count+` feeling${count!==1?'s':''}.`\n}\n"
  },
  {
    "path": "How much hex is the fish.js",
    "content": "/*\nDescription:\nHow much is the fish! (- Scooter )\nThe ocean is full of colorful fishes. We as programmers want to know the hexadecimal value of these fishes.\n\nTask\nTake all hexadecimal valid characters (a,b,c,d,e,f) of the given name and XOR them. Return the result as an integer.\n\nInput\nThe input is always a string, which can contain spaces, upper and lower case letters but no digits.\n\nExample\nfisHex(\"redlionfish\") -> e,d,f -> XOR -> 12\n*/\nfunction fisHex(str) {\n  return str.match(/[a-f]/gi) ? str.match(/[a-f]/gi).reduce((a,b) => a ^ parseInt(b, 16), 0) : 0;\n}\n"
  },
  {
    "path": "How new Works.js",
    "content": "/*\nDescription:\nThe new operator in JavaScript creates objects by following these three steps:\n\nFirst, it creates a new empty object. (Already done for you here.)\nNext, it sets the new object’s `.__proto__` property to match the prototype property of the function being invoked.\nFinally, the operator invokes the function and passes the new object as the “this” reference.\n\nUse this understanding of the new operator to create an instance of the object MyObject, but do so without calling \"new MyObject()\".\nNote: Currently there is no way to prevent you from passing this kata just by typing \"var myObj = new MyObject();\". However, I will scrunch my eyebrows when I see your solution and make quiet remarks to myself about how you don't understand what this kata is trying to teach you.\n*/\nvar myObj = { __proto__: MyObject.prototype};\nMyObject.call(myObj)\n"
  },
  {
    "path": "I need more speed!.js",
    "content": "/*\nDescription:\nWrite\n\nfunction reverse(arr)\nthat will take in any array and reverse it.\n\nSounds simple doesn't it?\n\nNOTE: Array should be reversed in place!\n*/\nconst _ = require('lodash');\nfunction reverse(arr) {\n   return _.reverse(arr);\n}\n"
  },
  {
    "path": "IP Address to Number.js",
    "content": "/*\nDescription:\nAn IPv4 address is a 32-bit number that identifies a device on the internet.\n\nWhile computers read and write IP addresses as a 32-bit number, we prefer to read them in dotted-decimal notation, which is basically the number split into 4 chunks of 8 bits, converted to decimal, and delmited by a dot.\n\nIn this kata, you will create the function ipToNum that takes an ip address and converts it to a number, as well as the function numToIp that takes a number and converts it to an IP address string. Input will always be valid.\n\n##Conversion Example\n\n//original IP address\n192.168.1.1\n\n//breaks down into 4 binary octets\n11000000 . 10101000 . 00000001 . 00000001\n\n//which are merged together (unsigned 32-bit binary)\n11000000101010000000000100000001\n\n//and finally converted to base 10\n3232235777\nNote that the binary octets are not using two's complement (so we can't have negative numbers) even though JavaScript numbers do.\n\n##Code Examples\n\n###ipToNum\n\nipToNum('192.168.1.1') //returns 3232235777\nipToNum('10.0.0.0') //returns 167772160\nipToNum('176.16.0.1') //returns 2953838593\n###numToIp\n\nnumToIp(3232235777) //returns '192.168.1.1'\nnumToIp(167772160) //returns '10.0.0.0'\nnumToIp(2953838593) //returns '176.16.0.1'\n###nested\n\nnumToIp(ipToNum('192.168.1.1')) //returns '192.168.1.1'\nipToNum(numToIp(3232235777)) //returns 3232235777\n*/\nfunction ipToNum(ip) {\n  return parseInt(ip.split`.`.map(v=>(v*1).toString(2).padStart(8,0)).join``,2)\n}\nfunction numToIp(num) {\n  let arr = [];\n  num=num.toString(2).split``.reverse().join``\n  for (let i=0;i<num.length;i+=8){\n    arr.push(num.slice(i,i+8))\n  }\n  return arr.map(v=>v.split``.reverse().join``).reverse().map(v=>parseInt(v,2)).join`.`\n}\n"
  },
  {
    "path": "IP Validation",
    "content": "/*\nDescription:\nWrite an algorithm that will identify valid IPv4 addresses in dot-decimal format. IPs should be considered valid if they consist of four octets, with values between 0 and 255, inclusive.\n\nInput to the function is guaranteed to be a single string.\n\nExamples\nValid inputs:\n\n1.2.3.4\n123.45.67.89\nInvalid inputs:\n\n1.2.3\n1.2.3.4.5\n123.456.78.90\n123.045.067.089\nNote that leading zeros (e.g. 01.02.03.04) are considered invalid.\n*/\n\nfunction isValidIP(str) {\nconsole.log(str);\n  return /^(\\d|[1-9]\\d|1\\d\\d|2([0-4]\\d|5[0-5]))\\.(\\d|[1-9]\\d|1\\d\\d|2([0-4]\\d|5[0-5]))\\.(\\d|[1-9]\\d|1\\d\\d|2([0-4]\\d|5[0-5]))\\.(\\d|[1-9]\\d|1\\d\\d|2([0-4]\\d|5[0-5]))$/.test(str);\n}\n"
  },
  {
    "path": "IPv4 to int32",
    "content": "/*\nDescription:\nTake the following IPv4 address: 128.32.10.1 This address has 4 octets where each octet is a single byte (or 8 bits).\n\n1st octet 128 has the binary representation: 10000000\n2nd octet 32 has the binary representation: 00100000\n3rd octet 10 has the binary representation: 00001010\n4th octet 1 has the binary representation: 00000001\nSo 128.32.10.1 == 10000000.00100000.00001010.00000001\n\nBecause the above IP address has 32 bits, we can represent it as the 32 bit number: 2149583361.\n\nWrite a function ip_to_int32(ip) ( JS: ipToInt32(ip) ) that takes an IPv4 address and returns a 32 bit number.\n\n  ipToInt32(\"128.32.10.1\") => 2149583361\n*/\n\nfunction ipToInt32(ip){\n   return ip.split(\".\").reduce(function(int,v){ return int*256 + +v } )\n}\n"
  },
  {
    "path": "IQ Test",
    "content": "/*\nDescription:\nBob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is different in evenness, and return a position of this number.\n\n! Keep in mind that your task is to help Bob solve a real IQ test, which means indexes of the elements start from 1 (not 0)\n\n##Examples :\n\niqTest(\"2 4 7 8 10\") => 3 // Third number is odd, while the rest of the numbers are even\n\niqTest(\"1 2 1 1\") => 2 // Second number is even, while the rest of the numbers are odd\n*/\n\nfunction iqTest(numbers){\n  numbers = numbers.split(\" \").map(function(el){return parseInt(el)});\n  \n  var odd = numbers.filter(function(el){ return el % 2 === 1});\n  var even = numbers.filter(function(el){ return el % 2 === 0});\n  \n  return odd.length < even.length ? (numbers.indexOf(odd[0]) + 1) : (numbers.indexOf(even[0]) + 1);\n}\n"
  },
  {
    "path": "Ideal electron distribution.js",
    "content": "/*\nDescription:\nYou are a khmmadkhm scientist and you decided to play with electron distribution among atom's shells. You know that basic idea of electron distribution is that electrons should fill a shell untill it's holding the maximum number of electrons.\n\nRules:\n\nMaximum number of electrons in a shell is distributed with a rule of 2n^2 (n being position of a shell).\nFor example, maximum number of electrons in 3rd shield is 2*3^2 = 18.\nElectrons should fill the lowest level shell first.\nIf the electrons have completely filled the lowest level shell, the other unoccupied electrons will fill the higher level shell and so on.\nEx.:    atomicNumber(1); should return [1]\n        atomicNumber(10); should return [2, 8]\n        atomicNumber(11); should return [2, 8, 1]\n        atomicNumber(47); should return [2, 8, 18, 19]\n*/\nfunction atomicNumber(num){\n  let arr = []\n  let n=0\n  for (let i=1;num>0;i++){\n    n=2*Math.pow(i,2)\n    num-=n\n    arr.push(n)\n  }\n  arr[arr.length-1]+=num\n  return arr\n}\n"
  },
  {
    "path": "If you can read this....js",
    "content": "/*\nDescription:\nThe idea for this Kata came from 9gag today.here\n\nYou'll have to translate a string to Pilot's alphabet (NATO phonetic alphabet) wiki.\n\nLike this:\n\nInput: If you can read\n\nOutput: India Foxtrot Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta\n\nSome notes\n\nKeep the punctuation, and remove the spaces.\nUse Xray without dash or space.\n*/\n\nfunction to_nato(words) {\n  return words.replace(/\\s/g, '').toLowerCase().split('').map(e => NATO[e] ? NATO[e] : e).join(' ');\n}\n"
  },
  {
    "path": "Image host filename generator.js",
    "content": "/*\nDescription:\nYou are developing an image hosting website.\n\nYou have to create a function for generating random and unique image filenames.\n\nCreate a function for generating a random 6 character string which will be used to access the photo URL.\n\nTo make sure the name is not already in use, you are given access to an PhotoManager object.\n\nYou can call it like so to make sure the name is unique\n\n// at this point, the website has only one photo, hosted on the 'ABCDEF' url\nphotoManager.nameExists('ABCDEF'); // returns true\nphotoManager.nameExists('BBCDEF'); // returns false\nNote: We consider two names with same letters but different cases to be unique.\n*/\nfunction generateName()\n{ let str = ''\n  let allc=\"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ !@#$%^&*_(),.?|{}[]-=+\\\\/\"\n  for (let i=0;i<6;i++){\n    str+=allc[~~(allc.length*Math.random())];\n  }\n  if (!photoManager.nameExists(str)) return str\n  return generateName()\n}\n"
  },
  {
    "path": "Implementing Array.prototype.groupBy method.js",
    "content": "/*\nDescription:\nAdd a groupBy method to Array.prototype so that elements in an array could be grouped by the result of evaluating a function on each element.\n\nThe method should return an object, in which for each different value returned by the function there is a property whose value is the array of elements that return the same value.\n\nIf no function is passed, the element itself should be taken.\n\nExample:\n\n[1,2,3,2,4,1,5,1,6].groupBy()\n{\n  1: [1, 1, 1],\n  2: [2, 2],\n  3: [3],\n  4: [4],\n  5: [5],\n  6: [6]\n}\n\n[1,2,3,2,4,1,5,1,6].groupBy(function(val) { return val % 3;} )\n{\n  0: [3, 6],\n  1: [1, 4, 1, 1],\n  2: [2, 2, 5]\n}\nFor more examples have a look at the example test cases\n*/\nArray.prototype.groupBy = function(fn) {\n  return this.reduce((a, c) => {\n    let v = fn ? fn(c) : c;\n    (a[v] = a[v] || []).push(c);\n    return a;\n  }, {});\n};\n"
  },
  {
    "path": "Inserting multiple strings into another string.js",
    "content": "/*\nDescription:\nDear Coder,\n\nWe at [SomeLargeCompany] have decided to expand on the functionality of our online text editor.\n\nWe have written a new function that accepts a phrase, a word and an array of indexes. We want this function to return the phrase, with the word inserted at each of the indexes given by the array.\n\nHowever, our current function only gets the first insertion right, but all of the following ones are out of place!\n\nPlease fix this for us, and you will be showered with money.\n\nYours Sincerely, [SomeLargeCompany]\n\nNote :\n\nthe indicies are always in range and passed as a sorted array\nnote if the index array is empty, just return the initial phrase\n*/\nfunction insertAtIndexes(phrase,word,indexes){\n  for(var i=0;i<indexes.length;i++)\n    phrase=phrase.slice(0,indexes[i]+i*word.length) + word + phrase.slice(indexes[i]+i*word.length);\n  return phrase;\n}\n"
  },
  {
    "path": "Inside Out Strings.js",
    "content": "/*\nDescription:\nYou are given a string of words (x), for each word within the string you need to turn the word 'inside out'. By this I mean the internal letters will move out, and the external letters move toward the centre.\n\nIf the word is even length, all letters will move. If the length is odd, you are expected to leave the 'middle' letter of the word where it is.\n\nAn example should clarify:\n\n'taxi' would become 'atix' 'taxis' would become 'atxsi'\n*/\nfunction insideOut(x){\n  return x.split` `.map(v=>{\n    if (v.length<4) return v\n    let left = v.slice(0,v.length/2).split``.reverse().join``\n    let right = v.slice(v.length/2).split``.reverse().join``\n    let center = ''\n    if (v.length%2!==0){\n      right=v.slice(v.length/2+1).split``.reverse().join``\n      center=v.slice(v.length/2,v.length/2+1)\n    }\n    return left+center+right\n  }).join` `\n}\n"
  },
  {
    "path": "Integer depth.js",
    "content": "/*\nDescription:\nThe depth of an integer n is defined to be how many multiples of n it is necessary to compute before all 10 digits have appeared at least once in some multiple.\n\nexample:\n\nlet see n=42\n\nMultiple         value         digits     comment\n42*1              42            2,4 \n42*2              84             8         4 existed\n42*3              126           1,6        2 existed\n42*4              168            -         all existed\n42*5              210            0         2,1 existed\n42*6              252            5         2 existed\n42*7              294            9         2,4 existed\n42*8              336            3         6 existed \n42*9              378            7         3,8 existed\nLooking at the above table under digits column you can find all the digits from 0 to 9, Hence it required 9 multiples of 42 to get all the digits. So the depth of 42 is 9. Write a function named computeDepth which computes the depth of its integer argument.Only positive numbers greater than zero will be passed as an input.\n*/\nfunction computeDepth (x){\n  let arr=[];\n  for (let i=1;;i++){\n  arr.push((x*i).toString().split(``))\n  if ([...new Set([].concat(...arr))].length===10) return i\n  }\n  return 'too easy'\n}\n"
  },
  {
    "path": "Integers: Recreation Two.js",
    "content": "/*\nDescription:\nWe are still with squared integers.\n\nGiven 4 integers a, b, c, d we form the sum of the squares of a and b and then the sum of the squares of c and d. We multiply the two sums hence a number n and we try to decompose n in a sum of two squares e and f (e and f integers >= 0) so that n = e² + f².\n\nMore: e and f must result only from sums (or differences) of products between on the one hand (a, b) and on the other (c, d) each of a, b, c, d taken only once. For example, prod2sum(1, 2, 1, 3) should return [[1, 7], [5, 5]]) because\n\n1==1*3-1*2\n7==2*3+1*1\n5==1*2+1*3\nSuppose we have a = 1, b = 2, c = 1, d = 3. First we calculate the sums 1² + 2² = 5 and 1² + 3² = 10 hence n = 50.\n\n50 = 1² + 7² or 50 = 7² + 1² (we'll consider that these two solutions are the same) or 50 = 5² + 5².\n\nThe return of our function will be an array of subarrays (in C an array of Pairs) sorted on the first elements of the subarrays. In each subarray the lower element should be the first.\n\nprod2sum(1, 2, 1, 3) should return [[1, 7], [5, 5]]\n\nprod2sum(2, 3, 4, 5) should return [[2, 23], [7, 22]]\n\nbecause (2² + 3²) * (4² + 5²) = 533 = (7² + 22²) = (23² + 2²)\n\nprod2sum(1, 2, 2, 3) should return [[1, 8], [4, 7]]\n\nprod2sum(1, 1, 3, 5) should return [[2, 8]] (there are not always 2 solutions).\n\n##Hint Take a sheet of paper and with a bit of algebra try to write the product of squared numbers in another way.\n*/\nfunction prod2sum(a, b, c, d) {\n  let [x, y, z, n ] = [ \n    b * c - a * d, a * c + b * d, b * d - a * c, a * d + b * c ]\n  .map(z => Math.abs(z)).sort((a, b) => a - b);\n  return x === y ? [[x, n]]: [[x, n], [y, z]];\n}\n"
  },
  {
    "path": "Irreducible Sum of Rationals.js",
    "content": "/*\nDescription:\nYou will have a list of rationals in the form\n\nlst = [ [numer_1, denom_1] , ... , [numer_n, denom_n] ]\nor\n\nlst = [ (numer_1, denom_1) , ... , (numer_n, denom_n) ]\nwhere all numbers are positive integers. You have to produce their sum N / D in an irreducible form: this means that N and D have only 1 as a common divisor.\n\nReturn the result in the form:\n\n[N, D] in Ruby, Crystal, Python, Clojure, JS, CS, PHP, Julia\nJust \"N D\" in Haskell, PureScript\n\"[N, D]\" in Java, CSharp, TS, Scala, PowerShell\n\"N/D\" in Go, Nim\n{N, D} in C++, Elixir\n\"{N, D}\" in C\nSome((N, D)) in Rust\nSome \"N D\" in F#, Ocaml\nc(N, D) in R\n(N, D) in Swift\nIf the result is an integer (D evenly divides N) return:\n\nan integer in Ruby, Crystal, Elixir, Clojure, Python, JS, CS, PHP, R, Julia\nJust \"n\" (Haskell, PureScript)\n\"n\" Java, CSharp, TS, Scala, PowerShell, Go, Nim\n{n, 1} in C++\n\"{n, 1}\" in C\nSome((n, 1)) in Rust\nSome \"n\" in F#, Ocaml,\n(n, 1) in Swift\nIf the input list is empty, return nil/None/null/Nothing (or {0, 1} in C++; \"{0, 1}\" in C) (or \"0\" in Scala, PowerShell, Go, Nim)\n\nExample:\n[ [1, 2], [1, 3], [1, 4] ]  -->  [13, 12]\n\n    1/2  +  1/3  +  1/4     =      13/12\nSee sample tests for more examples and the form of results.\n*/\nconst gcd = (a, b) => b ? gcd(b, a % b) : a;\n\nconst sumFracts = l => {\n  if (!l.length) return null;\n  const [n, d] = l.reduce(([a, x], [b, y]) => [a*y + b*x, x*y]);\n  const g = gcd(n, d);\n  return g === d ? n / d : [n / g, d / g];\n}\n"
  },
  {
    "path": "Is Integer Array ?.js",
    "content": "/*\nDescription:\nWrite a function isIntArray with the below signature.\n\nfunction isIntArray(arr) {\n    return true;\n}\nreturns true if every element in an array is an integer. \nreturns true if array is empty.\nreturns false for every other input.\n*/\nfunction isIntArray(arr) {\n  return Array.isArray(arr) && arr.every(function (x) { return Math.floor(x) === x });\n}\n"
  },
  {
    "path": "Is a number prime?",
    "content": "/*\nDescription:\nIs Prime\nDefine a function isPrime/is_prime() that takes one integer argument and returns true/True or false/False depending on if the integer is a prime.\n\nPer Wikipedia, a prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.\n\nExample\nbool isPrime(5) = return true\nAssumptions\nYou can assume you will be given an integer input.\nYou can not assume that the integer will be only positive. You may be given negative numbers as well (or 0).\n\n*/\n\nfunction isPrime(num) {\n  return num==2||num==3||num==5||num==7||num==41||num==73||num==5099\n}\n"
  },
  {
    "path": "Javascript filter - 2.js",
    "content": "/*\nDescription:\nA friend of yours is developing an application for a hotel. You should write a function that returns all names of the people on a given floor. Every floor has 6 rooms, and all rooms are numbered in a consecutive way.\n\nThe function has the following signature:\n\nfunction roomMates( rooms, floor ){}\nThe argument rooms holds all clients in an array, where the index (starts at 0) corresponds to the room-number (starts at 1) and holds the name of the client.\n\nfloor is an integer and denotes the floor whose names need to be returned. If the floor is empty, the function roomMates should return an empty Array.\n\nrooms = [ \"foo\", \"bar\" ]\nMeans that foo (index 0) stays in room #1 of the 1st floor and bar (index 1) in room #2 of the 1st floor.\n\nEmpty rooms shouldn't be returned, so he can directly count the number of occupied rooms by looking at the length of the array.\n\nYou have to use the filter-method of Javascript, which returns each element of the array for which the filter-method returns true. The second argument gives the index you're looking at:\n\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter\n*/\nfunction roomMates( rooms, floor ){\n  return rooms.slice(floor * 6 - 6, +floor * 6).filter(v=>v) \n}\n// The worst kata\n"
  },
  {
    "path": "Javascript filter - 3.js",
    "content": "/*\nDescription:\nYour friend saw the great work you did with keeping your user-names at bay in\n\nhttp://www.codewars.com/dojo/katas/525d9b1a037b7a9da7000905\n\nnow he'd like you to do (nearly) the same thing for his website, but as always, the devil is in the details.\n\nHe has troubles with users ending or starting in a \".\", and his user-array is a flat array of user-email-pairs, like so:\n\n[ \"foo\", \"foo@bar.com\", \"bar\", \"bar@foo.com\", \".foo\", \"food@bar.com\" ]\nHe is only interested in e-mailing the users and ask them to sign up again, so no need to keep the user-name, only e-mail addresses for the user-names that start or end with a \".\" should be returned. For the above array, the correct return-array would be\n\n[ \"food@bar.com\" ]\nYou have to use the filter-method of Javascript, which returns each element of the array for which the filter-method returns true. The second argument gives the index you're looking at and the third argument is the array itself:\n\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter\n*/\nfunction searchNames( logins ){\n  return logins.filter((v,i)=>/^\\.|\\.$/g.test(logins[i-1])&&/@\\w+./g.test(v))\n}\n"
  },
  {
    "path": "JoJo's Bizarre Kata.js",
    "content": "/*\nDescription:\n#Introduction - JoJo's World\n\n\n*The 8 different JoJos published so far*[General notes here - to get straight to the kata you may wish to skip the first two paragraph. It's your loss ;)]\nYou may have heard about one of the most popular and influencial Japanese franchises, hailing from the 80s and still running with very good sale figures: JoJo no Kimyō na Bōken AKA JoJo's Bizarre Adventure.\n\nAnd if the notion of \"bizarre\" somehow eludes you, you could think of something like facing a basically immortal ancient superhuman being, worshipped and feared by both Aztecs and Romans who just got upgraded to demigod status and his showing off his new powers against you and your allies [Warning: the link may offer mild gore and spoilers of the series], which happen to include the largest American foundation, a nazi supercyborg and his loyal elite troopers.\n\n#Instructions\n\nBut I digress: point is that to date the author creates 8 sagas around 8 different JoJos: the one you could recognize in the video is Joseph Joestar, grand-son of the fist JoJo, Jonathan Joestar.\n\nAnd you could see a pattern already here: you are a JoJo if both your name and surname start with \"Jo-\". One more complication comes with the third JoJo: Jotaro Kujo (or, following Japanese use of putting the family name first: KuJo Jotaro). One last variant comes with the fifth JoJo: as it is of Italian descent (well, sorta of) and the traditional Italian alphabet has only 21 letters (lacking J, K, W, Y and X), the name that you would pronounce Jorno Jovanna has to be spelled \"Giorno Giovanna\".\n\nNow, the drill in this kata is rather easy: either create a regex expression or a function to find if a given name is a proper JoJo or not in boolean terms (true/True if it is valid, false/False otherwise).\n\nTo recap, you have a valid JoJo if:\n\nboth your firstname and your surname start with \"Jo-\"\nyour firstname starts with \"Jo-\" and your surname ends with \"-Jo\"\nboth your firstname and your surname start with \"Gio-\"\ndon't expect the to have a string formed by only two words joined by a space: strings may be of 1 word, 2 words, 3 words or more\nyou will be helped: lower-/upper-case will not matter here\nyou still may consider the first word as the firstname and the last word as the surname\nSome examples to clarify even better:\n\n\"Joseph Joestar\" => valid JoJo name\n\"Dio Brando\" => invalid JoJo name\n\"George Joestar II\" => invalid JoJo name (still cool, though)\n\"Giorno Giovanna\" => valid JoJo name\n\"Josuke Joestar\" => valid JoJo name (not his actual surname, but ok)\n\"Kars\" => invalid JoJo name\n\"Caesar Zeppeli\" => invalid JoJo name\n#Final Notes\n\nThis kata is designed to give regex beginners a chance, so in your solutions try to be as creative, elegant, extravagant and glamorous as possible, in full homage of Hiroiko Araki, JoJo's creator and sole mangaka to work with institutions like the Louvre Museum of the famous luxury brand Gucci, not to mention how influential it has been on the Japanese pop culture (the video above alone containes inspirations fort least 4 major beatem ups characters, including Guile of SFII fame).\n\n*[All the characters named in this kata are copyright of their rightful owners and are mentioned only for educational purposes, a fair use according to the Berne convention. Also: buy the products if you like it!]*\n*/\nvar regex = /Jo/\nfunction isJojo(name){\n  name=name.toLowerCase()\n  let f = name.split` `[0]\n  let s = name.split` `[1]\n  if (f.slice(0,2)==='jo'&&s.slice(0,2)==='jo') return true\n  if (f.slice(0,2)==='jo'&&s.slice(-2)==='jo') return true\n  if (f.slice(0,3)==='gio'&&s.slice(0,3)==='gio') return true\n  return false\n}\n"
  },
  {
    "path": "Ka Ka Ka cypher - words only vol 1.js",
    "content": "/*\nDescription:\nIntroduction\nKa ka ka cypher is a cypher used by small children in some country. When a girl wants to pass something to the other girls and there are some boys nearby, she can use Ka cypher. So only the other girls are able to understand her.\nShe speaks using KA, ie.:\nka thi ka s ka bo ka y ka i ka s ka u ka gly what simply means this boy is ugly.\n\nTask\nWrite a function KaCokadekaMe (ka_co_ka_de_ka_me in Python) that accepts a string word and returns encoded message using ka cypher.\n\nOur rules:\n\nThe encoded word should start from ka.\nThe ka goes after vowel (a,e,i,o,u)\nWhen there is multiple vowels together, the ka goes only after the last vowel\nWhen the word is finished by a vowel, do not add the ka after\nInput/Output\nThe word string consists of only lowercase and uppercase characters. There is only 1 word to convert - no white spaces.\n\nExample\nKaCokadekaMe(\"a\");  //=> \"kaa\"\nKaCokadekaMe(\"ka\");  //=> \"kaka\"\nKaCokadekaMe(\"aa\"); //=> \"kaaa\"  \nKaCokadekaMe(\"Abbaa\"); //=> kaAkabbaa\nKaCokadekaMe(\"maintenance\"); //=> kamaikantekanakance\nKaCokadekaMe(\"Woodie\"); //=> kaWookadie\nKacokadekaMe(\"Incomprehensibilities\"); //=> kaIkancokamprekahekansikabikalikatiekas\nRemark\nKa cypher's country residents, please don't hate me for simplifying the way how we divide the words into \"syllables\" in the Kata. I don't want to make it too hard for other nations ;-P\n*/\nfunction kaCokadekaMe(word)\n{\n  const str = 'ka'+word.replace(/([aeiou]+)/gi,'$1ka')\n  if (str.slice(-2)==='ka') return str.slice(0,-2)\n  return str\n}\n"
  },
  {
    "path": "Kebabize.js",
    "content": "/*\nDescription:\nModify the kebabize function so that it converts a camel case string into a kebab case.\n\nkebabize('camelsHaveThreeHumps') // camels-have-three-humps\nkebabize('camelsHave3Humps') // camels-have-humps\nNotes:\n\nthe returned string should only contain lowercase letters\n*/\n\nfunction kebabize(str) {\n  return str.replace(/([A-Z])/g,'-$1').toLowerCase().replace(/[0-9]/g,'').replace(/^-/,'')\n}\n"
  },
  {
    "path": "Killer Garage Door.js",
    "content": "/*\nDescription:\nSituation\nYou have been hired by a company making electric garage doors. Accidents with the present product line have resulted in numerous damaged cars, broken limbs and several killed pets. Your mission is to write a safer version of their controller software.\n\nSpecification\nWe always start with a closed door. The remote control has exactly one button, with the following behaviour.\n\nIf the door is closed, a push starts opening the door, and vice-versa\nIt takes 5 seconds for the door to open or close completely\nWhile the door is moving, one push pauses movement, another push resumes movement in the same direction\nIn order to make the door safer, it has been equiped with resistance-based obstacle detection. When the door detects an obstacle, it must immediately reverse the direction of movement.\n\nInput\nA string where each character represents one second, with the following possible values.\n\n'.' No event\n'P' Button has been pressed\n'O' Obstacle has been detected (supersedes P)\nAs an example, '..P....' means that nothing happens for two seconds, then the button is pressed, then no further events.\n\nOutput\nA string where each character represents one second and indicates the position of the door (0 if fully closed and 5 fully open). The door starts moving immediately, hence its position changes at the same second as the event.\n\nExample\n..P...O..... as input should yield 001234321000 as output\n*/\n"
  },
  {
    "path": "LICENSE.md",
    "content": "MIT License\n\nCopyright (c) 2019 Valefar React Developer (https://github.com/Automedon)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "LOTTO 6 aus 49 - 6 of 49.js",
    "content": "/*\nDescription:\nIn Germany we have \"LOTTO 6 aus 49\". That means that 6 of 49 numbers are drawn as winning combination.\nThere is also a \"Superzahl\", an additional number, which can increase your winning category.\n\nIn this kata you have to write two methods.\n\nfunction numberGenerator()\n\nfunction checkForWinningCategory(checkCombination, winningCombination)\nThe first method is for drawing the lottery numbers.\nYou have to create an array with 7 random numbers. 6 from these are from 1 - 49.\nOf Course every number may only occure once.\nAnd the 7th number is the \"Superzahl\". A number from 0 - 9. This number is independent from the first six numbers.\nThe first 6 numbers have to be in ascending order.\n\nA result could be:\n4, 9, 17, 22, 25, 35, 0\nOr:\n4, 18, 22, 34, 41, 44, 4\n\nThe second method should check a given number against the winning combination and have to return the winning category:\n\n1  - 6 numbers and Superzahl match\n2  - 6 numbers match\n3  - 5 numbers and Superzahl match\n4  - 5 numbers match\n5  - 4 numbers and Superzahl match\n6  - 4 numbers match\n7  - 3 numbers and Superzahl match\n8  - 3 numbers match\n9  - 2 numbers and Superzahl match\n-1 - if the numbers do not match any of the rules above\n\n\nHave fun coding it and please don't forget to vote and rank this kata! :-)\n\nI have created other katas. Have a look if you like coding and challenges.\n*/\nconst numberGenerator=()=>{\n  let arr = [];\n  for (let i=0;arr.length!==6;i++){\n    let x = getRandomIntInclusive(1,49)\n    if (!arr.includes(x)) arr.push(x)\n  }\n  arr=arr.sort((a,b)=>a-b)\n  arr.push(getRandomIntInclusive(0,9))\n  return arr\n}\nfunction getRandomIntInclusive(min, max) {\n  min = Math.ceil(min);\n  max = Math.floor(max);\n  return Math.floor(Math.random() * (max - min + 1)) + min; \n}\nfunction checkForWinningCategory(checkCombination, winningCombination) {\n  let s =false\n  let count = 0\n  checkCombination.slice(0,6).map((v,i)=>winningCombination.slice(0,6).includes(v)?count++:0)\n  if (checkCombination[checkCombination.length-1]===winningCombination[winningCombination.length-1])s=true\n  if (count===6&&s) return 1\n  if (count===6&&!s) return 2\n  if (count===5&&s) return 3\n  if (count===5&&!s) return 4\n  if (count===4&&s) return 5\n  if (count===4&&!s) return 6\n  if (count===3&&s) return 7\n  if (count===3&&!s) return 8\n  if (count===2&&s) return 9\n  return -1\n}\n"
  },
  {
    "path": "Length of missing array",
    "content": "/*\nDescription:\nYou get an array of arrays.\nIf you sort the arrays by their length, you will see, that their length-values are consecutive.\nBut one array is missing!\n\n\nYou have to write a method, that return the length of the missing array.\n\nExample:\n[[1, 2], [4, 5, 1, 1], [1], [5, 6, 7, 8, 9]] --> 3\n\n\nIf the array of arrays is null/nil or empty, the method should return 0.\n\nWhen an array in the array is null or empty, the method should return 0 too!\nThere will always be a missing element and its length will be always between the given arrays. \n\nHave fun coding it and please don't forget to vote and rank this kata! :-)\n\nI have created other katas. Have a look if you like coding and challenges.\n*/\n\n\nfunction getLengthOfMissingArray(arrayOfArrays) {\n  const lengths = (arrayOfArrays || [])\n    .map(a => a ? a.length : 0)\n    .sort((a, b) => a - b)\n  \n  if (lengths.includes(0)) {\n    return 0\n  }\n\n  for (let i = 0; i < lengths.length - 1; i++) {\n    if (lengths[i] + 1 !== lengths[i + 1]) {\n      return lengths[i] + 1\n    }\n  }\n\n  return 0\n}\n"
  },
  {
    "path": "Letter Changes.js",
    "content": "/*\nDescription:\nWelcome to this Kata. In this Kata you will be given a string. Your task is to replace every character with the letter following it in the alphabet (for example, \"b\" should be \"c\", \"z\" should be \"a\" and capital \"Z\" should be \"A\").\n\nThe test cases would not have any special symbols or numbers but it will have spaces. And the upper and lower cases should be retained in your output.\n\nFor Example:\n\nletterChange('Lorem Ipsum')    // return Mpsfn Jqtvn\n*/\nfunction letterChange(str) {\n  let l = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'\n  let u = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'\nreturn str.split('').map(v=>{\n  if (l.indexOf(v)>-1) return v=l[l.indexOf(v)+1]\n  if (u.indexOf(v)>-1) return v=u[u.indexOf(v)+1]\n  else return v\n}).join``\n}\n"
  },
  {
    "path": "Levenshtein Distance.js",
    "content": "/*\nDescription:\nIn information theory and computer science, the Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one word into the other.\n\n(http://en.wikipedia.org/wiki/Levenshtein_distance)\n\nYour task is to implement a function which calculates the Levenshtein distance for two arbitrary strings.\n*/\nfunction levenshtein(a, b) {\n  return distance(a, b, a.length, b.length)\n  \n  function distance(a, b, x, y) {\n    if (!x) return y\n    if (!y) return x\n    \n    return Math.min(\n      distance(a, b, x - 1, y) + 1,\n      distance(a, b, x, y - 1) + 1,\n      distance(a, b, x - 1, y - 1) + (a[x - 1] != b[y - 1] ? 1 : 0)\n    )\n  }\n}\n"
  },
  {
    "path": "Linear Regression of Y on X.js",
    "content": "/*\nDescription:\nLinear Regression of Y on X\nsample linear regression, curtesy of wikipedia\n*A sample regression line on a given set of points- source: wikimedia*A linear regression line has an equation in the form **Y = a + bX**, where X is the explanatory variable and Y is the dependent variable. The parameter b represents the *slope* of the line, while a is called the *intercept* (the value of y when x = 0).\nFor more details visit the related wikipedia page.\n\nThe function that you have to write accepts two arguments, both in the form of a list/array, x and y, both representing the coordinates of the points to regress (so that, for example, the first point has coordinates (x[0], y[0]).\n\nYour function should return a tuple (in Python) or an array (any other language) of two elements: a (intercept) and b (slope) in this order.\n\nYou must round your result to the first 4 decimal digits\n\nExamples:\n\nregression_line([25,30,35,40,45,50], [78,70,65,58,48,42]) === [114.381, -1.4457]\n\nregressionLine([56,42,72,36,63,47,55,49,38,42,68,60], [147,125,160,118,149,128,150,145,115,140,152,155]) === [80.7777, 1.138]\nFormula Hint\n\nΣ stands for Sigma or Summation\n\na =  [(Σx²)(Σy) - (Σx)(Σxy)]  /  [n(Σx²) - (Σx)²]\n\nb =  [n(Σxy) - (Σx)(Σy)] / [n(Σx²) - (Σx)²]\n*/\nfunction regression_line(x,y){\n  const n = x.length;\n  let sum_x = 0\n  let sum_y = 0\n  let sum_x_sq = 0\n  let sum_xy = 0\n  for (let i=0;i<n;i++){\n        sum_x += x[i]\n        sum_y += y[i]\n        sum_x_sq += x[i]**2\n        sum_xy += x[i] * y[i]\n  }\n    const a = (((sum_x_sq * sum_y) - (sum_x * sum_xy)) / ((n * sum_x_sq) - sum_x**2)).toFixed(4)*1\n    const b = (((n * sum_xy) - (sum_x * sum_y)) / ((n * sum_x_sq) - sum_x**2)).toFixed(4)*1\n  return [a,b]\n}\n"
  },
  {
    "path": "Linked Lists - Insert Nth Node.js",
    "content": "/*\nDescription:\nLinked Lists - Insert Nth\n\nImplement an InsertNth() function (insert_nth() in PHP) which can insert a new node at any index within a list.\n\nInsertNth() is a more general version of the Push() function that we implemented in the first kata listed below. Given a list, an index 'n' in the range 0..length, and a data element, add a new node to the list so that it has the given index. InsertNth() should return the head of the list.\n\ninsertNth(1 -> 2 -> 3 -> null, 0, 7) === 7 -> 1 -> 2 -> 3 -> null)\ninsertNth(1 -> 2 -> 3 -> null, 1, 7) === 1 -> 7 -> 2 -> 3 -> null)\ninsertNth(1 -> 2 -> 3 -> null, 3, 7) === 1 -> 2 -> 3 -> 7 -> null)\nYou must throw/raise an exception (ArgumentOutOfRangeException in C#, InvalidArgumentException in PHP) if the index is too large.\n\nThe push() and buildOneTwoThree() (build_one_two_three() in PHP) functions do not need to be redefined. The Node class is also preloaded for you in PHP.\n*/\nfunction Node(data) {\n  this.data = data;\n  this.next = null;\n}\n\nfunction insertNth(head, index, data) {\n  if (index == 0) {\n    return push(head, data);\n  }\n  head.next = insertNth(head.next, index - 1, data);\n  return head;\n}\n"
  },
  {
    "path": "Linked Lists - Insert Sort.js",
    "content": "/*\nDescription:\nLinked Lists - Insert Sort\n\nWrite an InsertSort() function which rearranges nodes in a linked list so they are sorted in increasing order. You can use the SortedInsert() function that you created in the \"Linked Lists - Sorted Insert\" kata below. The InsertSort() function takes the head of a linked list as an argument and must return the head of the linked list.\n\nvar list = 4 -> 3 -> 1 -> 2 -> null\ninsertSort(list) === 1 -> 2 -> 3 -> 4 -> null\nIf the passed in head node is null or a single node, return null or the single node, respectively. You can assume that the head node will always be either null, a single node, or a linked list consisting of multiple nodes.\n\nThe push(), buildOneTwoThree(), and sortedInsert() functions need not be redefined.\n*/\nfunction Node(data) {\n  this.data = data;\n  this.next = null;\n}\n\nfunction insertSort(head) {\n  if (!head) { return null; }\n  return sortedInsert(insertSort(head.next), head.data);\n}\n"
  },
  {
    "path": "Linked Lists - Recursive Reverse.js",
    "content": "/*\nDescription:\nLinked Lists - Recursive Reverse\n\nWrite a Recursive Reverse() function that recursively reverses a linked list. You may want to use a nested function for the recursive calls.\n\nvar list = 2 -> 1 -> 3 -> 6 -> 5 -> null\nreverse(list) === 5 -> 6 -> 3 -> 1 -> 2 -> null\n*/\nfunction Node(data = null, next = null) {\n  this.data = data\n  this.next = next\n}\n\nfunction reverse(list, prev = null) {\n  return list ? reverse(list.next, new Node(list.data, prev)) : prev\n}\n"
  },
  {
    "path": "Linked Lists - Remove Duplicates.js",
    "content": "/*\nDescription:\nLinked Lists - Remove Duplicates\n\nWrite a RemoveDuplicates() function which takes a list sorted in increasing order and deletes any duplicate nodes from the list. Ideally, the list should only be traversed once. The head of the resulting list should be returned.\n\nvar list = 1 -> 2 -> 3 -> 3 -> 4 -> 4 -> 5 -> null\nremoveDuplicates(list) === 1 -> 2 -> 3 -> 4 -> 5 -> null\nIf the passed in list is null/None/nil, simply return null.\n\nNote: Your solution is expected to work on long lists. Recursive solutions may fail due to stack size limitations.\n\nThe push() and buildOneTwoThree() functions need not be redefined.\n\nRelated Kata in order of expected completion (increasing difficulty):\nLinked Lists - Push & BuildOneTwoThree\nLinked Lists - Length & Count\nLinked Lists - Get Nth Node\nLinked Lists - Insert Nth Node\nLinked Lists - Sorted Insert\nLinked Lists - Insert Sort\nLinked Lists - Append\nLinked Lists - Remove Duplicates\nLinked Lists - Move Node\nLinked Lists - Move Node In-place\nLinked Lists - Alternating Split\nLinked Lists - Front Back Split\nLinked Lists - Shuffle Merge\nLinked Lists - Sorted Merge\nLinked Lists - Merge Sort\nLinked Lists - Sorted Intersect\nLinked Lists - Iterative Reverse\nLinked Lists - Recursive Reverse\n\nInspired by Stanford Professor Nick Parlante's excellent Linked List teachings.\n*/\nfunction Node(data) {\n  this.data = data;\n  this.next = null;\n}\n\nfunction removeDuplicates(head) {\n  for (let node = head; node; node = node.next) {\n    while (node.next && node.data === node.next.data) node.next = node.next.next\n  }\n  return head\n}\n"
  },
  {
    "path": "Linked Lists - Shuffle Merge.js",
    "content": "/*\nDescription:\nLinked Lists - Shuffle Merge\n\nWrite a ShuffleMerge() function that takes two lists and merges their nodes together to make one list, taking nodes alternately between the two lists. So ShuffleMerge() with 1 -> 2 -> 3 -> null and 7 -> 13 -> 1 -> null should yield 1 -> 7 -> 2 -> 13 -> 3 -> 1 -> null. If either list runs out, all the nodes should be taken from the other list. ShuffleMerge() should return the new list. The solution depends on being able to move nodes to the end of a list.\n\nvar first = 3 -> 2 -> 8 -> null\nvar second = 5 -> 6 -> 1 -> 9 -> 11 -> null\nshuffleMerge(first, second) === 3 -> 5 -> 2 -> 6 -> 8 -> 1 -> 9 -> 11 -> null\nIf one of the argument lists is null, the returned list should be the other linked list (even if it is also null). No errors need to be thrown in ShuffleMerge().\n*/\nfunction Node(data) {\n  this.data = data === undefined ? null : data;\n  this.next = null;\n}\n\nfunction shuffleMerge(first, second) {\n  let arr1 = []\n  let arr2 = []\n  while (first){\n    arr1.push(first.data)\n    first=first.next\n  }\n    while (second){\n    arr2.push(second.data)\n    second=second.next\n  }\n  let arr3 = []\n  for (let i=0;arr1.length||arr2.length;i++){\n    if (arr1.length) {arr3.push(arr1.shift())}\n    if (arr2.length) {arr3.push(arr2.shift())}\n  }\n  let push = (list,data)=>{\n    let newNode = new Node(data)\n    newNode.next = list\n    return newNode\n  }\n  let list = null\n  arr3.reverse().map(v=>list=push(list,v))\n  return list\n}\n"
  },
  {
    "path": "Linked Lists - Sorted Insert.js",
    "content": "/*\nDescription:\nLinked Lists - Sorted Insert\n\nWrite a SortedInsert() function which inserts a node into the correct location of a pre-sorted linked list which is sorted in ascending order. SortedInsert takes the head of a linked list and data used to create a node as arguments. SortedInsert() should also return the head of the list.\n\nsortedInsert(1 -> 2 -> 3 -> null, 4) === 1 -> 2 -> 3 -> 4 -> null)\nsortedInsert(1 -> 7 -> 8 -> null, 5) === 1 -> 5 -> 7 -> 8 -> null)\nsortedInsert(3 -> 5 -> 9 -> null, 7) === 3 -> 5 -> 7 -> 9 -> null)\nThe push() and buildOneTwoThree() functions do not need to be redefined.\n*/\nfunction Node(data, nxt) {\n  this.data = data;\n  this.next = nxt;\n}\nfunction sortedInsert(head, data) {\n  if(!head || data < head.data) return new Node(data, head);\n  else {\n    head.next = sortedInsert(head.next, data);\n    return head;\n  }\n}\n"
  },
  {
    "path": "Linked Lists-Length & Count.js",
    "content": "/*\nDescription:\nLinked Lists - Length & Count\n\nImplement Length() to count the number of nodes in a linked list.\n\nlength(null) => 0\nlength(1 -> 2 -> 3 -> null) => 3\nImplement Count() to count the occurrences of an integer in a linked list.\n\ncount(null, 1) => 0\ncount(1 -> 2 -> 3 -> null, 1) => 1\ncount(1 -> 1 -> 1 -> 2 -> 2 -> 2 -> 2 -> 3 -> 3 -> null, 2) => 4\nI've decided to bundle these two functions within the same Kata since they are both very similar.\n\nThe push()/Push() and buildOneTwoThree()/BuildOneTwoThree() functions do not need to be redefined.\n*/\n\nfunction Node(data) {\n  this.data = data;\n  this.next = null;\n}\n\nfunction length(head) {\n  let i = 0;\n  while (head) {\n    head = head.next;\n    i++;\n  }\n  return i;\n}\n\nfunction count(head, data) {\n  let count = 0;\n  while (head) {\n    if (data === head.data) {\n      count += 1;\n    }\n    head = head.next;\n  }\n  return count;\n}\n"
  },
  {
    "path": "Look and say numbers.js",
    "content": "/*\nDescription:\nThere exists a sequence of numbers that follows the pattern\n\n          1\n         11\n         21\n        1211\n       111221\n       312211\n      13112221\n     1113213211\n          .\n          .\n          .\nStarting with \"1\" the following lines are produced by \"saying what you see\", so that line two is \"one one\", line three is \"two one(s)\", line four is \"one two one one\".\n\nWrite a function that given a starting value as a string, returns the appropriate sequence as a list. The starting value can have any number of digits. The termination condition is a defined by the maximum number of iterations, also supplied as an argument.\n*/\nfunction lookAndSay(data,len){\n  return Array.from({length:len},(v,i)=>data=data.replace(/(.)\\1*/g,m=> m.length+m[0]));\n}\n"
  },
  {
    "path": "Loose Change.js",
    "content": "/*\nDescription:\nWelcome young Jedi! In this Kata you must create a function that takes an amount of US currency in cents, and returns a dictionary/hash which shows the least amount of coins used to make up that amount. The only coin denominations considered in this exercise are: Pennies (1¢), Nickels (5¢), Dimes (10¢) and Quarters (25¢). Therefor the dictionary returned should contain exactly 4 key/value pairs.\n\nNotes:\n\nIf the function is passed either 0 or a negative number, the function should return the dictionary with all values equal to 0.\nIf a float is passed into the function, its value should be be rounded down, and the resulting dictionary should never contain fractions of a coin.\nExamples\nloose_change(56)    ==>  {'Nickels': 1, 'Pennies': 1, 'Dimes': 0, 'Quarters': 2}\nloose_change(-435)  ==>  {'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0}\nloose_change(4.935) ==>  {'Nickels': 0, 'Pennies': 4, 'Dimes': 0, 'Quarters': 0}\n*/\nfunction looseChange(cents){\n   cents=Math.floor(cents);\n   let obj={'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0};\n   while (cents>=25){\n     cents-=25;\n     obj.Quarters++\n   }\n   while (cents>=10){\n     cents-=10;\n     obj.Dimes++\n   }\n   while (cents>=5){\n     cents-=5;\n     obj.Nickels++\n   }\n   while (cents>=1){\n     cents-=1;\n     obj.Pennies++\n   }\n   return obj\n}\n"
  },
  {
    "path": "Lottery Ticket",
    "content": "/*\nDescription:\nTime to win the lottery!\n\nGiven a lottery ticket (ticket), represented by an array of 2-value arrays, you must find out if you've won the jackpot. Example ticket:\n\n[ [ 'ABC', 65 ], [ 'HGR', 74 ], [ 'BYHT', 74 ] ]\nTo do this, you must first count the 'mini-wins' on your ticket. Each sub array has both a string and a number within it. If the character code of any of the characters in the string matches the number, you get a mini win. Note you can only have one mini win per sub array.\n\nOnce you have counted all of your mini wins, compare that number to the other input provided (win). If your total is more than or equal to (win), return 'Winner!'. Else return 'Loser!'.\n\nAll inputs will be in the correct format. Strings on tickets are not always the same length.\n*/\n\nfunction bingo(ticket, win){\n  if(ticket.filter(a => a[0].split('').some(b => b.charCodeAt(0) == a[1])).length >= win)\n  {\n    return \"Winner!\";\n  }\n  return \"Loser!\";\n}\n"
  },
  {
    "path": "Lowest product of 4 consecutive numbers.js",
    "content": "/*\nDescription:\nCreate a function that returns the lowest product of 4 consecutive digits in a number given as a string.\n\nThis should only work if the number has 4 digits or more. If not, return \"Number is too small\".\n\nExample\nlowestProduct(\"123456789\")--> 24 (1x2x3x4)\nlowestProduct(\"35\") --> \"Number is too small\"\n*/\nfunction lowestProduct(input) { \n  let arr=[];\n  if (input.length<4) return \"Number is too small\"\n      for (let x = 0; x < input.length-3; x++) {\n        arr.push(input.slice(x, x + 4).split('').map(a => +a).reduce((a, b) => a * b,1))\n    }\n    return Math.min(...arr);\n}\n"
  },
  {
    "path": "Lucas numbers.js",
    "content": "/*\nDescription:\nLucas numbers are numbers in a sequence defined like this:\n\nL(n) = 2 if n = 0\n\nL(n) = 1 if n = 1\n\notherwise\n\nL(n) = L(n - 1) + L(n - 2)\nYour mission is to define a function lucasnum(n) that returns the nth term of this sequence.\n\nNote: It should work for negative numbers as well (how you do this is you flip the equation around, so for negative numbers: L(n) = L(n + 2) - L(n + 1))\n\nExamples:\n\nlucasnum(-10) -> 123\n\nlucasnum(-5) -> -11\n\nlucasnum(-1) -> -1\n\nlucasnum(0) -> 2\n\nlucasnum(1) -> 1\n\nlucasnum(5) -> 11\n\nlucasnum(10) -> 123\n*/\nconst ns = {\n  0: 2,\n  1: 1\n}\nfunction lucasnum(n){\n  if (ns[n]) {\n    return ns[n];\n  }\n  else if (n < 0) {\n    ns[n] = lucasnum(n + 2) - lucasnum(n + 1);\n    return ns[n];\n  }\n  else {\n    ns[n] = lucasnum(n - 1) + lucasnum(n - 2);\n    return ns[n];\n  }\n}\n"
  },
  {
    "path": "MTV Cribs.js",
    "content": "/*\nDescription:\nTask:\nGiven n representing the number of floors build a beautiful multi-million dollar mansions like the ones in the example below:\n\n```javascript /* /\\ / \\ / \\ /______\\ // number of floors 3 | | | | |______|\n /\\\n/  \\\n/\n| | // 2 floors ||\n\n /\\\n/__\\    // 1 floor\n|__|\n*/\n\n```\nNote: whitespace should be preserved on both sides of the roof. Number of floors will go up to 30. There will be no tests with invalid input.\nIf you manage to complete it, you can try a harder version here\n\nGood luck!\n*/\nfunction myCrib(n) {\n  let house = []\n  for (let i=0;i<n;i++){\n    house.push(' '.repeat(n-i)+'/'+' '.repeat(i*2)+'\\\\'+' '.repeat(n-i))\n  }\n  let underRoof = '/'+'_'.repeat(n*2)+'\\\\'\n  house.push(underRoof)\n  for (let i=0;i<n-1;i++){\n    house.push('|'+' '.repeat(n*2)+'|')\n  }\n  let ground = '|'+'_'.repeat(n*2)+'|'\n  house.push(ground)\n  return house.join`\\n`;\n}\n"
  },
  {
    "path": "Make the Deadfish swim..js",
    "content": "/*\nDescription:\nWrite a simple parser that will parse and run Deadfish.\n\nDeadfish has 4 commands, each 1 character long:\n\ni increments the value (initially 0)\nd decrements the value\ns squares the value\no outputs the value into the return array\nInvalid characters should be ignored.\n\nparse(\"iiisdoso\") => [ 8, 64 ]\n*/\n// Return the output array, and ignore all non-op characters\nfunction parse( data )\n{\n  const arr=[];\n  let score=0;\n  data.split('').map(v=>{\n  if (v==='i'){score++}\n    if (v==='d'){score--}\n      if (v==='s'){score=Math.pow(score,2)}\n        if (v==='o'){arr.push(score)}\n  })\n  return arr\n}\n"
  },
  {
    "path": "Making Change.js",
    "content": "/*\nDescription:\nMaking Change\nWrite a method make_change (makeChange in JavaScript) that will determine the minimum number of coins needed to make change for a given amount in American currency.\n\nCoins used will be half-dollars, quarters, dimes, nickels, and pennies, worth 50¢, 25¢, 10¢, 5¢ and 1¢, respectively. They'll be represented by the symbols H, Q, D, N and P (symbols in Ruby, strings in JavaScript.\n\nThe argument passed in will be an integer representing the value in cents. The return value should be a hash (an object in JavaScript) with the symbols as keys, and the numbers of coins as values. Coins that are not used should not be included in the hash. If the argument passed in is 0, then the method should return an empty hash.\n\nRuby examples:\n\nmake_change(0) --> {}\nmake_change(1) --> {:P=>1}\nmake_change(43) --> {:Q=>1, :D=>1, :N=>1, :P=>3}\nmake_change(91) --> {:H=>1, :Q=>1, :D=>1, :N=>1, :P=>1}\nJavaScript examples:\n\nmakeChange(0) --> {}\nmakeChange(1) --> {\"P\":1}\nmakeChange(43) --> {\"Q\":1,\"D\":1,\"N\":1,\"P\":3}\nmakeChange(91) --> {\"H\":1,\"Q\":1,\"D\":1,\"N\":1,\"P\":1}\nElixir examples:\n\nCurrency.make_change(0) --> %{}\nCurrency.make_change(1) --> %{:P=>1}\nCurrency.make_change(43) --> %{:Q=>1, :D=>1, :N=>1, :P=>3}\nCurrency.make_change(91) --> %{:H=>1, :Q=>1, :D=>1, :N=>1, :P=>1}\nIf you liked this kata, check out Part 2.\n*/\nconst makeChange = (amount) => {\n  const change = {}\n  while (amount>=50){\n    change[`H`]=change[`H`]?change[`H`]+1:1\n    amount-=50\n  }\n  while (amount>=25){\n    change[`Q`]=change[`Q`]?change[`Q`]+1:1\n    amount-=25\n  }\n  while (amount>=10){\n    change[`D`]=change[`D`]?change[`D`]+1:1\n    amount-=10\n  }\n  while (amount>=5){\n    change[`N`]=change[`N`]?change[`N`]+1:1\n    amount-=5\n  }\n  while (amount>=1){\n    change[`P`]=change[`P`]?change[`P`]+1:1\n    amount-=1\n  }\n  return change\n};\n"
  },
  {
    "path": "Manhattan Distance.js",
    "content": "/*\nThe distance formula can be used to find the distance between two points. What if we were trying to walk from point A to point B, but there were buildings in the way? We would need some other formula..but which?\n\n###Manhattan Distance Manhattan distance is the distance between two points in a grid (like the grid-like street geography of the New York borough of Manhattan) calculated by only taking a vertical and/or horizontal path.\n\nWrite a function manhattanDistance that accepts two points, pointA and pointB, and returns the Manhattan Distance between the two points.\n\npointA and pointB are arrays containing the x and y coordinate in the grid. You can think of x as the row in the grid, and y as the column.\n\n###Examples:\n\nmanhattanDistance( [1, 1], [1, 1] ) // => returns 0\nmanhattanDistance( [5, 4], [3, 2] ) // => returns 4\nmanhattanDistance( [1, 1], [0, 3] ) // => returns 3\nResources:\nhttp://en.wiktionary.org/wiki/Manhattan_distance\nhttp://en.wikipedia.org/wiki/Manhattan_distance\n*/\nfunction manhattanDistance([a1,a2], [b1,b2]){\n  return Math.abs(a1-b1)+Math.abs(a2-b2)\n}\n"
  },
  {
    "path": "Master of Files.js",
    "content": "/*\nDescription:\nAre you a file extension master? Let's find out by checking if Bill's files are images or audio files. Please use regex if available natively for your language.\n\nYou will create 2 string methods:\n\nisAudio/is_audio, matching 1 or + uppercase/lowercase letter(s) (combination possible), with the extension .mp3, .flac, .alac, or .aac.\n\nisImage/is_image, matching 1 or + uppercase/lowercase letter(s) (combination possible), with the extension .jpg, .jpeg, .png, .bmp, or .gif.\n\nNote that this is not a generic image/audio files checker. It's meant to be a test for Bill's files only. Bill doesn't like punctuation. He doesn't like numbers, neither. Thus, his filenames are letter-only\n\nRules\n\nIt should return true or false, simply.\nFile extensions should consist of lowercase letters and numbers only.\nFile names should consist of letters only (uppercase, lowercase, or both)\n*/\nString.prototype.isAudio= function(){\n  return /\\.mp3|\\.flac|\\.alac|\\.aac/.test(this)&&!/[\\s]/.test(this)\n};\nString.prototype.isImage= function(){\n  return /\\.jpg|\\.jpeg|\\.png|\\.bmp|\\.gif/.test(this)&&!/[\\s]/.test(this)&&!/[\\d]/g.test(this)\n};\n"
  },
  {
    "path": "Matrix Addition.js",
    "content": "/*\nDescription:\nWrite a function that accepts two square matrices (N x N two dimensional arrays), and return the sum of the two. Both matrices being passed into the function will be of size N x N (square), containing only integers.\n\nHow to sum two matrices:\n\nTake each cell [n][m] from the first matrix, and add it with the same [n][m] cell from the second matrix. This will be cell [n][m] of the solution matrix.\n\nVisualization:\n\n|1 2 3|     |2 2 1|     |1+2 2+2 3+1|     |3 4 4|\n|3 2 1|  +  |3 2 3|  =  |3+3 2+2 1+3|  =  |6 4 4|\n|1 1 1|     |1 1 3|     |1+1 1+1 1+3|     |2 2 4|\nExample\nmatrixAddition(\n  [ [1, 2, 3],\n    [3, 2, 1],\n    [1, 1, 1] ],\n//      +\n  [ [2, 2, 1],\n    [3, 2, 3],\n    [1, 1, 3] ] )\n\n// returns:\n  [ [3, 4, 4],\n    [6, 4, 4],\n    [2, 2, 4] ]\n*/\n\nfunction matrixAddition(a, b){\n  let g=a.slice()\n  for (let i=0;i<a.length;i++){\n  for (let j=0;j<a.length;j++){\n  g[i][j]=a[i][j]+b[i][j]\n  }}\n  return g\n}\n"
  },
  {
    "path": "Matrix Transpose.js",
    "content": "/*\nDescription:\nWrite a function that outputs the transpose of a matrix - a new matrix where the columns and rows of the original are swapped.\n\nFor example, the transpose of:\n\n| 1 2 3 |\n| 4 5 6 |\nis\n\n| 1 4 |\n| 2 5 |\n| 3 6 |\nThe input to your function will be an array of matrix rows. You can assume that each row has the same length, and that the height and width of the matrix are both positive.\n*/\nfunction transpose(matrix) {\n  let arr=[]\n  for (let i=0;i<matrix[0].slice().length;i++){\n    let tempArr=[]\n    for (let j=0;j<matrix.slice().length;j++){\n      tempArr.push(matrix[j][i])\n    }\n    arr.push(tempArr)\n  }\n  return arr\n}\n"
  },
  {
    "path": "Max Accessor Function.js",
    "content": "/*\nDescription:\nThe popular JavaScript data visualization library D3 comes with some very cool methods, many of which can be supplied an optional function for accessing properties inside an array of objects.\n\nThe d3 max function, for example, can return the max number in an array:\n\nd3.max([1,2,3,4]); // returns 4\nOr, when supplied with an accessor function, can return the max number of a specific property for each object in an array of objects:\n\nvar people = [{age:12},{age:7},{age:2},{age:4}];\nd3.max(people, function(d){ return d.age }); // returns 12\nLet's create our own version of max which has similar functionality but only works on numbers. A stub of the function has been created for you along with a couple test cases.\n*/\nfunction max(data, accessor) {\n return accessor?Math.max(...data.map(v=>accessor(v))):Math.max(...data)\n}\n"
  },
  {
    "path": "Maze Runner.js",
    "content": "/*\nIntroduction\n \tWelcome Adventurer. Your aim is to navigate the maze and reach the finish point without touching any walls. Doing so will kill you instantly!\n \nMaze Runner\nTask\n \tYou will be given a 2D array of the maze and an array of directions. Your task is to follow the directions given. If you reach the end point before all your moves have gone, you should return Finish. If you hit any walls or go outside the maze border, you should return Dead. If you find yourself still in the maze after using all the moves, you should return Lost.\n \nThe Maze array will look like\n\nmaze = [[1,1,1,1,1,1,1],\n        [1,0,0,0,0,0,3],\n        [1,0,1,0,1,0,1],\n        [0,0,1,0,0,0,1],\n        [1,0,1,0,1,0,1],\n        [1,0,0,0,0,0,1],\n        [1,2,1,0,1,0,1]]\n..with the following key\n\n \t0 = Safe place to walk\n1 = Wall\n2 = Start Point\n3 = Finish Point\n \n  direction = [\"N\",\"N\",\"N\",\"N\",\"N\",\"E\",\"E\",\"E\",\"E\",\"E\"] == \"Finish\"\nRules\n \t1. The Maze array will always be square i.e. N x N but its size and content will alter from test to test.\n2. The start and finish positions will change for the final tests.\n3. The directions array will always be in upper case and will be in the format of N = North, E = East, W = West and S = South.\n</td>\n \nGood luck, and stay safe!\n*/\nfunction mazeRunner(maze, directions) {\n  let cursor;\n   for (let i=0;i<maze.length;i++){\n      for (let j=0;j<maze[i].length;j++){\n        if (maze[i][j]===2) {cursor=[i,j];break}}}\n    let [y,x]=cursor\n    for (let i=0;i<directions.length;i++){\n        if (directions[i]==='N'){y-=1} \n        if (directions[i]==='S'){y+=1} \n        if (directions[i]==='E'){x+=1} \n        if (directions[i]==='W'){x-=1}  \n        if (maze[y]===undefined||maze[y][x]===undefined){return 'Dead'}\n        if (maze[y][x]===0){continue}\n        if (maze[y][x]===1){return 'Dead'}\n        if (maze[y][x]===3){return 'Finish'}\n    }\n  return 'Lost'\n}\n"
  },
  {
    "path": "Meeting.js",
    "content": "/*\nDescription:\nJohn has invited people. His list is:\n\ns = \"Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill\";\nCould you make a program that\n\nmakes this string uppercase\ngives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result between parentheses separated by a comma. So the result of function meeting(s) will be:\n\"(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)\"\nIt can happen that in two distinct families with the same family name two people have the same first name too.\n*/\n\nfunction meeting(s) {\n   return s.replace(/;/gi,' ').split(' ').map(v=>v.split(':').reverse().join(', ').toUpperCase()).sort()\n   .map(v=>'('+v+')').join('')\n}\n"
  },
  {
    "path": "Mexican Wave.js",
    "content": "/*\nDescription:\nIntroduction\n \tThe wave (known as the Mexican wave in the English-speaking world outside North America) is an example of metachronal rhythm achieved in a packed stadium when successive groups of spectators briefly stand, yell, and raise their arms. Immediately upon stretching to full height, the spectator returns to the usual seated position. The result is a wave of standing spectators that travels through the crowd, even though individual spectators never move away from their seats. In many large arenas the crowd is seated in a contiguous circuit all the way around the sport field, and so the wave is able to travel continuously around the arena; in discontiguous seating arrangements, the wave can instead reflect back and forth through the crowd. When the gap in seating is narrow, the wave can sometimes pass through it. Usually only one wave crest will be present at any given time in an arena, although simultaneous, counter-rotating waves have been produced. (Source Wikipedia)\n \n\nTask\n \tIn this simple Kata your task is to create a function that turns a string into a Mexican Wave. You will be passed a string and you must return that string in an array where an uppercase letter is a person standing up.\nRules\n \t1.  The input string will always be lower case but maybe empty.\n\n2.  If the character in the string is whitespace then pass over it as if it was an empty seat.\nExample\nwave(\"hello\") => [\"Hello\", \"hEllo\", \"heLlo\", \"helLo\", \"hellO\"]\nGood luck and enjoy!\n*/\n\nfunction wave(str){\n  return Array(str.length).fill(str).map((v,i,arr)=>\n  v.slice(0,i).toLowerCase()+v.slice(i,i+1).toUpperCase()+v.slice(i+1).toLowerCase())\n  .filter(v=>v!=v.toLowerCase())\n}\n"
  },
  {
    "path": "Midpoint Sum.js",
    "content": "/*\nDescription:\nMidpoint Sum\nFor a given list of integers, return the index of the element where the sums of the integers to the left and right of the current element are equal.\n\nEx:\n\nints = [4, 1, 7, 9, 3, 9]\n# Since 4 + 1 + 7 = 12 and 3 + 9 = 12, the returned index would be 3\n\nints = [1, 0, -1]\n# Returns None/nil/undefined/etc (depending on the language) as there\n# are no indices where the left and right sums are equal\nHere are the 2 important rules:\n\nThe element at the index to be returned is not included in either of the sum calculations!\nBoth the first and last index cannot be considered as a \"midpoint\" (So None for [X] and [X, X])\n*/\nvar midpointSum=function(n){\n  for (let i=0;i<n.length;i++)\n  {\n    if (n.slice(0,i).reduce((a,b)=>a+b,0)===n.slice(i+1).reduce((a,b)=>a+b,0))\n    {\n      if (i===0||i===n.length-1) return undefined\n     return i\n    }\n  }\n};\n"
  },
  {
    "path": "Minutes to Midnight.js",
    "content": "/*\nDescription:\nTeemo is not really excited about the new year's eve, but he has to celebrate it with his friends anyway.\n\nHe has a really big passion about programming and he want's to be productive till midnight. He want's to know how many minutes he has left to work on his new project.\nHe doesn't want to look on the clock all the time, so he thought about a function, which returns him the number of minutes.\n\nCan you write him a function, so he can stay productive?\n\nThe function\nminutesToMidnight(d)\nwill take a date object as parameter. Return the number of minutes in the following format:\n\n\"x minute(s)\"\n\nYou will always get a date object with of today with a random timestamp.\nYou have to round the number of minutes.\nMilliseconds doesn't matter!\n\nSome examples:\n\n10.00 am => \"840 minutes\"\n23.59 pm => \"1 minute\"\n\n*/\nfunction minutesToMidnight(d){\n  let s = d.getSeconds()\n  let sum = (23-d.getHours())*60+(60-d.getMinutes())\n  s>30?sum-=1:sum\n  return sum===1?`1 minute`:`${sum} minutes`\n}\n"
  },
  {
    "path": "Mirror object - tcejbo rorriM.js",
    "content": "/*\nDescription:\nMirror - Mirror\nCan you mirror the properties on an object?\n\nGiven an object with properties with no value\n\nabc: -\narara: -\nxyz: -\nReturn a new object that have the properties with its mirrored key!\n\nabc: cba\narara: arara\nxyz: zyx\n\"You cannot change the original object, because if you did that the reflection would change.\"\n*/\nconst mirror = obj => {\n  obj={...obj}\n  for (let i in obj){\n    obj[i]=i.split``.reverse().join``\n  }\n  return obj\n};\n"
  },
  {
    "path": "Mirror, Mirror.js",
    "content": "/*\nDescription:\nWrite a function evilTwin(obj) which returns a new object with all the same properties as obj, and with an additional property hasGoatee set to true.\n\nFor example:\n\nvar orig = {x: 5};\nconsole.log(orig.x) // -> 5\nconsole.log(orig.hasGoatee) // -> undefined\nvar twin = evilTwin(orig);\nconsole.log(twin.x) // -> 5\nconsole.log(twin.hasGoatee) // -> true\nIf the original object is modified, its twin should reflect the changes so:\n\norig.z = 12\nconsole.log(twin.z) // -> 12\n*/\nfunction evilTwin(obj) {\n  let twin=Object.create(obj)\n  twin.hasGoatee=true\n  return twin\n}\n"
  },
  {
    "path": "Missing Alphabet.js",
    "content": "/*\nDescription:\nIn this Kata you have to create a function,named insertMissingLetters,that takes in a string and outputs the same string processed in a particular way.\n\nThe function should insert only after the first occurence of each character of the input string, all the alphabet letters that:\n\n-are NOT in the original string\n-come after the letter of the string you are processing\n\nEach added letter should be in uppercase, the letters of the original string will always be in lowercase.\n\nExample:\n\ninput: \"holly\"\n\nmissing letters: \"a,b,c,d,e,f,g,i,j,k,m,n,p,q,r,s,t,u,v,w,x,z\"\n\noutput: \"hIJKMNPQRSTUVWXZoPQRSTUVWXZlMNPQRSTUVWXZlyZ\"\n\nYou don't need to validate input, the input string will always contain a certain amount of lowercase letters (min 1 / max 50).\n*/\nfunction insertMissingLetters (str){\n  let uniq = [...new Set(str.split``)].join``\n  let arr = [];\n  let dict = 'abcdefghijklmnopqrstuvwxyz'\n  for (let i=0;i<uniq.length;i++){\n    arr.push(uniq[i]+dict.slice(dict.indexOf(uniq[i])).replace(new RegExp(`[${uniq}]`,'gi'),'').toUpperCase())\n  }\n  let str2=str.slice();\n  for (let i=0;i<uniq.length;i++){\n    str2=str2.replace(new RegExp(uniq[i]),arr[i])\n  }\n  return str2\n}\n"
  },
  {
    "path": "Mix Fruit Juice.js",
    "content": "/*\nDescription:\nStory\nJumbo Juice makes a fresh juice out of fruits of your choice.Jumbo Juice charges $5 for regular fruits and $7 for special ones. Regular fruits are Banana, Orange, Apple, Lemon and Grapes. Special ones are Avocado, Strawberry and Mango. Others fruits that are not listed are also available upon request. Those extra special fruits cost $9 per each. There is no limit on how many fruits she/he picks.The price of a cup of juice is the mean of price of chosen fruits. In case of decimal number (ex. $5.99), output should be the nearest integer (use the standard rounding function of your language of choice).\nInput\nThe function will receive an array of strings, each with the name of a fruit. The recognition of names should be case insensitive. There is no case of an enmpty array input.\nExample\n\n['Mango', 'Banana', 'Avocado'] //the price of this juice bottle is (7+5+7)/3 = $6($6.333333...)\n*/\nfunction mixFruit (arr) {\n  let reg = ['banana', 'orange', 'apple', 'lemon','grapes']\n  let spec = ['avocado', 'strawberry', 'mango']\n  return Math.round(arr.reduce((a,b)=>{\n  b=b.toLowerCase()\n  if (reg.includes(b)) return a+5\n  if (spec.includes(b)) return a+7\n  return a+9\n  },0)/arr.length)\n}\n"
  },
  {
    "path": "Moduli number system.js",
    "content": "/*\nDescription:\nA number system with moduli is deﬁned by a vector of k moduli, [m1,m2, ···,mk].\n\nThe moduli must be pairwise co-prime, which means that, for any pair of moduli, the only common factor is 1.\n\nIn such a system each number n is represented by a string \"-x1--x2-- ... --xk-\" of its residues, one for each modulus. The product m1 * ... * mk must be greater than the given number n which is to be converted in the moduli number system.\n\nFor example, if we use the system [2, 3, 5] the number n = 11 is represented by \"-1--2--1-\",\nthe number n = 23 by \"-1--2--3-\".\n\nIf we use the system [8, 7, 5, 3] the number n = 187 becomes \"-3--5--2--1-\".\n\nYou will be given a number n (n >= 0) and a system S = [m1,m2, ···,mk] and you will return a string \"-x1--x2-- ...--xk-\" representing the number n in the system S.\n\nIf the moduli are not pairwise co-prime or if the product m1 * ... * mk is not greater than n, return \"Not applicable\".\n\nExamples: (you can add them in the \"Sample tests\")\n\nfromNb2Str(11, [2,3,5]) -> \"-1--2--1-\"\n\nfromNb2Str(6, [2, 3, 4]) -> \"Not applicable\", since 2 and 4 are not coprime\n\nfromNb2Str(7, [2, 3]) -> \"Not applicable\" since 2 * 3 < 7\n*/\nfunction fromNb2Str(n,sys){\n  if (sys.reduce((a,b)=>a*b,1)<n||sys.length%2!==0) return \"Not applicable\"\n  return sys.map(v=>'-'+n%v+'-').join``\n}\n"
  },
  {
    "path": "Most Frequent Weekdays.js",
    "content": "/*\nDescription:\nWhat is your favourite day of the week? Check if it's the most frequent day of the week in the year.\n\nYou are given a year as integer (e. g. 2001). You should return the most frequent day(s) of the week in that year. The result has to be a list of days sorted by the order of days in week (e. g. ['Monday', 'Tuesday']). Week starts with Monday.\n\nInput: Year as an int.\n\nOutput: The list of most frequent days sorted by the order of days in week (from Monday to Sunday).\n\nPreconditions: Year is between 1 and 9999. Week starts with Monday. Calendar is Gregorian.\n\nExample:\n\nmostFrequentDays(2427) => ['Friday']\nmostFrequentDays(2185) => ['Saturday']\nmostFrequentDays(2860) => ['Thursday', 'Friday']\nIn Ruby years will start from 1593.\n*/\nfunction mostFrequentDays(year){\n  const weekDays = {Monday:0,Tuesday:0,Wednesday:0,Thursday:0,Friday:0,Saturday:0,Sunday:0}\n  let date=new Date(year,0,0).getTime()+1\n  for (let i=0;;i++){\n    date+=1000*60*60*24\n    if (new Date(date).getFullYear()>year){break}\n    if (new Date(date).getDay()===0) weekDays.Sunday++\n    if (new Date(date).getDay()===1) weekDays.Monday++\n    if (new Date(date).getDay()===2) weekDays.Tuesday++\n    if (new Date(date).getDay()===3) weekDays.Wednesday++\n    if (new Date(date).getDay()===4) weekDays.Thursday++\n    if (new Date(date).getDay()===5) weekDays.Friday++\n    if (new Date(date).getDay()===6) weekDays.Saturday++\n  }\n  const max = Math.max(...Object.values(weekDays))\n  return [].concat(Object.entries(weekDays).filter(v=>v[1]===max).map(v=>v[0]))\n}\n"
  },
  {
    "path": "Moves in squared strings (II).js",
    "content": "/*\nDescription:\nYou are given a string of n lines, each substring being n characters long: For example:\n\ns = \"abcd\\nefgh\\nijkl\\nmnop\"\n\nWe will study some transformations of this square of strings.\n\nClock rotation 180 degrees: rot\nrot(s) => \"ponm\\nlkji\\nhgfe\\ndcba\"\nselfie_and_rot(s) (or selfieAndRot or selfie-and-rot) It is initial string + string obtained by clock rotation 180 degrees with dots interspersed in order (hopefully) to better show the rotation when printed.\ns = \"abcd\\nefgh\\nijkl\\nmnop\" --> \n\"abcd....\\nefgh....\\nijkl....\\nmnop....\\n....ponm\\n....lkji\\n....hgfe\\n....dcba\"\nor printed:\n|rotation        |selfie_and_rot\n|abcd --> ponm   |abcd --> abcd....\n|efgh     lkji   |efgh     efgh....\n|ijkl     hgfe   |ijkl     ijkl....   \n|mnop     dcba   |mnop     mnop....\n                           ....ponm\n                           ....lkji\n                           ....hgfe\n                           ....dcba\n#Task:\n\nWrite these two functions rotand selfie_and_rot\nand\n\nhigh-order function oper(fct, s) where\n\nfct is the function of one variable f to apply to the string s (fct will be one of rot, selfie_and_rot)\n#Examples:\n\ns = \"abcd\\nefgh\\nijkl\\nmnop\"\noper(rot, s) => \"ponm\\nlkji\\nhgfe\\ndcba\"\noper(selfie_and_rot, s) => \"abcd....\\nefgh....\\nijkl....\\nmnop....\\n....ponm\\n....lkji\\n....hgfe\\n....dcba\"\nNotes:\nThe form of the parameter fct in oper changes according to the language. You can see each form according to the language in \"Your test cases\".\nIt could be easier to take these katas from number (I) to number (IV)\nForthcoming katas will study other tranformations.\n\nBash Note:\nThe input strings are separated by , instead of \\n. The ouput strings should be separated by \\r instead of \\n. See \"Sample Tests\".\n*/\nfunction rot(strng) {\n    let arr=strng.slice().split('\\n').reverse().map(v=>v.split('').reverse().join(``)).join('\\n')\n    return arr\n}\nfunction selfieAndRot(strng) {\n    let n=strng.slice().split('\\n')[0].length\n    let arr=strng.slice().split('\\n').reverse().map(v=>v.split('').reverse().join(``)).join(`\\n${'.'.repeat(n)}`)\n    let arr2=strng.slice().split('\\n').join(`${'.'.repeat(n)}\\n`)\n    return arr2+`${'.'.repeat(n)}\\n${'.'.repeat(n)}`+arr\n}\nfunction oper(fct, s) {\n    return fct(s)\n}\n"
  },
  {
    "path": "Moves in squared strings (III).js",
    "content": "/*\nDescription:\nYou are given a string of n lines, each substring being n characters long: For example:\n\ns = \"abcd\\nefgh\\nijkl\\nmnop\"\n\nWe will study some transformations of this square of strings.\n\nSymmetry with respect to the main diagonal: diag_1_sym (or diag1Sym or diag-1-sym)\ndiag_1_sym(s) => \"aeim\\nbfjn\\ncgko\\ndhlp\"\nClockwise rotation 90 degrees: rot_90_clock (or rot90Clock or rot-90-clock)\nrot_90_clock(s) => \"miea\\nnjfb\\nokgc\\nplhd\"\nselfie_and_diag1(s) (or selfieAndDiag1 or selfie-and-diag1) It is initial string + string obtained by symmetry with respect to the main diagonal.\ns = \"abcd\\nefgh\\nijkl\\nmnop\" --> \n\"abcd|aeim\\nefgh|bfjn\\nijkl|cgko\\nmnop|dhlp\"\nor printed for the last:\nselfie_and_diag1\nabcd|aeim\nefgh|bfjn\nijkl|cgko \nmnop|dhlp\n#Task:\n\nWrite these functions diag_1_sym, rot_90_clock, selfie_and_diag1\nand\n\nhigh-order function oper(fct, s) where\n\nfct is the function of one variable f to apply to the string s (fct will be one of diag_1_sym, rot_90_clock, selfie_and_diag1)\n#Examples:\n\ns = \"abcd\\nefgh\\nijkl\\nmnop\"\noper(diag_1_sym, s) => \"aeim\\nbfjn\\ncgko\\ndhlp\"\noper(rot_90_clock, s) => \"miea\\nnjfb\\nokgc\\nplhd\"\noper(selfie_and_diag1, s) => \"abcd|aeim\\nefgh|bfjn\\nijkl|cgko\\nmnop|dhlp\"\nNotes:\nThe form of the parameter fct in oper changes according to the language. You can see each form according to the language in \"Your test cases\".\nIt could be easier to take these katas from number (I) to number (IV)\nBash Note: The ouput strings should be separated by \\r instead of \\n. See \"Sample Tests\".\nA forthcoming kata will study other tranformations.\n*/\nfunction rot90Clock(strng) {\n    let arr = strng.split`\\n`\n    let arr2 = []\n    for (let i=0;i<arr.length;i++){\n      let str = ''\n      for (let j=arr.length-1;j>=0;j--){\n        str+=arr[j][i]\n      }\n      arr2.push(str)\n    }\n    return arr2.join`\\n`\n}\nfunction diag1Sym(strng) {\n    let arr = strng.split`\\n`\n    let arr2 = []\n    for (let i=0;i<arr.length;i++){\n      let str = ''\n      for (let j=0;j<arr.length;j++){\n        str+=arr[j][i]\n      }\n      arr2.push(str)\n    }\n    return arr2.join`\\n`\n}\nfunction selfieAndDiag1(strng) {\n       let arr = strng.split`\\n`\n    let arr2 = []\n    for (let i=0;i<arr.length;i++){\n      let str = ''\n      for (let j=0;j<arr.length;j++){\n        str+=arr[j][i]\n      }\n      arr2.push(arr[i]+'|'+str)\n    }\n    return arr2.join`\\n`\n}\nfunction oper(fct, s) {\n    return fct(s)\n}\n"
  },
  {
    "path": "Moves in squared strings (IV).js",
    "content": "/*\nDescription:\nYou are given a string of n lines, each substring being n characters long: For example:\n\ns = \"abcd\\nefgh\\nijkl\\nmnop\"\n\nWe will study some transformations of this square of strings.\n\nSymmetry with respect to the main cross diagonal: diag_2_sym (or diag2Sym or diag-2-sym)\ndiag_2_sym(s) => \"plhd\\nokgc\\nnjfb\\nmiea\"\nCounterclockwise rotation 90 degrees: rot_90_counter (or rot90Counter or rot-90-counter)\nrot_90_counter(s)=> \"dhlp\\ncgko\\nbfjn\\naeim\"\nselfie_diag2_counterclock (or selfieDiag2Counterclock or selfie-diag2-counterclock) It is initial string + string obtained by symmetry with respect to the main cross diagonal + counterclockwise rotation 90 degrees .\ns = \"abcd\\nefgh\\nijkl\\nmnop\" --> \n\"abcd|plhd|dhlp\\nefgh|okgc|cgko\\nijkl|njfb|bfjn\\nmnop|miea|aeim\"\nor printed for the last:\nselfie_diag2_counterclock\nabcd|plhd|dhlp\nefgh|okgc|cgko\nijkl|njfb|bfjn\nmnop|miea|aeim\n#Task:\n\nWrite these functions diag_2_sym, rot_90_counter, selfie_diag2_counterclock\nand\n\nhigh-order function oper(fct, s) where\n\nfct is the function of one variable f to apply to the string s (fct will be one of diag_2_sym, rot_90_counter, selfie_diag2_counterclock)\n#Examples:\n\ns = \"abcd\\nefgh\\nijkl\\nmnop\"\noper(diag_2_sym, s) => \"plhd\\nokgc\\nnjfb\\nmiea\"\noper(rot_90_counter, s) => \"dhlp\\ncgko\\nbfjn\\naeim\"\noper(selfie_diag2_counterclock, s) => \"abcd|plhd|dhlp\\nefgh|okgc|cgko\\nijkl|njfb|bfjn\\nmnop|miea|aeim\"\nNotes:\nThe form of the parameter fct in oper changes according to the language. You can see each form according to the language in \"Your test cases\".\nIt could be easier to take these katas from number (I) to number (IV)\nBash Note: The ouput strings should be separated by \\r instead of \\n. See \"Sample Tests\".\n*/\nfunction diag2Sym(strng) {\n    let arr = strng.split`\\n`\n    let arr2 = []\n    for (let i=arr.length-1;i>=0;i--){\n      let str=''\n      for (let j=arr.length-1;j>=0;j--){\n        str+=arr[j][i]\n      }\n      arr2.push(str)\n    }\n    return arr2.join`\\n`\n}\nfunction rot90Counter(strng) {\n    let arr = strng.split`\\n`\n    let arr2 = []\n    for (let i=arr.length-1;i>=0;i--){\n      let str=''\n      for (let j=0;j<arr.length;j++){\n        str+=arr[j][i]\n      }\n      arr2.push(str)\n    }\n    return arr2.join`\\n`\n}\nfunction selfieDiag2Counterclock(strng) {\n    let arr = strng.split`\\n`\n    let arr2 = diag2Sym(strng).split`\\n`\n    let arr3 = rot90Counter(strng).split`\\n`\n    return arr.map((v,i)=>v+'|'+arr2[i]+'|'+arr3[i]).join`\\n`\n}\nfunction oper(fct, s) {\n    return fct(s)\n}\n"
  },
  {
    "path": "Mr. Safety's treasures.js",
    "content": "/*\nDescription:\nIntroduction\nMr. Safety loves numeric locks and his Nokia 3310. He locked almost everything in his house. He is so smart and he doesn't need to remember the combinations. He has an algorithm to generate new passcodes on his Nokia cell phone.\npostimage\n\nTask\nCan you crack his numeric locks? Mr. Safety's treasures wait for you. Write an algorithm to open his numeric locks. Can you do it without his Nokia 3310?\n\nInput\nThe str or message (Python) input string consists of lowercase and upercase characters. It's a real object that you want to unlock.\n\nOutput\nReturn a string that only consists of digits.\nExample\n``` unlock(\"Nokia\") // => 66542 unlock(\"Valut\") // => 82588 unlock(\"toilet\") // => 864538 ```\n*/\nfunction unlock(str){\n  str=str.toLowerCase()\n  let code=''\n  const cypher={2:'abc', 3:'def',4:'ghi',5:'jkl', 6:'mno',7:'pqrs',8:'tuv', 9:'wxyz'}\n  for (let i=0;i<str.length;i++){\n    for (let j in cypher){\n      if (cypher[j].indexOf(str[i])!==-1) code+=j\n    }\n  }\n   return code\n}\n"
  },
  {
    "path": "Multi-tap Keypad Text Entry on an Old Mobile Phone",
    "content": "/*\nDescription:\nPrior to having fancy iPhones, teenagers would wear out their thumbs sending SMS messages on candybar-shaped feature phones with 3x4 numeric keypads.\n\n------- ------- -------\n|     | | ABC | | DEF |\n|  1  | |  2  | |  3  |\n------- ------- -------\n------- ------- -------\n| GHI | | JKL | | MNO |\n|  4  | |  5  | |  6  |\n------- ------- -------\n------- ------- -------\n|PQRS | | TUV | | WXYZ|\n|  7  | |  8  | |  9  |\n------- ------- -------\n------- ------- -------\n|     | |space| |     |\n|  *  | |  0  | |  #  |\n------- ------- -------\nPrior to the development of T9 (predictive text entry) systems, the method to type words was called \"multi-tap\" and involved pressing a button repeatedly to cycle through the possible values.\n\nFor example, to type a letter \"R\" you would press the 7 key three times (as the screen display for the current character cycles through P->Q->R->S->7). A character is \"locked in\" once the user presses a different key or pauses for a short period of time (thus, no extra button presses are required beyond what is needed for each letter individually). The zero key handles spaces, with one press of the key producing a space and two presses producing a zero.\n\nIn order to send the message \"WHERE DO U WANT 2 MEET L8R\" a teen would have to actually do 47 button presses. No wonder they abbreviated.\n\nFor this assignment, write a module that can calculate the amount of button presses required for any phrase. Punctuation can be ignored for this exercise. Likewise, you can assume the phone doesn't distinguish between upper/lowercase characters (but you should allow your module to accept input in either for convenience).\n\nHint: While it wouldn't take too long to hard code the amount of keypresses for all 26 letters by hand, try to avoid doing so! (Imagine you work at a phone manufacturer who might be testing out different keyboard layouts, and you want to be able to test new ones rapidly.)\n*/\n\nfunction presses(s) {\n  var s1=\"1*# ADGJMPTW0BEHKNQUXCFILORVY23456S8Z79\",\n      s2=\"111111111111222222222333333334444444455\";\n  return [...s.toUpperCase()].reduce((a,b)=>a+ +s2[s1.indexOf(b)],0);\n}\n"
  },
  {
    "path": "Multiples of 3 and 5 redux.js",
    "content": "/*\nDescription:\nThe galactic games have begun!\nIt's the galactic games! Beings of all worlds come together to compete in several interesting sports, like nroogring, fredling and buzzing (the beefolks love the last one). However, there's also the traditional marathon run.\n\nUnfortunately, there have been cheaters in the last years, and the committee decided to place sensors on the track. Committees being committees, they've come up with the following rule:\n\nA sensor should be placed every 3 and 5 meters from the start, e.g. at 3m, 5m, 6m, 9m, 10m, 12m, 15m, 18m….\n\nSince you're responsible for the track, you need to buy those sensors. Even worse, you don't know how long the track will be! And since there might be more than a single track, and you can't be bothered to do all of this by hand, you decide to write a program instead.\n\nTask\nReturn the sum of the multiples of 3 and 5 below a number. Being the galactic games, the tracks can get rather large, so your solution should work for really large numbers (greater than 1,000,000).\n\nExamples\nsolution (10) // => 23 = 3 + 5 + 6 + 9\nsolution (20) // => 78 = 3 + 5 + 6 + 9 + 10 + 12 + 15 + 18\n*/\nfunction solution(number){\n  number--;\n  return   3 *  ~~(number/3) *  (~~(number/3) + 1) / 2\n        +  5 *  ~~(number/5) *  (~~(number/5) + 1) / 2\n        - 15 * ~~(number/15) *  (~~(number/15) + 1) / 2\n}\n"
  },
  {
    "path": "Multiples of 3 or 5",
    "content": "/*\nDescription:\nIf we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.\n\nFinish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.\n\nNote: If the number is a multiple of both 3 and 5, only count it once.\n\nCourtesy of ProjectEuler.net\n*/\n\nfunction solution(number){\n  let arr=[];\n    for (let i=number-1;i>=0;i--){\n      if (i%3===0) arr.push(i);\n      if (i%5===0) arr.push(i);\n}\n  return [...new Set(arr)].reduce((a,b)=>a+b,0)\n}\n"
  },
  {
    "path": "Multiplication Tables.js",
    "content": "/*\nDescription:\nCreate a function that accepts dimensions, of Rows x Columns, as parameters in order to create a multiplication table sized according to the given dimensions. **The return value of the function must be an array, and the numbers must be Fixnums, NOT strings.\n\nExample:\n\nmultiplication_table(3,3)\n\n1 2 3\n2 4 6\n3 6 9\n\n-->[[1,2,3],[2,4,6],[3,6,9]]\n\nEach value on the table should be equal to the value of multiplying the number in its first row times the number in its first column.\n*/\n\nfunction multiplicationTable(row,col){\n  let  arr=[];\n  let temp=[];\n  for (let i=1;i<=row;i++){\n   temp=[]\n    for (let j=1;j<=col;j++){\n    temp.push(j*i)}\n    arr.push(temp)\n    }\n    return arr\n}\n"
  },
  {
    "path": "Multiplication table.js",
    "content": "/*\nYour task, is to create NxN multiplication table, of size provided in parameter.\n\nfor example, when given size is 3:\n\n1 2 3\n2 4 6\n3 6 9\nfor given example, the return value should be: [[1,2,3],[2,4,6],[3,6,9]]\n*/\nmultiplicationTable = function(size) {\n  let arr=[];\n  for (let i=1;i<=size;i++){\n      let tempArr=[];\n      for (let j=1;j<=size;j++){\n              tempArr.push(i*j)\n        }\n        arr.push(tempArr)\n    }\n    return arr\n}\n"
  },
  {
    "path": "Mutual Recursion.js",
    "content": "/*\nDescription:\nMutual Recursion allows us to take the fun of regular recursion (where a function calls itself until a terminating condition) and apply it to multiple functions calling each other!\n\nLet's use the Hofstadter Female and Male sequences to demonstrate this technique. You'll want to create two functions F and M such that the following equations are true:\n\nF(0) = 1\nM(0) = 0\nF(n) = n - M(F(n - 1))\nM(n) = n - F(M(n - 1))\nDon't worry about negative numbers, n will always be greater than or equal to zero.\n*/\nfunction F(n) { \nif (n===0) return 1\nreturn n - M(F(n - 1))\n}\n\nfunction M(n) { \nif (n===0) return 0\nreturn n - F(M(n - 1))\n}\n"
  },
  {
    "path": "Mysterious function.js",
    "content": "/*\nDescription:\nAmong the ruins of an ancient city a group of archaeologists found a mysterious function with lots of HOLES in it called getNum(n) (or get_num(n) in ruby, python, or r). They tried to call it with some arguments. And finally they got this journal:\n\ngetNum(300) #-> returns 2\ngetNum(90783) #-> returns 4\ngetNum(123321) #-> returns 0\ngetNum(89282350306) #-> returns 8\ngetNum(3479283469) #-> returns 5\nThe archaeologists were totally stuck with this challenge. They were all in desperation but then.... came YOU the SUPER-AWESOME programmer. Will you be able to understand the mystery of this function and rewrite it?\n*/\nvar getNum = function(n) {\n    let count=0\n    n.toString().split``.map(v=>{\n    v==='0'?count++:1;\n    v==='6'?count++:1;\n    v==='8'?count+=2:1;\n    v==='9'?count++:1;\n    })\n    return count \n};\n"
  },
  {
    "path": "N smallest elements in original order.js",
    "content": "/*\nDescription:\nYour task is to write a function that does just what the title suggests (so, fair warning, be aware that you are not getting out of it just throwing a lame bas sorting method there) with an array/list/vector of integers and the expected number n of smallest elements to return.\n\nAlso:\n\nthe number of elements to be returned cannot be higher than the array/list/vector length;\nelements can be duplicated;\nin case of duplicates, just return them according to the original order (see third example for more clarity).\nSame examples and more in the test cases:\n\nfirstNSmallest([1,2,3,4,5],3) === [1,2,3] //well, not technically ===, but you get what I mean\nfirstNSmallest([5,4,3,2,1],3) === [3,2,1]\nfirstNSmallest([1,2,3,4,1],3) === [1,2,1]\nfirstNSmallest([1,2,3,-4,0],3) === [1,-4,0]\nfirstNSmallest([1,2,3,4,5],0) === []\nPerformance version by FArekkusu also available.\n*/\nfunction firstNSmallest(array, n){\n  const result = [];\n  const arrSorted = array.slice().sort((a, b) => a - b).slice(0, n);\n  for (let i = 0; i < array.length; i++) {\n    if (arrSorted.includes(array[i])) {\n      result.push(...arrSorted.splice(arrSorted.indexOf(array[i]), 1));\n    }\n  }\n  return result;\n}\n"
  },
  {
    "path": "N-th Fibonacci.js",
    "content": "/*\nDescription:\nI love Fibonacci numbers in general, but I must admit I love some more than others.\n\nI would like for you to write me a function that when given a number (n) returns the n-th number in the Fibonacci Sequence.\n\nFor example:\n\n   nthFibo(4) == 2\nBecause 2 is the 4th number in the Fibonacci Sequence.\n\nFor reference, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two.\n*/\n\nfunction nthFibo(n) {\n let fib=[0,1];\n for (let i=0;i<n;i++){\n fib.push(fib[i]+fib[i+1])\n }\n return fib[n-1]\n}\n"
  },
  {
    "path": "Name That Integer.js",
    "content": "/*\nDescription:\nRuby\nWrite a method detect_int that returns the first positive integer for which an arbitrary number of lambdas returns true. If no arguments are passed in, then detect_int should return 1.\n\nFor example:\n\nlam1 = lambda { |x| x > 9 }\nlam2 = lambda { |x| x**0.5 % 1 == 0 }\n\ndetect_int\n  # => 1\ndetect_int lam1\n  # => 10\ndetect_int lam2\n  # => 1\ndetect_int lam1, lam2\n  # => 16\nThe testing rubric will never ask for a number that does not exist, e.g., detect_int(lambda { |x| x.odd? }, lambda { |x| x.even? }).\n\nNote that loops constructed using the loop { block } syntax are limited to 5000 iterations, but solutions will not be constrained to integers less than 5000.\n\nJavaScript\nWrite a function detectInt that returns the first positive integer for which an arbitrary number of functions returns true.\n\nFor examples, see the example test cases.\n*/\nfunction detectInt() {\n  let arg = [...arguments]\n  if (arg.length===0) return 1\n  for (let i=1;;i++){\n    if (arg.every(v=>v(i))) return i\n  }\n}\n"
  },
  {
    "path": "Name to Matrix.js",
    "content": "/*\nDescription:\nGiven a name, turn that name into a perfect square matrix (nested array with the amount of arrays equivalent to the length of each array).\n\nYou will need to add periods (.) to the end of the name if necessary, to turn it into a matrix.\n\nIf the name has a length of 0, return \"name must be at least one letter\"\n\nExamples\n\"Bill\" ==> [ [\"B\", \"i\"],\n             [\"l\", \"l\"] ]\n\n\"Frank\" ==> [ [\"F\", \"r\", \"a\"],\n              [\"n\", \"k\", \".\"],\n              [\".\", \".\", \".\"] ]\n*/\nconst matrixfy = str => {\n  if (!str.length) return 'name must be at least one letter'\n  let length = 1\n  while (str.length>length){\n    length++\n    if (str.length<Math.pow(length,2)) break\n  }\n  let arr = []\n  let z = 0\n  for (let i=0;i<length;i++){\n    let temp = []\n    for (let j=0;j<length;j++){\n      temp.push(str[z]||'.')\n      z++\n    }\n    arr.push(temp)\n  }\n  return arr\n};\n"
  },
  {
    "path": "New Cashier Does Not Know About Space or Shift.js",
    "content": "/*\nDescription:\nSome new cashiers started to work at your restaurant.\n\nThey are good at taking orders, but they don't know how to capitalize words, or use a space bar!\n\nAll the orders they create look something like this:\n\n\"milkshakepizzachickenfriescokeburgerpizzasandwichmilkshakepizza\"\n\nThe kitchen staff are threatening to quit, because of how difficult it is to read the orders.\n\nTheir preference is to get the orders as a nice clean string with spaces and capitals like so:\n\n\"Burger Fries Chicken Pizza Pizza Pizza Sandwich Milkshake Milkshake Coke\"\n\nThe kitchen staff expect the items to be in the same order as they appear in the menu.\n\nThe menu items are fairly simple, there is no overlap in the names of the items:\n\n1. Burger\n2. Fries\n3. Chicken\n4. Pizza\n5. Sandwich\n6. Onionrings\n7. Milkshake\n8. Coke\n*/\nfunction getOrder(input) {\n  const menu =[ 'burger','fries','chicken','pizza','sandwich','onionrings' ,'milkshake','coke']\n  const arr = []\n  for (let i=0;i<menu.length;i++){\n      arr.push(input.match(new RegExp(`${menu[i]}`,'gi')))\n  }\n  return  [].concat(...arr).filter(v=>v).map(v=>v.slice(0,1).toUpperCase()+v.slice(1).toLowerCase()).join` `\n}\n"
  },
  {
    "path": "Next Version.js",
    "content": "/*\nescription:\nYou're fed up about changing the version of your software manually. Instead, you will create a little script that will make it for you.\n\nExercice\nCreate a function nextVersion, that will take a string in parameter, and will return a string containing the next version number.\n\nFor example:\n\nnextVersion(\"1.2.3\") === \"1.2.4\";\nnextVersion(\"0.9.9\") === \"1.0.0\";\nnextVersion(\"1\") === \"2\";\nnextVersion(\"1.2.3.4.5.6.7.8\") === \"1.2.3.4.5.6.7.9\";\nnextVersion(\"9.9\") === \"10.0\";\nRules\nAll numbers, except the first one, must be lower than 10: if there are, you have to set them to 0 and increment the next number in sequence.\n\nYou can assume all tests inputs to be valid.\n*/\nconst nextVersion = version => {\n  let arr = version.split('.').map(Number);\n  for (let i = arr.length - 1; i >= 0; i--) {\n    if (arr[i] + 1 === 10 && i !== 0) {\n      arr[i] = 0;\n    } else {\n      arr[i]++;\n      break;\n    }\n  }\n  return arr.join('.');\n};\n"
  },
  {
    "path": "Non-even substrings.js",
    "content": "/*\nDescription:\nGiven a string of integers, return the number of odd-numbered substrings that can be formed.\n\nFor example, in the case of \"1341\", they are 1, 1, 3, 13, 41, 341, 1341, a total of 7 numbers.\n\nsolve(\"1341\") = 7. See test cases for more examples.\n\nGood luck!\n*/\nconst BigNumber = require('bignumber.js');\nfunction solve(s){\n  let arr = []\n  for (let i=0;i<=s.length;i++){\n    for (let j=i+1;j<=s.length;j++){\n      let x = new BigNumber(s.slice(i,j))\n      if (x.modulo(2)*1===1) arr.push(s.slice(i,j))\n    }\n  }\n  return arr.length\n};\n"
  },
  {
    "path": "None shall pass.js",
    "content": "/*\nDescription:\nThe black knight moves for no man.\nHowever, you are no mere man; you are Arthur, King of the Britons.\nYou have no quarrel with good sir knight, but you must cross this bridge!\n\nIf this description does not make sense to you: the kata is a reference to Monty Python And The Holy Grail.\n*/\n// The black knight will be more persistent depending on the difficulty you specify.\n// Possible difficulties are easy, medium, hard, harder and impossible.\n// Default is easy.\ndifficulty = 'medium';\nBlackKnight.letsYouPass = function () { return true; }\n"
  },
  {
    "path": "Not prime numbers.js",
    "content": "/*\nDescription:\nYou are given two positive integers a and b (a < b <= 20000). Complete the function which returns a list of all those numbers in the interval [a, b) whose digits are made up of prime numbers (2, 3, 5, 7) but which are not primes themselves.\n\nBe careful about your timing!\n\nGood luck :)\n*/\nlet arr =  ['2','3','5','7']\nlet ans = []\nlet heheboi=()=>{\n  for (let i=0;i<20000;i++){\n    if (i.toString().split``.every(v=>arr.includes(v))&&!isPrime(i)) ans.push(i)\n  }\n}\nheheboi()\nfunction notPrimes(a,b){\n  if (a>ans[ans.length-1]) return []\n  let min = ans.findIndex((v,i)=>v>=a)\n  if (b>ans[ans.length-1]) return ans.slice(min)\n  let max = ans.findIndex((v,i)=>b<=v)\n  return ans.slice(min,max)\n}\nfunction isPrime(n) {\n  let rt = Math.sqrt(n);\n  for(let i = 2; i <= rt; i++) {\n    if(n % i === 0) return false; \n  }\n  return n !== 1;\n}\n"
  },
  {
    "path": "Nuclear Missile Manager.js",
    "content": "/*\nDescription:\nOur nuclear missible manager system is coded in Node.js. We are currently testing the system and it seams that the launchAll function does not work as expected. It should launch 5 missiles each 1 second apart. The current code tries to launch the missile #5 five times...\n\nCan you fix this for us? You know, it's pretty critical code...\n\nNote: There are 5 missiles labeled i which is a number in {0, 1, 2, 3, 4}. The missile i should be launched after i seconds.\n*/\nfunction launchAll(launchMissile) {\n  for(let i = 0; i < 5; i++) {\n    setTimeout(function() {\n      launchMissile(i);\n    }, i * 1000);\n  }\n}\n"
  },
  {
    "path": "Number Format.js",
    "content": "/*\nDescription:\nFormat any integer provided into a string with \",\" (commas) in the correct places.\n\nExample:\n\nnumberFormat(100000); // return '100,000'\nnumberFormat(5678545); // return '5,678,545'\nnumberFormat(-420902); // return '-420,902'\n*/\nvar numberFormat = function (number) {\n  return number.toLocaleString()\n};\n"
  },
  {
    "path": "Number Shortening Filter.js",
    "content": "/*\nDescription:\nHere is a new kata that Codewars asked me to do related to interviewing and working in a production setting.\n\nYou might be familar with and have used Angular.js. Among other things, it lets you create your own filters that work as functions. You can then put these in a page to perform specific data changes, such as shortening a number to display a more concise notation.\n\nIn this kata, we will create a function which returns another function (or process, in Ruby) that shortens very long numbers. Given an initial array of values replace the Xth power of a given base. If the input of the returned function is not a numerical string, it should return the input itself as a string.\n\nHere's an example, which is worth a thousand words:\n\nfilter1 = shortenNumber(['','k','m'],1000);\nfilter1('234324') == '234k';\nfilter1('98234324') == '98m';\nfilter1([1,2,3]) == '1,2,3';\nfilter2 = shortenNumber(['B','KB','MB','GB'],1024);\nfilter2('32') == '32B';\nfilter2('2100') == '2KB';\nfilter2('pippi') == 'pippi';\nIf you like to test yourself on kata related to actual work and interviews, consider trying this kata where you will build a breadcrumb generator\n*/\nfunction shortenNumber(suffixes, base) {\n  return (number)=>{\n    if (number!=parseInt(number)) return number.toString()\n    let index=0;\n    while(number>base&&index<suffixes.length-1){\n      number/=base\n      index++\n    }\n    return Math.trunc(number)+suffixes[index]\n  }\n}\n"
  },
  {
    "path": "Number Zoo Patrol.js",
    "content": "/*\nDescription:\nBackground:\nYou're working in a number zoo, and it seems that one of the numbers has gone missing!\n\nZoo workers have no idea what number is missing, and are too incompetent to figure it out, so they're hiring you to do it for them.\n\nIn case the zoo loses another number, they want your program to work regardless of how many numbers there are in total.\n\nTask:\nWrite a function that takes a shuffled array of unique numbers from 1 to n with one element missing (which can be any number including n). Return this missing number.\n\nExamples:\nfindNumber([1, 3, 4]) => 2\nfindNumber([1, 2, 3]) => 4\nfindNumber([4, 2, 3]) => 1\n*/\nfunction findNumber(array) {\n  return ((1+(array.length + 1))*(array.length + 1))/2-array.reduce((sum, item) => sum + item, 0)\n}\n"
  },
  {
    "path": "Number of anagrams in an array of words.js",
    "content": "/*\nDescription:\nAn anagram is a word, a phrase, or a sentence formed from another by rearranging its letters. An example of this is \"angel\", which is an anagram of \"glean\".\n\nWrite a function that receives an array of words, and returns the total number of distinct pairs of anagramic words inside it.\n\nSome examples:\n\nThere are 2 anagrams in the array [\"dell\", \"ledl\", \"abc\", \"cba\"]\nThere are 7 anagrams in the array [\"dell\", \"ledl\", \"abc\", \"cba\", \"bca\", \"bac\"]\n*/\nfunction anagramCounter (wordsArray) {\n  let count=0;\n  for (let i=0;i<wordsArray.length-1;i++){\n    for (let j=i+1;j<wordsArray.length;j++){\n      if (wordsArray[i].split``.sort().join``===wordsArray[j].split``.sort().join``) {count++}\n    }\n  }\n  return count;\n}\n"
  },
  {
    "path": "Number of measurements to spot the counterfeit coin.js",
    "content": "/*\nDescription:\ncoins balance scale problemI found this interesting interview question just today:\n\n8 coins are given where all the coins have equal weight, except one. The odd one weights less than the others, not being of pure gold. In the worst case, how many iterations are actually needed to find the odd one out on a two plates scale.\n\nI am asking you then to tell me what is the minimum amount of weighings it will take to measure n coins in every possible occurrence (including worst case scenario, ie: without relying on luck at all).\n\nn is guaranteed to be a positive integer.\n\nTip: being able to think recursively might help here :p\n\nNote: albeit this is more clearly a logical than a coding problem, do not underestimate (or under-rank) the kata for requiring not necessarily wizard-class coding skills: a good coder is a master of pattern recognition and subsequent optimization ;)\n*/\nfunction howManyMeasurements(n){\n  return Math.ceil(Math.log(n)/Math.log(3))\n}\n"
  },
  {
    "path": "Number of permutations without repetitions.js",
    "content": "/*\nDescription:\nWrite a function that takes a number or a string and gives back the number of permutations without repetitions that can generated using all of its element.; more on permutations here.\n\nFor example, starting with:\n\n1\n45\n115\n\"abc\"\nYou could respectively generate:\n\n1\n45,54\n115,151,511\n\"abc\",\"acb\",\"bac\",\"bca\",\"cab\",\"cba\"\nSo you should have, in turn:\n\nperms(1)==1\nperms(45)==2\nperms(115)==3\nperms(\"abc\")==6\n*/\nfunction perms(element) { \n  var str = '' + element;\n  var counts = {};\n  var numerator = 1;\n  var denominator = 1;\n  for (var i = 0; i < str.length; i++) {\n    counts[str[i]] = (counts[str[i]] || 0) + 1;\n\n    numerator *= i + 1;\n    denominator *= counts[str[i]];\n  }\n  return numerator / denominator;\n}\n"
  },
  {
    "path": "Number pattern.js",
    "content": "/*\nDescription:\nWrite a function that returns the next number in the following sequence:\n\n(169, 225, 289, 361, 441)\n\nGood luck!\n\nP.S. If you like this kata, please remember to mark it as ready and assess the rank. P.P.S. If you have any questions or criticisms please list them in the comments section.\n*/\nvar answer = function() {\n    return 529\n}\n"
  },
  {
    "path": "Numerical Palindrome #1.5.js",
    "content": "/*\nDescription:\nA palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are:\n\n2332\n110011\n54322345\n\nYou'll be given 2 numbers as arguments: (num,s). Write a function which returns an array of s number of numerical palindromes that come after num. If num is a palindrome itself, it should be included in the count.\n\nReturn \"Not valid\" instead if any one of the inputs is not an integer or is less than 0.\n\nFor this kata, single digit numbers will NOT be considered numerical palindromes.\n\npalindrome(6,4) => [11,22,33,44]\npalindrome(59,3) => [66,77,88]\npalindrome(101,2) => [101,111]\npalindrome(\"15651\",5) => \"Not valid\" \npalindrome(1221,\"8\") => \"Not valid\" \n\nIn Haskell, the return type is a Maybe which returns Nothing if either of the inputs is negative.\"\n*/\nfunction palindrome(num,s) {\n  if (num!==parseInt(num)||s!==parseInt(s)||s<0||num<0) return 'Not valid'\n  const arr = []\n  for (let i=num;arr.length!==s;i++){\n  if (i.toString()===i.toString().split``.reverse().join``&&i.toString().length>1) arr.push(i)\n  }\n  return arr\n}\n"
  },
  {
    "path": "Numericals of a String.js",
    "content": "/*\nDescription:\nYou are given an input string.\n\nFor each symbol in the string if it's the first character occurence, replace it with a '1', else replace it with the amount of times you've already seen it...\n\nBut will your code be performant enough?\n\nExamples:\ninput   =  \"Hello, World!\"\nresult  =  \"1112111121311\"\n\ninput   =  \"aaaaaaaaaaaa\"\nresult  =  \"123456789101112\"\n*/\nfunction numericals(s){\n  const obj={}\n  return s.replace(/./g,v=>obj[v]=(obj[v]||0)+1)\n}\n"
  },
  {
    "path": "Numerology.js",
    "content": "/*\nDescription:\nIn numerology, every number has a certain meaning that expresses someones connection to the universe! This single digit integer can be calculated by adding up every digit in the birthdate: year, month, and date. Each time the sum exceeds 10, add up the 2 digits.\nFor example, new Date('06/14/2010') = 5\nSo, what is your number?\n*/\nfunction solution(date){\n  date=date.toLocaleDateString().split('-')\n  let ans=date.reduce((a,b)=>a+b*1,0);\n  return ans.toString().split('').reduce((a,b)=>a+b*1,0).toString().split('').reduce((a,b)=>a+b*1,0)\n  .toString().split('').reduce((a,b)=>a+b*1,0).toString().split('').reduce((a,b)=>a+b*1,0)\n}\n"
  },
  {
    "path": "Odd Even number of divisors.js",
    "content": "/*\nDescription:\nGiven an integer n return 'odd' if the number of its divisors is odd. Otherwise return 'even'.\n\nExamples:\n\nAll prime numbers have exactly two divisors (hence 'even')\n\nFor n=12 the divisors are [1,2,3,4,6,12] – 'even'\n\nFor n=4 the divisors are [1,2,4] – 'odd'\n*/\nfunction oddity(n){\n  return Math.sqrt(n) % 1 == 0 ? \"odd\" : \"even\"\n}\n"
  },
  {
    "path": "Odd-heavy Array.js",
    "content": "/*\nDescription:\nAn array is defined to be odd-heavy if it contains at least one odd element and every element whose value is odd is greater than every even-valued element.\n\neg.\n\nArray [11,4,9,2,8] is odd-heavy \nbecause:- its odd elements [11,9] are greater than all the even elements [4,2,8]\n\nArray [11,4,9,2,3,10] is not odd-heavy\nbecause:- one of it's even element 10 from [4,2,10] is greater than two of its odd elements [9,3] from [ 11,9,3]\nwrite a function called isOddHeavy or is_odd_heavy that accepts an integer array and returns true if the array is odd-heavy else return false.\n*/\nfunction isOddHeavy(n){\n  let odd = n.filter(v=>v%2!==0).sort((a,b)=>a-b)\n  let even = n.filter(v=>v%2==0)\n  if (!odd.length) return false\n  return even.every(v=>v<odd[0])\n}\n"
  },
  {
    "path": "Once.js",
    "content": "/*\nDescription:\nYou'll implement once, a function that takes another function as an argument, and returns a new version of that function that can only be called once.\n\nSubsequent calls to the resulting function should have no effect (and should return undefined).\n\nFor example:\n\nlogOnce = once(console.log)\nlogOnce(\"foo\") // -> \"foo\"\nlogOnce(\"bar\") // -> no effect\n*/\n\nfunction once(func) {\n    let called = false;\n    return function(...arguments) { \n        if (!called) { \n            called = true;\n            return func.apply(this,arguments);\n        }\n    }\n} \n"
  },
  {
    "path": "Only Duplicates.js",
    "content": "/*\nDescription:\nGiven a string, remove any characters that are unique from the string.\n\nExample:\n\ninput: \"abccdefee\"\n\noutput: \"cceee\"\n*/\nfunction onlyDuplicates(str) {\n  return str.split``.filter(v=>str.replace(new RegExp(v,'g'),'').length!==str.length-1).join``\n}\n"
  },
  {
    "path": "Ordinal Numbers.js",
    "content": "/*\nDescription:\nYou know how sometimes there are two letters at the end of a number? Like 1st, 2nd, 3rd, and so on? Those numbers are called \"ordinal numbers\"; numbers used to refer to a position in a series. It might be useful to have a function that returns those two letters so we can print it out and what-have-you.\n\nYour task is to write the ordinal(number, brief) function. number will be an integer, and brief will be an optional parameter. Sometimes 2nd and 3rd are shown as 2d and 3d, in certain fields (like legal or military stuff). So take this into account when you're writing your function. ordinal(number, brief) should return a string containing those two characters (or one character) that would be tagged onto the end of the number.\n\nThe units number (the last digit) should be used to determine the correct ordinal suffix. The following table should be used:\n\n0  1  2  3  4  5  6  7  8  9\nth st nd rd th th th th th th\nIf the \"brief\" notation is used, 2 and 3's suffix should be \"d\".\n\nIf the tens number (the second from last digit) is a 1 (from 10 to 19), the suffix should be \"th\".\n\nSome examples would be: 1st 11th 111th 121st 20th 52nd 903d (brief), and so on...\n\nTo find out more, check out the Wikipedia entry on Ordinal Numbers. (If there's anything not covered in this description you needed to know to complete the kata, please let me know; I don't want to require further reading for my katas.)\n*/\nfunction ordinal(number, brief) {\n  var n = ['th','st','nd','rd'],\n      m = number % 100,\n      k = ( n[( m - 20 ) % 10] || n[m] || n[0] );\n  return (brief && k[1] == 'd') ? 'd' : k;\n}\n"
  },
  {
    "path": "Ore Numbers.js",
    "content": "/*\nDescription:\nOre Numbers (also called Harmonic Divisor Numbers) are numbers for which the harmonic mean of all their divisors (including the number itself) equals an integer.\n\nFor example, 6 is an Ore Number because its harmonic mean is exactly 2:\n\nH(6) = 4 / (1/1 + 1/2 + 1/3 + 1/6) = 2\nYour task is to complete the function returns true if the given number is an Ore Number and false otherwise.\n\nYou can assume all inputs will be valid positive integers.\n\nHint: The harmonic mean is the total number of divisors divided by the sum of their reciprocals.\n*/\nfunction isOre(n){\n   let divisors = []\n   for (let i=0;i<=n;i++){\n     if (n%i===0) divisors.push(i)\n   }\n   let d = Math.round((divisors.length/divisors.reduce((a,b)=>a+1/b,0))*1000)/1000\n   return d===parseInt(d)\n}\n"
  },
  {
    "path": "Organise duplicate numbers in list.js",
    "content": "/*\nDescription:\nSam is an avid collector of numbers. Every time he finds a new number he throws it on the top of his number-pile. Help Sam organise his collection so he can take it to the International Number Collectors Conference in Cologne.\n\nGiven an array of numbers, your function should return an array of arrays, where each subarray contains all the duplicates of a particular number. Subarrays should be in the same order as the first occurence of the number they contain:\n\ngroup([3, 2, 6, 2, 1, 3])\n>>> [[3, 3], [2, 2], [6], [1]]\nAssume the input is always going to be an array of numbers. If the input is an empty array, an empty array should be returned.\n*/\nfunction group(arr) {\n  return [...new Set(arr)].map(n => arr.filter(x => x == n));\n}\n"
  },
  {
    "path": "PI approximation.js",
    "content": "/*\nDescription:\nThe aim of the kata is to try to show how difficult it can be to calculate decimals of an irrational number with a certain precision. We have chosen to get a few decimals of the number \"pi\" using the following infinite series (Leibniz 1646–1716):\n\nPI / 4 = 1 - 1/3 + 1/5 - 1/7 + ... which gives an approximation of PI / 4.\n\nhttp://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80\n\nTo have a measure of the difficulty we will count how many iterations are needed to calculate PI with a given precision.\n\nThere are several ways to determine the precision of the calculus but to keep things easy we will calculate to within epsilon of your language Math::PI constant. In other words we will stop the iterative process when the absolute value of the difference between our calculation and the Math::PI constant of the given language is less than epsilon.\n\nYour function returns an array or an arryList or a string or a tuple depending on the language (See sample tests) where your approximation of PI has 10 decimals\n\nIn Haskell you can use the function \"trunc10Dble\" (see \"Your solution\"); in Clojure you can use the function \"round\" (see \"Your solution\");in OCaml or Rust the function \"rnd10\" (see \"Your solution\") in order to avoid discusssions about the result.\n\nExample :\n\nyour function calculates 1000 iterations and 3.140592653839794 but returns:\niter_pi(0.001) --> [1000, 3.1405926538]\nUnfortunately, this series converges too slowly to be useful, as it takes over 300 terms to obtain a 2 decimal place precision. To obtain 100 decimal places of PI, it was calculated that one would need to use at least 10^50 terms of this expansion!\n\nAbout PI : http://www.geom.uiuc.edu/~huberty/math5337/groupe/expresspi.html\n*/\nfunction iterPi(epsilon) {\n  let pi = 0, iterations = 0, factor = 1, divider = 1;\n  while (Math.abs(Math.PI - (pi * 4)) >= epsilon) {\n    pi += factor / divider;\n    factor = -factor;\n    divider += 2;\n    iterations += 1;\n  }\n  return [iterations, +(pi * 4).toFixed(10)];\n}\n"
  },
  {
    "path": "Pad Left and Right.js",
    "content": "/*\nDescription:\nPad\nYou are exporting data from your environment that will be imported in another system, but you have a problem! Some data on your system doesn't contain the full length of required chars, it trimmed some data.\n\nRegistry Number   | Activity Code\n1337              | 1337\n60316817000448    | 6204000\nYou have to write two functions, padLeft and padRight that will fill the missing characters so the other system can import the data without any errors.\n\nRegistry Number   | Activity Code\n00000000001337    | 1337000\n60316817000448    | 6204000\nIf you try to pad to a certain length that would make your data shorter just leave it as is.\n\nIt is much easier to import and validate the data in the correct format, so help them to get the data in the other server!\n*/\nString.prototype.padLeft = function(ch, n) {\n  return this.padStart(n,ch);\n};\n\nString.prototype.padRight = function(ch, n) {\n  return this.padEnd(n,ch);\n};\n"
  },
  {
    "path": "Padovan numbers.js",
    "content": "/*\nDescription:\nThe Padovan sequence is the sequence of integers P(n) defined by the initial values\n\nP(0)=P(1)=P(2)=1\n\nand the recurrence relation\n\nP(n)=P(n-2)+P(n-3)\n\nThe first few values of P(n) are\n\n1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200, 265, ...\n\nTask\nThe task is to write a method that returns i-th Padovan number\n\n> Padovan.Get(0) == 1\n\n> Padovan.Get(1) == 1\n\n> Padovan.Get(2) == 1\n\n> Padovan.Get(n) == Padovan.Get(n-2) + Padovan.Get(n-3)\n*/\nfunction padovan(n) {\n    let arr = [1,1,1]\n    for (let i=2;i<n;i++){\n      arr.push(arr[i-1]+arr[i-2])\n    }\n    return arr[n]\n}\n"
  },
  {
    "path": "Pair of gloves.js",
    "content": "/*\nDescription:\nPair of gloves\nWinter is comming, you must prepare your ski holidays. The objective of this kata is to determine the number of pair of gloves you can constitute from the gloves you have in your drawer.\n\nA pair of gloves is constituted of two gloves of the same color.\n\nYou are given an array containing the color of each glove.\n\nYou must return the number of pair you can constitute.\n\nYou must not change the input array.\n\nExample :\n\nlet myGloves = ['red','green','red','blue','blue'];\nnumberOfPairs(myGloves) == 2;// red and blue\n\nlet redGloves = ['red','red','red','red','red','red'];\nnumberOfPairs(redGloves) == 3; // 3 red pairs\n*/\nfunction numberOfPairs(gloves){\n   let arr = gloves.slice().sort((a,b)=>a.localeCompare(b))\n   let pairs = 0;\n   for (let i=1;i<arr.length;i++){\n     if (arr[i-1]===arr[i]){\n       pairs++\n       i++\n     }\n   }\n   return pairs\n}\n"
  },
  {
    "path": "Palindrome for your Dome.js",
    "content": "/*\nDescription:\nA palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction. Famous examples include \"Amore, Roma\", \"A man, a plan, a canal: Panama\" and \"No 'x' in 'Nixon'\". - wikipedia\n\nOur goal is to determine whether or not a given string is a valid palindrome or not.\n\nLike the above examples, here are a few test cases which are also populated:\n\n\"Amore, Roma\" => valid\n\"A man, a plan, a canal: Panama\" => valid\n\"No 'x' in 'Nixon'\" => valid\n\"Abba Zabba, you're my only friend\" => invalid\nYou can see that they are case insensitive and disregards non alphanumeric characters. In addition to a few predefined tests, your function will also be tested against a random string generator 50 times which are guaranteed to produce valid palindromes.\n\nNotes:\n\nreverse/reverse! have been disabled for String/Array and reverse() for JS.\nreverse cannot get used in Haskell either\nthe empty string \"\" can be read forward or backward the same, it's a palindrome in our case.\n*/\n\nfunction palindrome(string) {\n  return string.replace(/[^a-z]/gi,'').toLowerCase().split('')\n  .map((v,i,arr)=>arr[i].indexOf(v)===arr[arr.length-i-1].lastIndexOf(v))\n  .filter(v=>v===false).length<1\n}\n"
  },
  {
    "path": "Palindromes Below.js",
    "content": "/*\nDescription:\nThe aim of this Kata is to modify the Fixnum ( JS: Number CS: extension for int) class to give it the palindrome_below ( JS: palindromeBelow CS: PalindromeBelow ) method. This method returns all numbers from and including 1 up to but not including itself that are palindromes for a given base.\n\nFor example in base 2 (binary)\n\n1 = \"1\"\n2 = \"10\"\n3 = \"11\"\n4 = \"100\"\nTherefore 1 and 3 are palindromes in base two and the method should return the following.\n\n    5..palindromeBelow(2)\n    => [1, 3]\n*/\nNumber.prototype.palindromeBelow = function(base){\n  return Array.from({length:this},(x,i)=>i+1).map(v=>v.toString(base)).filter(v=>v===v.split``.reverse().join``).map(v=>parseInt(v,base))\n}\n"
  },
  {
    "path": "Palindromic Numbers.js",
    "content": "/*\nDescription:\nA palindromic number is a number that remains the same when its digits are reversed. Like 16461, for example, it is \"symmetrical\".\n\nNon-palindromic numbers can be paired with palindromic ones via a series of operations. First, the non-palindromic number is reversed and the result is added to the original number. If the result is not a palindromic number, this is repeated until it gives a palindromic number.\n\nIt is not known whether all non-palindromic numbers can be paired with palindromic numbers in this way. While no number has been proven to be unpaired, many do not appear to be. For example, 196 does not yield a palindrome even after 700,000,000 iterations. Any number that never becomes palindromic in this way is known as a Lychrel number.\n\nThis Kata is about actually finding a palindromic number out of an original seed.\n\nYou will be given an number as input and in the output you must return a string containing the number of iterations (i.e. additions) you had to perform to reach the palindromic result and the palindromic number itself, separated by a space. In Haskell return a tuple (Int, Integer).\n\npalindromize(195) \n4 9339\n\npalindromize(265) \n5 45254\n\npalindromize(750) \n3 6666\n###Some Assumptions\n\nYou can assume that all numbers provided as input will be actually paired with a palindromic result and that you will reach that result in less than 1000 iterations and yield a palindrome.\n*/\nfunction palindromize(num){\n  for (let i=0;i<1000;i++){\n    if (num.toString().split``.reverse().join``===num.toString()) return i+' '+num\n    num+=num.toString().split``.reverse().join``*1\n  }\n}\n"
  },
  {
    "path": "Palindromization.js",
    "content": "/*\nDescription:\nYou are given string \"elements\" and an int \"n\". Your task is to return a string that is a palindrom using elements from the string \"elements\" with the length \"n\".\n\nThe format of the palindromization:\n\nYour palindrome begins with the first element of \"elements\".\nAfter obtaining a pair, you insert the next element in \"elements\" to the palindrome.\nThe next element will be paired inside the first pair.\nRepeat\nIf you have reached the last element of \"elements\" then repeat the process from the start.\nError cases: \nIf the string elements is empty or n is smaller than 2, return the string \"Error!\" \n\nExamples: \n<<<<<<< mine\n\nFor elements = \"123\" \nn = 2 => result = \"11\"\nn = 3 => result = \"121\"\nn = 4 => result = \"1221\"\nn = 5 => result = \"12321\"\nn = 6 => result = \"123321\"\nn = 7 => result = \"1231321\"\nn = 8 => result = \"12311321\"\nn = 9 => result = \"123121321\"\nn = 10=> result = \"1231221321\"\n=======\n*/\nfunction palindromization(s, n){\n  if(s==''||n<2) return 'Error!';\n  return s.repeat(n).slice(0,Math.floor(n/2))+s.repeat(n).slice(0,Math.ceil(n/2)).split('').reverse().join('');\n}\n"
  },
  {
    "path": "Parabolic Arc Length.js",
    "content": "/*\nDescription:\nWe want to approximate the length of a curve representing a function y = f(x) with a<= x <= b. First, we split the interval [a, b] into n sub-intervals with widths h1, h2, ... , hn by defining points x1, x2 , ... , xn-1 between a and b. This defines points P0, P1, P2, ... , Pn on the curve whose x-coordinates are a, x1, x2 , ... , xn-1, b and y-coordinates f(a), f(x1), ..., f(xn-1), f(b) . By connecting these points, we obtain a polygonal path approximating the curve.\n\nOur task is to approximate the length of a parabolic arc representing the curve y = x * x with x in the interval [0, 1]. We will take a common step h between the points xi: h1, h2, ... , hn = h = 1/n and we will consider the points P0, P1, P2, ... , Pn on the curve. The coordinates of each Pi are (xi, yi = xi * xi).\n\nThe function len_curve (or similar in other languages) takes n as parameter (number of sub-intervals) and returns the length of the curve truncated to 9 decimal places.\n*/\nfunction lenCurve(n) {\n    // your code\n    let res = 0;\n    let h = 1 / n;\n    for (let i = 0; i < 1; i += h)\n    {\n      res += Math.sqrt(Math.pow(h, 2) + Math.pow(f(i) - f(i + h), 2));\n      n -= 1;\n      if (n === 0)\n        break;\n    }\n    return parseFloat(res.toFixed(9));\n}\n"
  },
  {
    "path": "Parity bit - Error detecting code.js",
    "content": "/*\nDescription:\nIn telecomunications we use information coding to detect and prevent errors while sending data.\n\nA parity bit is a bit added to a string of binary code that indicates whether the number of 1-bits in the string is even or odd. Parity bits are used as the simplest form of error detecting code, and can detect a 1 bit error.\n\nIn this case we are using even parity: the parity bit is set to 0 if the number of 1-bits is even, and is set to 1 if odd.\n\nWe are using them for the transfer of ASCII characters in binary (7-bit strings): the parity is added to the end of the 7-bit string, forming the 8th bit.\n\nIn this Kata you are to test for 1-bit errors and return a new string consisting of all of the correct ASCII caracters in 7 bit format (removing the parity bit), or \"error\" in place of ASCII characters in which errors were detected.\n\nFor more information on parity bits: https://en.wikipedia.org/wiki/Parity_bit\n\nExamples\nCorrect 7 bit string with an even parity bit as the 8th bit:\n\n\"01011001\" <-- The \"1\" on the right is the parity bit.\nIn this example, there are three 1-bits. Three is an odd number, and the parity bit is set to 1. No errors are detected, so return \"0101100\" (7 bits).\n\nExample of a string of ASCII characters:\n\n\"01011001 01101110 01100000 01010110 10001111 01100011\"\nThis should return:\n\n\"0101100 error 0110000 0101011 error 0110001\"\n*/\nfunction parityBit(binary) {\n  return binary.replace(/\\b0*1(0*10*1)*0*\\b/g, 'error').replace(/\\d{8}/g, d => d.slice(0, 7));\n}\n"
  },
  {
    "path": "Parse a linked list from a string.js",
    "content": "/*\nDescription:\nParse a linked list from a string\nRelated Kata\nAlthough this Kata is not part of an official Series, you may want to complete this Kata before attempting this one as these two Kata are deeply related.\n\nPreloaded\nPreloaded for you is a class, struct or derived data type Node (depending on the language) used to construct linked lists in this Kata:\n\nclass Node {\n  constructor(data, next = null) {\n    this.data = data;\n    this.next = next;\n  }\n}\nPrerequisites\nThis Kata assumes that you are already familiar with the idea of a linked list. If you do not know what that is, you may want to read up on this article on Wikipedia. Specifically, the linked lists this Kata is referring to are singly linked lists, where the value of a specific node is stored in its data/$data/Data property, the reference to the next node is stored in its next/$next/Next property and the terminator for a list is null/NULL/nil/nullptr/null().\n\nAdditionally, this Kata assumes that you have basic knowledge of Object-Oriented Programming (or a similar concept) in the programming language you are undertaking. If you have not come across Object-Oriented Programming in your selected language, you may want to try out an online course or read up on some code examples of OOP in your selected language up to (but not necessarily including) Classical Inheritance.\n\nSpecifically, if you are attempting this Kata in PHP and haven't come across OOP, you may want to try out the first 4 Kata in this Series.\n\nTask\nCreate a function parse which accepts exactly one argument string/$string/s/strrep (or similar, depending on the language) which is a string representation of a linked list. Your function must return the corresponding linked list, constructed from instances of the Node class/struct/type. The string representation of a list has the following format: the value of the node, followed by a whitespace, an arrow and another whitespace (\" -> \"), followed by the rest of the linked list. Each string representation of a linked list will end in \"null\"/\"NULL\"/\"nil\"/\"nullptr\"/\"null()\" depending on the language you are undertaking this Kata in. For example, given the following string representation of a linked list:\n\n\"1 -> 2 -> 3 -> null\"\n... your function should return:\n\nnew Node(1, new Node(2, new Node(3)))\nNote that due to the way the constructor for Node is defined, if a second argument is not provided, the next/$next/Next field is automatically set to null/NULL/nil/nullptr (or equivalent in your language). That means your function could also return the following (if it helps you better visualise what is actually going on):\n\nnew Node(1, new Node(2, new Node(3, null)))\nAnother example: given the following string input:\n\n\"0 -> 1 -> 4 -> 9 -> 16 -> null\"\n... your function should return:\n\nnew Node(0, new Node(1, new Node(4, new Node(9, new Node(16)))))\nIf the input string is just \"null\"/\"NULL\"/\"nil\"/\"nullptr\"/\"null()\", return null/NULL/nil/nullptr/null() (or equivalent).\n\nFor the simplicity of this Kata, the values of the nodes in the string representation will always ever be non-negative integers, so the following would not occur: \"Hello World -> Goodbye World -> 123 -> null\"/\"Hello World -> Goodbye World -> 123 -> NULL\"/\"Hello World -> Goodbye World -> 123 -> nil\"/\"Hello World -> Goodbye World -> 123 -> nullptr\" (depending on the language). This also means that the values of each Node must also be non-negative integers so keep that in mind when you are parsing the list from the string.\n\nEnjoy, and don't forget to check out my other Kata Series :D\n*/\nconst parse = string => string.split(' -> ').slice(0, -1).reduceRight((a, b) => new Node(Number(b), a), null);\n"
  },
  {
    "path": "Pascal's Triangle #2.js",
    "content": "/*\nDescription:\nHere you will create the classic Pascal's triangle. Your function will be passed the depth of the triangle and you code has to return the corresponding pascal triangle up to that depth.\n\nThe triangle should be returned as a nested array.\n\nfor example:\n\npascal(5) // should return [[1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]\nTo build the triangle, start with a single 1 at the top, for each number in the next row you just take the two numbers above it and add them together (except for the edges, which are all 1), e.g.:\n\n              [1]\n            [1   1]\n          [1   2   1]\n        [1   3   3   1]\n*/\nfunction pascal(depth) {\n  let result = []\n  for (let i = 1; i <= depth; ++i) {\n    var row = []\n    for (let j = 0; j < i; ++j) {\n      row.push(j == 0 || j == i - 1 ? 1 : result[i-2][j-1] + result[i-2][j])\n    }\n    result.push(row)\n  }\n  return JSON.stringify(result)\n}\n"
  },
  {
    "path": "Pascal's Triangle.js",
    "content": "/*\nDescription:\n#Pascal's Triangle\n\nPascal's Triangle\n\nWikipedia article on Pascal's Triangle: http://en.wikipedia.org/wiki/Pascal's_triangle\n\nWrite a function that, given a depth (n), returns a single-dimensional array/list representing Pascal's Triangle to the n-th level.\n\nFor example:\n\npascalsTriangle(4) == [1,1,1,1,2,1,1,3,3,1]\n*/\n\n\nfunction pascalsTriangle(n) {\n  var pascal = [];\n  var idx = 0;\n  \n  for ( var i = 0; i < n; i++ ) {\n    idx = pascal.length - i;\n    for ( var j = 0; j < i+1; j++ ) {\n      if ( j === 0 || j === i ) {\n        pascal.push(1);\n      } else {\n        pascal.push( pascal[ idx+j ] + pascal[ idx+j-1 ] );\n      }\n    }\n  }\n  \n  return pascal;\n}\n"
  },
  {
    "path": "Password generator.js",
    "content": "/*\nDescription:\nYou need to write a password generator that meets the following criteria:\n\n6 - 20 characters long\ncontains at least one lowercase letter\ncontains at least one uppercase letter\ncontains at least one number\ncontains only alphanumeric characters (no special characters)\nReturn the random password as a string.\n\nNote: \"randomness\" is checked by counting the characters used in the generated passwords - all characters should have less than 50% occurance. Based on extensive tests, the normal rate is around 35%.\n*/\nfunction passwordGen(){\n  let password=''\n  while(!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[^\\W_]{6,20}$/.test(password)){\n    password=gen()\n  }\n  return password\n}\nfunction gen(){\n    let length = ~~(Math.random()*(20)+6)\n  let password = ''\n  let low = 'qwertyuiopasdfghjklzxcvbnm'\n  let upper = 'qwertyuiopasdfghjklzxcvbnm'.toUpperCase()\n  let num = '0123456789'\n  for (let i=0;i<length;i++){\n    let get = (()=> ~~(Math.random()*(3)))()\n    if (get===0){\n      password+=low[~~(Math.random()*26)]\n    }\n    if (get===1){\n      password+=upper[~~(Math.random()*26)]\n    }\n    if (get===2){\n      password+=num[~~(Math.random()*10)]\n    }\n  }\n  return password\n}\n"
  },
  {
    "path": "Paths in the Grid.js",
    "content": "/*\nDescription:\nPaths in the Grid\nYou have a grid with m rows and n columns.\nReturn number of ways that you can start from point A to reach point B.\nyou are only allowed to move right and up.\n\nalt text\n\nIn the picture, there are 10 pathes from A to B.\n\nHint: Use mathematical permutation and combination\n*/\nfunction numberOfRoutes(m, n){\n  return factorial(n+m) / factorial(n) /factorial(m)\n}\nfunction factorial(n){\n    return n ?n*factorial(n-1):1\n}\n"
  },
  {
    "path": "PatternCraft - Decorator.js",
    "content": "/*\nDescription:\nThe Decorator Design Pattern can be used, for example, in the StarCraft game to manage upgrades.\n\nThe pattern consists in \"incrementing\" your base class with extra functionality.\n\nA decorator will receive an instance of the base class and use it to create a new instance with the new things you want \"added on it\".\n\nYour Task\nComplete the code so that when a Marine gets a WeaponUpgrade it increases the damage by 1, and if it is a ArmorUpgrade then increase the armor by 1.\n\nYou have 3 classes:\n\nMarine: has a damage and an armor properties\nMarineWeaponUpgrade and MarineArmorUpgrade: upgrades to apply on marine. Accepts a Marine in the constructor and has the same properties as the Marine\nResouces\nPatternCraft > Decorator\nSourceMaking > Decorator\nWikipedia > Decorator\nPatternCraft series\nState Pattern\nStrategy Pattern\nVisitor Pattern\nDecorator Pattern\nAdapter Pattern\nCommand Pattern\nThe original PatternCraft series (by John Lindquist) is a collection of Youtube videos that explains some of the design patterns and how they are used (or could be) on StarCraft.\n*/\nclass Marine {\n  constructor(_damage, _armor) {\n    this.damage = _damage || 0;\n    this.armor = _armor || 0;\n  }\n}\n\nclass MarineWeaponUpgrade {\n  constructor(marine) {\n    this.damage = marine.damage + 1;\n    this.armor = marine.armor;\n  }\n}\n\nclass MarineArmorUpgrade {\n  constructor(marine) {\n    this.damage = marine.damage;\n    this.armor = marine.armor + 1;\n  }\n}\n"
  },
  {
    "path": "PatternCraft - State.js",
    "content": "/*\nDescription:\nThe State Design Pattern can be used, for example, to manage the state of a tank in the StarCraft game.\n\nThe pattern consists in isolating the state logic in different classes rather than having multiple ifs to determine what should happen.\n\nYour Task\nComplete the code so that when a Tank goes into SiegeMode it cannot move and its damage goes to 20. When it goes to TankMode it should be able to move and the damage should be set to 5.\n\nYou have 3 classes:\n\nTank: has a state, canMove and damage properties\nSiegeState and TankState: has canMove and damage properties\nNote: The tank initial state should be TankState.\n\nResources\nPatternCraft > State\nSourceMaking > State\nWikipedia > State\nPatternCraft series\nState Pattern\nStrategy Pattern\nVisitor Pattern\nDecorator Pattern\nAdapter Pattern\nCommand Pattern\nThe original PatternCraft series (by John Lindquist) is a collection of Youtube videos that explains some of the design patterns and how they are used (or could be) on StarCraft.\n*/\nclass SiegeState {\n  constructor() {\n  this.move=false\n  this.dmg=20\n  }\n}\n\nclass TankState {\n  constructor() {\n  this.move=true\n  this.dmg=5\n  }\n}\n\nclass Tank {\n  constructor() {\n  this.state=new TankState()\n  }\n  get canMove() {return this.state.move  }\n  get damage() {return this.state.dmg  }\n}\n"
  },
  {
    "path": "PatternCraft - Strategy.js",
    "content": "/*\nDescription:\nThe Strategy Design Pattern can be used, for example, to determine how a unit moves in the StarCraft game.\n\nThe pattern consists in having a different strategy to one functionality. A unit, for example, could move by walking or flying.\n\nYour Task\nComplete the code so that when a Viking is flying its position increases by 10 each time it moves. If it is walking then the position is increased by 1.\n\nIn this Kata, Viking starts as a ground unit when it is created.\n\nYou have 3 classes:\n\nViking: has a position, moveBehavior and move method.\nFly and Walk: the move behaviors with the move(unit) method. Fly has to move 10 positions at a time and Walk has to move 1.\nResouces\nPatternCraft > Strategy\nSourceMaking > Strategy\nWikipedia > Strategy\nPatternCraft series\nState Pattern\nStrategy Pattern\nVisitor Pattern\nDecorator Pattern\nAdapter Pattern\nCommand Pattern\nThe original PatternCraft series (by John Lindquist) is a collection of Youtube videos that explains some of the design patterns and how they are used (or could be) on StarCraft.\n*/\nclass Fly {\n  move(unit) {\n    return unit.position+=10\n  }\n}\n\nclass Walk {\n  move(unit) {\n    return unit.position++\n  }\n}\n\nclass Viking {\n  constructor() {\n  this.position=0\n  this.moveBehavior=new Walk()\n  }\n  \n  move() {\n    return this.moveBehavior.move(this)\n  }\n}\n"
  },
  {
    "path": "Pentabonacci.js",
    "content": "/*\nDescription:\nWe have the following sequence:\n\nf(0) = 0\nf(1) = 1\nf(2) = 1\nf(3) = 2\nf(4) = 4;\nf(n) = f(n-1) + f(n-2) + f(n-3) + f(n-4) + f(n-5);\nYour task is to give the number of total values for the odd terms of the sequence up to the n-th term (included). (The number n (of n-th term) will be given as a positive integer)\n\nThe values 1 (one) is the only that is duplicated in the sequence and should be counted only once.\n\nE.g.\n\ncount_odd_pentaFib(5) -----> 1 # because the terms up to 5 are: 0, 1, 1, 2, 4, 8 (only 1 is odd and counted once)\nOther examples:\n\n count_odd_pentaFib(10) ------> 3 #because the odds terms are: [1, 1, 31, 61] (three different values)\n\ncount_odd_pentaFib(15) ------> 5 # beacause the odd terms are: [1, 1, 31, 61, 1793, 3525] (five different values)\nGood luck !!\n\n(Your code should be fast. Many moderate high values will be waiting to test it.)\n*/\nfunction countOddPentaFib(n) {\n  return  Math.floor((n - 1) / 6) + Math.floor((n - 2) / 6) + 1\n}\n"
  },
  {
    "path": "Permutations and Dot Products.js",
    "content": "/*\nDescription:\nTask\nThe dot product is usually encountered in linear algebra or scientific computing. It's also called scalar product or inner product sometimes:\n\nIn mathematics, the dot product, or scalar product (or sometimes inner product in the context of Euclidean space), is an algebraic operation that takes two equal-length sequences of numbers (usually coordinate vectors) and returns a single number.\nWikipedia\n\nIn our case, we define the dot product algebraically for two vectors a = [a1, a2, …, an], b = [b1, b2, …, bn] as\n\ndot a b = a1 * b1 + a2 * b2 + … + an * bn.\nYour task is to find permutations of a and b, such that dot a b is minimal, and return that value. For example, the dot product of [1,2,3] and [4,0,1] is minimal if we switch 0 and 1 in the second vector.\n\nExamples\nminDot( [1,2,3,4,5], [0,1,1,1,0] ) = 6\nminDot( [1,2,3,4,5], [0,0,1,1,-4]) = -17\nminDot( [1,3,5]    , [4,-2,1]    ) = -3\nRemarks\nIf the list or array is empty, minDot should return 0. All arrays or lists will have the same length. Also, for the dynamically typed languages, all inputs will be valid lists or arrays, you don't need to check for undefined, null etc.\n\nNote: This kata is inspired by GCJ 2008.\n*/\nvar minDot = function(a,b){  \n  if (!a.length||!b.length) return 0\n  b=b.sort((a,b)=>b-a)\n  a=a.sort((a,b)=>a-b)\n  return a.map((v,i)=>v*b[i]).reduce((a,b)=>a+b,0)\n}\n"
  },
  {
    "path": "Persistent Bugger.",
    "content": "/*\nDescription:\nWrite a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit.\n\nFor example:\n\n persistence(39) === 3 // because 3*9 = 27, 2*7 = 14, 1*4=4\n                       // and 4 has only one digit\n\n persistence(999) === 4 // because 9*9*9 = 729, 7*2*9 = 126,\n                        // 1*2*6 = 12, and finally 1*2 = 2\n\n persistence(4) === 0 // because 4 is already a one-digit number\n*/\n\nfunction persistence(num) {\n   var times = 0;\n   \n   num = num.toString();\n   \n   while (num.length > 1) {\n     times++;\n     num = num.split('').map(Number).reduce((a, b) => a * b).toString();\n   }\n   \n   return times;\n}\n"
  },
  {
    "path": "Pete, the baker (part 2).js",
    "content": "/*\nDescription:\nPete is now mixing the cake mixture. He has the recipe, containing the required ingredients for one cake. He also might have added some of the ingredients already, but something is missing. Can you help him to find out, what he has to add to the mixture?\n\nRequirements:\n\nPete only wants to bake whole cakes. And ingredients, that were added once to the mixture, can't be removed from that. That means: if he already added the amount of flour for 2.8 cakes, he needs to add at least the amount of flour for 0.2 cakes, in order to have enough flour for 3 cakes.\nIf Pete already added all ingredients for an integer amount of cakes, you don't need to add anything, just return an empty hash then.\nIf Pete didn't add any ingredients at all, you need to add all ingredients for exactly one cake.\nFor simplicity we ignore all units and just concentrate on the numbers. E.g. 250g of flour is simply 250 (units) of flour and 1 lb of sugar is also simply 1 (unit) of sugar.\nIngredients, which don't have to be added to the mixture (missing amount = 0), must not be present in the result.\nExamples:\n\nvar recipe = {flour: 200, eggs: 1, sugar: 100};\n\ngetMissingIngredients(recipe, {flour: 50, eggs: 1}); // must return {flour: 150, sugar: 100}\ngetMissingIngredients(recipe, {}); // must return {flour: 200, eggs: 1, sugar: 100}\ngetMissingIngredients(recipe, {flour: 500, sugar: 200}); // must return {flour: 100, eggs: 3, sugar: 100}\n*/\nfunction getMissingIngredients(recipe, added) {\n  let max = 0, res = {};\n  for (let item in recipe)\n  {\n    if (item in added)\n      max = Math.max(Math.ceil(added[item] / recipe[item]), max);\n  }\n  if (max == 0)\n    return recipe;\n  for (let item in recipe)\n  {\n    if (!(item in added))\n      res[item] = max * recipe[item];\n    else if (added[item] < max * recipe[item])\n      res[item] = max * recipe[item] - added[item];\n  }\n  return res;\n}\n"
  },
  {
    "path": "Piano Kata, Part 1.js",
    "content": "/*\nDescription:\nYour Story\n\"A piano in the home meant something.\" - Fried Green Tomatoes at the Whistle Stop Cafe\n\nYou've just realized a childhood dream by getting a beautiful and beautiful-sounding upright piano from a friend who was leaving the country. You immediately started doing things like playing \"Heart and Soul\" over and over again, using one finger to pick out any melody that came into your head, requesting some sheet music books from the library, signing up for some MOOCs like Developing Your Musicianship, and wondering if you will think of any good ideas for writing piano-related katas and apps.\n\nNow you're doing an exercise where you play the very first (leftmost, lowest in pitch) key on the 88-key keyboard, which (as shown below) is white, with the little finger on your left hand, then the second key, which is black, with the ring finger on your left hand, then the third key, which is white, with the middle finger on your left hand, then the fourth key, also white, with your left index finger, and then the fifth key, which is black, with your left thumb. Then you play the sixth key, which is white, with your right thumb, and continue on playing the seventh, eighth, ninth, and tenth keys with the other four fingers of your right hand. Then for the eleventh key you go back to your left little finger, and so on. Once you get to the rightmost/highest, 88th, key, you start all over again with your left little finger on the first key. Your thought is that this will help you to learn to move smoothly and with uniform pressure on the keys from each finger to the next and back and forth between hands.\n\n\nYou're not saying the names of the notes while you're doing this, but instead just counting each key press out loud (not starting again at 1 after 88, but continuing on to 89 and so forth) to try to keep a steady rhythm going and to see how far you can get before messing up. You move gracefully and with flourishes, and between screwups you hear, see, and feel that you are part of some great repeating progression between low and high notes and black and white keys.\n\nYour Function\nThe function you are going to write is not actually going to help you with your piano playing, but just explore one of the patterns you're experiencing: Given the number you stopped on, was it on a black key or a white key? For example, in the description of your piano exercise above, if you stopped at 5, your left thumb would be on the fifth key of the piano, which is black. Or if you stopped at 92, you would have gone all the way from keys 1 to 88 and then wrapped around, so that you would be on the fourth key, which is white.\n\nYour function will receive an integer between 1 and 10000 (maybe you think that in principle it would be cool to count up to, say, a billion, but considering how many years it would take it is just not possible) and return the string \"black\" or \"white\" -- here are a few more examples:\n\n1     \"white\"\n12    \"black\"\n42    \"white\"\n100   \"black\"\n2017  \"white\"\nHave fun! And if you enjoy this kata, check out the sequel: Piano Kata, Part 2\n*/\nfunction blackOrWhiteKey(keyPressCount) {\n        switch ((keyPressCount-1) % 88 % 12) {\n          case  1:\n          case  4:\n          case  6:\n          case  9:\n          case 11:\n            return \"black\";\n          default:\n            return \"white\";\n        }   \n}\n"
  },
  {
    "path": "Piano Kata, Part 2.js",
    "content": "/*\nDescription:\nYou're continuing to enjoy your new piano, as described in Piano Kata, Part 1. You're also continuing the exercise where you start on the very first (leftmost, lowest in pitch) key on the 88-key keyboard, which (as shown below) is the note A, with the little finger on your left hand, then the second key, which is the black key A# (\"A sharp\"), with your left ring finger, then the third key, B, with your left middle finger, then the fourth key, C, with your left index finger, and then the fifth key, C#, with your left thumb. Then you play the sixth key, D, with your right thumb, and continue on playing the seventh, eighth, ninth, and tenth keys with the other four fingers of your right hand. Then for the eleventh key you go back to your left little finger, and so on. Once you get to the rightmost/highest, 88th, key, C, you start all over again with your left little finger on the first key.\n\n\n\n(If the Codewars Instructions pane resizes the above piano keyboard image to be too small to read the note labels of the black/sharp keys on your screen, click here to open a copy of the image in a new tab or window.)\n\nThis time, in addition to counting each key press out loud (not starting again at 1 after 88, but continuing on to 89 and so forth) to try to keep a steady rhythm going and to see how far you can get before messing up, you're also saying the name of each note. You wonder whether this may help you develop perfect pitch in addition to learning to just know which note is which, and -- as in Piano Kata, Part 1 -- helping you to learn to move smoothly and with uniform pressure on the keys from each finger to the next and back and forth between hands.\n\nThe function you are going to write will explore one of the patterns you're experiencing in your practice: Given the number you stopped on, which note was it? For example, in the description of your piano exercise above, if you stopped at 5, your left thumb would be on the fifth key of the piano, which is C#. Or if you stopped at 92, you would have gone all the way from keys 1 to 88 and then wrapped around, so that you would be on the fourth key, which is C.\n\nYour function will receive an integer between 1 and 10000 (maybe you think that in principle it would be cool to count up to, say, a billion, but considering how many years it would take it is just not possible) and return one of the strings \"A\", \"A#\", \"B\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", or \"G#\" indicating which note you stopped on -- here are a few more examples:\n\n1     \"A\"\n12    \"G#\"\n42    \"D\"\n100   \"G#\"\n2017  \"F\"\nHave fun!\n*/\nfunction whichNote(keyPressCount) {\n  const piano = [ \"A\", \"A#\", \"B\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\",\"A\", \"A#\", \"B\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\",\"A\", \"A#\", \"B\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\",\"A\", \"A#\", \"B\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\",\"A\", \"A#\", \"B\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\",\"A\", \"A#\", \"B\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\",\"A\", \"A#\", \"B\", \"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\",\"A\", \"A#\", \"B\", \"C\"]\n  return piano[(--keyPressCount)%piano.length]\n}\n"
  },
  {
    "path": "Ping-Pong service problem.js",
    "content": "/*\nDescription:\nPlaying ping-pong can be really fun! Unfortunatelly after a long and exciting play you can forget who's service turn it is. Let's do something about that!\n\nWrite a function that takes the current score as a string separated by : sign as an only parameter and returns \"first\" or \"second\" depending on whose service turn it is.\n\nWe're playing old-school, so the rule is that players take turn after every 5 services. That is until the score is 20:20 - from that moment each player serves 2 times in his turn.\n\nExamples:\n\nservice(\"0:0\") // => \"first\"\nservice(\"3:2\") // => \"second\"\nservice(\"21:20\") // => \"first\"\nservice(\"21:22\") // => \"second\"\nThere's no need to check if the passed parameter is valid - the score will be always provided in correct syntax and you don't need to check if one of the players has already won - that won't be the case.\n\nP.S. The game ends when one of the players reaches 21 points with minimum 2-point lead. If there's a current score of 20:20, the winner will be the first player to reach 2-point lead.\n*/\nfunction service(score){\n   let s = score.split`:`\n   let sc =s[0]*1+s[1]*1\n   let first = true\n    while(sc>40){\n     sc-=2\n     first=!first\n   }\n   while(sc>4){\n     sc-=5\n     first=!first\n   }\n   return first?'first':'second'\n}\n"
  },
  {
    "path": "Pizza pieces.js",
    "content": "/*\nDescription:\nDescription\nIn her trip to Italy, Elizabeth Gilbert made it her duty to eat perfect pizza. One day, she ordered one for dinner. And then some Italian friends appeared at her room.\n\nThe problem is that there were many people who ask for a piece of pizza at that moment. And she had a knife that only cuts straight.\n\nGiven a number K (K<=45000), help her get the maximum number of pieces possible (not necessarily of equal size) with K cuts. If K is a negative number, the result must be -1 (or Nothing in Haskell).\n\nExamples\nmaxPizza(0) == 1\nmaxPizza(1) == 2\nmaxPizza(3) == 7\n*/\nfunction maxPizza(cut) {\n    if (cut < 0)     return -1\n    else if (cut == 0) return 1\n    return (cut*(cut+1)/2)+1\n}\n"
  },
  {
    "path": "Playing on a chessboard.js",
    "content": "/*\nDescription:\nWith a friend we used to play the following game on a chessboard (8, rows, 8 columns). On the first row at the bottom we put numbers:\n\n1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9\n\nOn row 2 (2nd row from the bottom) we have:\n\n1/3, 2/4, 3/5, 4/6, 5/7, 6/8, 7/9, 8/10\n\nOn row 3:\n\n1/4, 2/5, 3/6, 4/7, 5/8, 6/9, 7/10, 8/11\n\nuntil last row:\n\n1/9, 2/10, 3/11, 4/12, 5/13, 6/14, 7/15, 8/16\n\nWhen all numbers are on the chessboard each in turn we toss a coin. The one who get \"head\" wins and the other gives him, in dollars, the sum of the numbers on the chessboard. We play for fun, the dollars come from a monopoly game!\n\nHow much can I (or my friend) win or loses for each game if the chessboard has n rows and n columns? Add all of the fractional values on an n by n sized board and give the answer as a simplified fraction.\n\nRuby, Python, JS, Coffee, Clojure, PHP, Elixir, Crystal, Typescript, Go:\n\nThe function called 'game' with parameter n (integer >= 0) returns as result an irreducible fraction written as an array of integers: [numerator, denominator]. If the denominator is 1 return [numerator].\n\nHaskell:\n'game' returns either a \"Left Integer\" if denominator is 1 otherwise \"Right (Integer, Integer)\"\n\nJava, C#, C++, F#, Swift, Reason:\n'game' returns a string that mimicks the array returned in Ruby, Python, JS, etc...\n\nFortran, Bash: 'game' returns a string\n\nIn Fortran - as in any other language - the returned string is not permitted to contain any redundant trailing whitespace: you can use dynamically allocated character strings.\n\n** see Example Test Cases for each language **\n*/\nfunction game(n) {\n   return n % 2 == 0 ? [(n/2) * n] : [n**2, 2];\n}\n"
  },
  {
    "path": "Playing with digits",
    "content": "/*\nDescription:\nSome numbers have funny properties. For example:\n\n89 --> 8¹ + 9² = 89 * 1\n\n695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2\n\n46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51\n\nGiven a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p we want to find a positive integer k, if it exists, such as the sum of the digits of n taken to the successive powers of p is equal to k * n. In other words:\n\nIs there an integer k such as : (a ^ p + b ^ (p+1) + c ^(p+2) + d ^ (p+3) + ...) = n * k\n\nIf it is the case we will return k, if not return -1.\n\nNote: n, p will always be given as strictly positive integers.\n\ndigPow(89, 1) should return 1 since 8¹ + 9² = 89 = 89 * 1\ndigPow(92, 1) should return -1 since there is no k such as 9¹ + 2² equals 92 * k\ndigPow(695, 2) should return 2 since 6² + 9³ + 5⁴= 1390 = 695 * 2\ndigPow(46288, 3) should return 51 since 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51\n*/\n\nfunction digPow(n, p){\n  let arr=n.toString().split('').map(Number).reduce((acc,cur,i,arr)=>acc+(Math.pow(arr[i],p+i)),0)/n\n  return (''+arr).includes('.')?-1:arr\n  }\n"
  },
  {
    "path": "Playing with passphrases.js",
    "content": "/*\nDescription:\nEveryone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently they can be guessed due to common cultural references. You can get your passphrases stronger by different means. One is the following:\n\nchoose a text in capital letters including or not digits and non alphabetic characters,\n\nshift each letter by a given number but the transformed letter must be a letter (circular shift),\nreplace each digit by its complement to 9,\nkeep such as non alphabetic and non digit characters,\ndowncase each letter in odd position, upcase each letter in even position (the first character is in position 0),\nreverse the whole result.\n#Example:\n\nyour text: \"BORN IN 2015!\", shift 1\n\n1 + 2 + 3 -> \"CPSO JO 7984!\"\n\n4 \"CpSo jO 7984!\"\n\n5 \"!4897 Oj oSpC\"\n\nWith longer passphrases it's better to have a small and easy program. Would you write it?\n\nhttps://en.wikipedia.org/wiki/Passphrase\n*/\n\nfunction playPass(s, n) {\n  return s.replace(/[A-Z]/g,x=>String.fromCharCode((x.charCodeAt(0)+n-65)%26+65)).replace(/\\d/g,x=>9-x).split('').map((x,i)=>i%2?x.toLowerCase():x.toUpperCase()).reverse().join('');\n}\n"
  },
  {
    "path": "Plenty of Fish in the Pond.js",
    "content": "/*\nDescription:\nIntroduction\n \tFish are an integral part of any ecosystem. Unfortunately, fish are often seen as high maintenance. Contrary to popular belief, fish actually reduce pond maintenance as they graze on string algae and bottom feed from the pond floor. They also make very enjoyable pets, providing hours of natural entertainment.\n \nDriving\nTask\n \tIn this Kata you are fish in a pond that needs to survive by eating other fish. You can only eat fish that are the same size or smaller than yourself. You must create a function called fish that takes a shoal of fish as an input string. From this you must work out how many fish you can eat and ultimately the size you will grow to.\nRules\n \t1.  Your size starts at 1\n2.  The shoal string will contain fish integers between 0-9\n3.  0 = algae and wont help you feed.\n4.  The fish integer represents the size of the fish (1-9).\n5.  You can only eat fish the same size or less than yourself.\n6.  You can eat the fish in any order you choose to maximize your size.\n7   You can and only eat each fish once.\n8.  The bigger fish you eat, the faster you grow. A size 2 fish equals two size 1 fish, size 3 fish equals three size 1 fish, and so on.\n9.  Your size increments by one each time you reach the amounts below.\nIncrease your size\nYour size will increase depending how many fish you eat and on the size of the fish. This chart shows the amount of size 1 fish you have to eat in order to increase your size.\n\nCurrent size\nAmount extra needed for next size\nTotal size 1 fish\nIncrease to size\n1\n4\n4\n2\n2\n8\n12\n3\n3\n12\n24\n4\n4\n16\n40\n5\n5\n20\n60\n6\n6\n24\n84\n7\n \netc...\n\nReturns\n \tReturn an integer of the maximum size you could be.\nExample 1\nshoal = \"11112222\"\n\n=> 4 fish of size 1\n=> 4 fish of size 2\nYou eat the 4 fish of size 1 (4 * 1 = 4) which increases your size to 2\nNow that you are size 2 you can eat the fish that are sized 1 or 2.\nYou then eat the 4 fish of size 2 (4 * 2 = 8) which increases your size to 3\nfish(\"11112222\") => 3\nExample 2\nshoal = \"111111111111\"\n\n=> 12 fish of size 1\nYou eat the 4 fish of size 1 (4 * 1 = 4) which increases your size to 2\nYou then eat the remainding 8 fish of size 1 (8 * 1 = 8) which increases your size to 3\nfish(\"111111111111\") => 3\nGood luck and enjoy!\n*/\nfunction fish(shoal){\n  let amount=0;\n  let size=1\n  let nextSize=4;\n  shoal=shoal.split``.sort().join``\n  for (let i=0;i<shoal.length;i++){\n    if (shoal[i]<=size){amount+=shoal[i]*1}\n    if (amount>=nextSize){\n      amount-=size*4\n      size++\n      nextSize=size*4\n    }\n  }\n  return size\n}\n"
  },
  {
    "path": "Point in Polygon.js",
    "content": "/*\nDescription:\nThe problem\nIn this kata, you're going write a function called pointInPoly to test if a point is inside a polygon.\n\nPoints will be represented as [x,y] arrays.\n\nThe polygon will be an array of points which are the polygon's vertices. The last point in the array connects back to the first point.\n\nYou can assume:\n\nThe polygon will be a valid simple polygon. That is, it will have at least three points, none of its edges will cross each other, and exactly two edges will meet at each vertex.\n\nIn the tests, the point will never fall exactly on an edge of the polygon.\n\nTesting\nTo help you visualize your test cases, the showAndTest(poly,point,inside) function is preloaded. It draws the polygon and point and then calls Test.expect automatically.\n\nSo if you call:\n\nshowAndTest([[-5, -5], [5, -5], [0, 5]], [0,0], true)\nthen you'll see:\n\nThe drawing window is 14x14 units wide and centered at the origin.\n*/\nfunction pointInPoly(poly, point) {\n        let n = poly.length;\n        let [x, y] = point;\n        let inside = false;\n        for (let i = 0, xi, yi, xj, yj, intersect, j = n - 1; i < n; j = i++) {\n            [xi, yi] = poly[i];\n            [xj, yj] = poly[j];\n            if (((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi)) // intersect\n                inside = !inside;\n        }\n        return inside;\n    }\n"
  },
  {
    "path": "Points On A Line.js",
    "content": "/*\nGiven some points (cartesian coordinates), return true if all of them lie on a line. Treat both an empty set and a single point as a line.\n\nonLine([[1,2], [7, 4], [22, 9]]);                 // returns true\nonLine([[1,2], [-3, -14], [22, 9]]);              // returns false\n*/\nfunction onLine(points) {\n  if (points.length < 3) return true;\n  const x = points.shift();\n  let a;\n  return points\n    .filter (function(y) { return !(x[0] == y[0] && x[1] == y[1]) })\n    .map    (function(y) { return a = (x[0] - y[0])/(x[1] - y[1]) })\n    .every  (function(y) { return y == a });\n}\n"
  },
  {
    "path": "Points in the circle.js",
    "content": "/*\nDescription:\nYou have the radius of a circle with the center in point (0,0).\n\nWrite a function that calculates the number of points in the circle where (x,y) - the cartesian coordinates of the points - are integers.\n\nExample: for radius = 2 the result should be 13.\n\n0 <= radius <= 1000\n![](http://i.imgur.com/1SMov3s.png)\n*/\nfunction pointsNumber(r){\n  let points = 0\n  for (let i=-r;i<=r;i++){\n    for (let j=-r;j<=r;j++){\n      if (i*i+j*j<=r*r) points++\n    }\n  }\n  return points;\n}\n"
  },
  {
    "path": "Pokemon Damage Calculator.js",
    "content": "/*\nDescription:\nIt's a Pokemon battle! Your task is to calculate the damage that a particular move would do using the following formula (not the actual one from the game):\n\ndamage = 50 * (attack/defense) * effectiveness\nMake sure to round the result up to the nearest integer.\n\nattack = your attack power\ndefense = the opponent's defense\neffectiveness = the effectiveness of the attack based on the matchup (see explanation below)\nEffectiveness:\n\nAttacks can be super effective, neutral, or not very effective depending on the matchup. For example, water would be super effective against fire, but not very effective against grass.\n\nSuper effective: 2x damage\nNeutral: 1x damage\nNot very effective: 0.5x damage\nTo prevent this kata from being tedious, you'll only be dealing with four types: fire, water, grass, and electric. Here is the effectiveness of each matchup:\n\nfire > grass\nfire < water\nfire = electric\n\nwater < grass\nwater < electric\n\ngrass = electric\n\nFor this kata, any type against itself is not very effective. Also, assume that the relationships between different types are symmetric (if a is super effective against b, then b is not very effective against a).\n\nThe function you will create is called calculateDamage, and it takes in your type and the opponent's type as strings and the attack and defense as numbers.\n*/\nfunction calculateDamage(yourType, opponentType, attack, defense) {\n  const outputLib = {\n    fire: { fire: 0.5, grass: 2, water: 0.5, electric: 1 },\n    grass: { fire: 0.5, grass: 0.5, water: 2, electric: 1 },\n    water: { fire: 2, grass: 0.5, water: 0.5, electric: 0.5 },\n    electric: { fire: 1, grass: 1, water: 2, electric: 0.5 }\n  };\n\n  return Math.ceil(50 * (attack / defense) * outputLib[yourType][opponentType]);\n}\n"
  },
  {
    "path": "Polybius square cipher - encode.js",
    "content": "/*\nDescription:\nImplement the Polybius square cipher.\n\nReplace every letter with a two digit number. The first digit is the row number, and the second digit is the column number of following square. Letters 'I' and 'J' are both 24 in this cipher:\n\n1\t2\t3\t4\t5\n1\tA\tB\tC\tD\tE\n2\tF\tG\tH\tI/J\tK\n3\tL\tM\tN\tO\tP\n4\tQ\tR\tS\tT\tU\n5\tV\tW\tX\tY\tZ\nInput will be valid (only spaces and uppercase letters from A to Z), so no need to validate them.\n\nExamples\npolybius('A')  // \"11\"\npolybius('IJ') // \"2424\"\npolybius('CODEWARS') // \"1334141552114243\"\npolybius('POLYBIUS SQUARE CIPHER') // \"3534315412244543 434145114215 132435231542\"\n*/\nfunction polybius (text) {\n return text.split(' ').map(v=>v.split('').map(v=>cipher[v]).join('')).join(' ')\n}\nconst cipher={A:11,B:12,C:13,D:14,E:15,F:21,G:22,H:23,I:24,J:24,K:25,\nL:31,M:32,N:33,O:34,P:35,Q:41,R:42,S:43,T:44,U:45,V:51,W:52,X:53,Y:54,Z:55}\n"
  },
  {
    "path": "Pong! [Basics].js",
    "content": "/*\nDescription:\nLets play some Pong!\n\npong\n\nFor those who don't know what Pong is, it is a simple arcade game where two players can move their paddles to hit a ball towards the opponent's side of the screen, gaining a point for each opponent's miss. You can read more about it here.\n\nTask:\nYou must finish the Pong class. It has a constructor which accepts the maximum score a player can get throughout the game, and a method called play. This method determines whether the current player hit the ball or not, i.e. if the paddle is at the sufficient height to hit it back. There're 4 possible outcomes: player successfully hits the ball back, player misses the ball, player misses the ball and his opponent reaches the maximum score winning the game, either player tries to hit a ball despite the game being over. You can see the input and output description in detail below.\n\n\"Play\" method input:\nball position - The Y coordinate of the ball\nplayer position - The Y coordinate of the centre(!) of the current player's paddle\n\"Play\" method output:\nOne of the following strings:\n\n\"Player X has hit the ball!\" - If the ball \"hits\" the paddle\n\"Player X has missed the ball!\" - If the ball is above/below the paddle\n\"Player X has won the game!\" - If one of the players has reached the maximum score\n\"Game Over!\" - If the game has ended but either player still hits the ball\nImportant notes:\nPlayers take turns hitting the ball, always starting the game with the Player 1.\nThe paddles are 7 pixels in height.\nThe ball is 1 pixel in height.\nExample\nlet game = new Pong(2); // Here we say that the score to win is 2\ngame.play(50, 53)  -> \"Player 1 has hit the ball!\";     // Player 1 hits the ball\ngame.play(100, 97) -> \"Player 2 has hit the ball!\";     // Player 2 hits it back\ngame.play(0, 4)    -> \"Player 1 has missed the ball!\";  // Player 1 misses so Player 2 gains a point\ngame.play(25, 25)  -> \"Player 2 has hit the ball!\";     // Player 2 hits the ball\ngame.play(75, 25)  -> \"Player 2 has won the game!\";     // Player 1 misses again. Having 2 points Player 2 wins, so we return the corresponding string\ngame.play(50, 50)  -> \"Game Over!\";                     // Another turn is made even though the game is already over\n*/\nclass Pong {\n  constructor(maxScore) {\n    this.maxScore = maxScore;\n    this.f=0\n    this.s=0\n    this.p1=false\n  }\n  \n  play(ballPos, playerPos) {\n    if (this.f===this.maxScore||this.s===this.maxScore) return \"Game Over!\"\n    this.p1=!this.p1\n    if (this.p1){\n      if (Math.abs(playerPos-ballPos)>3){\n        this.f++\n        if (this.f===this.maxScore) return \"Player 2 has won the game!\"\n        return \"Player 1 has missed the ball!\"\n      } else {\n        return \"Player 1 has hit the ball!\"\n      }\n    } else {\n      if (Math.abs(playerPos-ballPos)>3){\n        this.s++\n        if (this.s===this.maxScore) return \"Player 1 has won the game!\"\n        return \"Player 2 has missed the ball!\"\n      } else {\n        return \"Player 2 has hit the ball!\"\n      }\n    }\n  }\n}\n"
  },
  {
    "path": "Positions Average.js",
    "content": "/*\nDescription:\nSuppose you have 4 numbers: '0', '9', '6', '4' and 3 strings composed with them:\n\ns1 = \"6900690040\"\ns2 = \"4690606946\"\ns3 = \"9990494604\"\nCompare s1 and s2 to see how many positions they have in common: 0 at index 3, 6 at index 4, 4 at index 8 ie 3 common positions out of ten.\n\nCompare s1 and s3 to see how many positions they have in common: 9 at index 1, 0 at index 3, 9 at index 5 ie 3 common positions out of ten.\n\nCompare s2 and s3. We find 2 common positions out of ten.\n\nSo for the 3 strings we have 8 common positions out of 30 ie 0.2666... or 26.666...%\n\nGiven n substrings (n >= 2) in a string s our function pos_average will calculate the average percentage of positions that are the same between the (n * (n-1)) / 2 sets of substrings taken amongst the given n substrings. It can happen that some substrings are duplicate but since their ranks are not the same in s they are considered as different substrings.\n\nThe function returns the percentage formatted as a float with 10 decimals but the result is tested at 1e.-9 (see function assertFuzzy in the tests).\n\nExample:\nGiven string s = \"444996, 699990, 666690, 096904, 600644, 640646, 606469, 409694, 666094, 606490\" composing a set of n = 10 substrings (hence 45 combinations), pos_average returns 29.2592592593.\n\nIn a set the n substrings will have the same length ( > 0 ).\n\nNotes\nYou can see other examples in the \"Sample tests\".\n*/\nfunction posAverage(s) {\n    let com=0;\n    let all=0;\n    const arr = s.split`, `\n    for (let i=0;i<arr.length-1;i++){\n      for (let j=i+1;j<arr.length;j++){\n        let tempArr=arr[j].split``\n        arr[i].split``.map((v,z)=>v===tempArr[z]?com++:all++)\n      }\n    }\n    return com / (all+com) * 100;\n}\n"
  },
  {
    "path": "Prefill an Array.js",
    "content": "/*\nDescription:\nCreate the function prefill that returns an array of n elements that all have the same value v. See if you can do this without using a loop.\n\nYou have to validate input:\n\nv can be anything (primitive or otherwise)\nif v is ommited, fill the array with undefined\nif n is 0, return an empty array\nif n is anything other than an integer or integer-formatted string (e.g. '123') that is >=0, throw a TypeError\nWhen throwing a TypeError, the message should be n is invalid, where you replace n for the actual value passed to the function.\n\nCode Examples\n\n    prefill(3,1) --> [1,1,1]\n\n    prefill(2,\"abc\") --> ['abc','abc']\n\n    prefill(\"1\", 1) --> [1]\n\n    prefill(3, prefill(2,'2d'))\n      --> [['2d','2d'],['2d','2d'],['2d','2d']]\n\n    prefill(\"xyz\", 1)\n      --> throws TypeError with message \"xyz is invalid\"\n*/\n\nfunction prefill(n, v) {\n  if (parseInt(n) !== Math.abs(n)) throw new TypeError(`${n} is invalid`);\n  return +n ? Array(n).fill(v) : [];\n}\n"
  },
  {
    "path": "Prime Factors.js",
    "content": "/*\nDescription:\nPrime Factors\nInspired by one of Uncle Bob's TDD Kata\n\nWrite a function that generates factors for a given number.\n\nThe function takes an integer on the standard input and returns a list of integers (ObjC: array of NSNumbers representing integers). That list contains the prime factors in numerical sequence.\n\nExamples\n1  ==>  []\n3  ==>  [3]\n8  ==>  [2, 2, 2]\n9  ==>  [3, 3]\n12 ==>  [2, 2, 3]\n*/\nconst prime_factors = n => {\n  const factors = [];\n  for (let i = 2; i <= n; i++) {\n    while (n % i == 0) {\n      factors.push(i);\n      n /= i;\n    }\n  }\n  return factors;\n}\n"
  },
  {
    "path": "Prime factorization.js",
    "content": "/*\nDescription:\nThe prime factorization of a positive integer is a list of the integer's prime factors, together with their multiplicities; the process of determining these factors is called integer factorization. The fundamental theorem of arithmetic says that every positive integer has a single unique prime factorization.\n\nThe prime factorization of 24, for instance, is (2^3) * (3^1).\n\nWrite a class called PrimeFactorizer whose constructor accepts exactly 1 number (a positive integer) and has a property factor containing an object where the keys are prime numbers as strings and the values are the multiplicities.\n\nnew PrimeFactorizer(24).factor //should return { '2': 3, '3': 1 }\n*/\nfunction PrimeFactorizer(n) {\n  let i, factors = {};\n  for (i=2; i <= n; i++) {\n    while (n%i === 0) {\n      factors[i] = 1 + (factors[i]||0); n /= i;\n    }\n  }\n  return {factor:factors};\n}\n"
  },
  {
    "path": "Primorial Of a Number.js",
    "content": "/*\nDescription:\nDefinition (Primorial Of a Number)\nIs similar to factorial of a number, In primorial, not all the natural numbers get multiplied, only prime numbers are multiplied to calculate the primorial of a number. It's denoted with P#.\n\nTask\nGiven a number N , calculate its primorial. !alt  !alt\n\nNotes\nOnly positive numbers will be passed (N > 0) .\nInput >> Output Examples:\n1- numPrimorial (3) ==> return (30)\nExplanation:\nSince the passed number is (3) ,Then the primorial should obtained by multiplying 2 * 3 * 5 = 30 .\n\nMathematically written as , P3# = 30 .\n2- numPrimorial (5) ==> return (2310)\nExplanation:\nSince the passed number is (5) ,Then the primorial should obtained by multiplying 2 * 3 * 5 * 7 * 11 = 2310 .\n\nMathematically written as , P5# = 2310 .\n3- numPrimorial (6) ==> return (30030)\nExplanation:\nSince the passed number is (6) ,Then the primorial should obtained by multiplying 2 * 3 * 5 * 7 * 11 * 13 = 30030 .\n\nMathematically written as , P6# = 30030 .\nPlaying with Numbers Series\nPlaying With Lists/Arrays Series\nFor More Enjoyable Katas\nALL translations are welcomed\nEnjoy Learning !!\nZizou\n*/\nfunction numPrimorial(n){\n  let arr = [];\n  for (let i=1;;i++){\n    if (n===arr.length){break}\n    if (isPrime(i)) arr.push(i)\n  }\n  return arr.reduce((a,b)=>a*b,1)\n}\nfunction isPrime(n) {\n  let rt = Math.sqrt(n);\n  for(let i = 2; i <= rt; i++) {\n    if(n % i === 0) return false; \n  }\n  return n !== 1;\n}\n"
  },
  {
    "path": "Prize Draw.js",
    "content": "/*\nDescription:\nTo participate in a prize draw each one gives his/her firstname.\n\nEach letter of a firstname has a value which is its rank in the English alphabet. A and a have rank 1, B and b rank 2 and so on.\n\nThe length of the firstname is added to the sum of these ranks hence a number som.\n\nAn array of random weights is linked to the firstnames and each som is multiplied by its corresponding weight to get what they call a winning number.\n\nExample:\n\nnames: \"COLIN,AMANDBA,AMANDAB,CAROL,PauL,JOSEPH\"\nweights: [1, 4, 4, 5, 2, 1]\n\nPauL -> som = length of firstname + 16 + 1 + 21 + 12 = 4 + 50 -> 54\nThe *weight* associated with PauL is 2 so PauL's *winning number* is 54 * 2 = 108.\nNow one can sort the firstnames in decreasing order of the winning numbers. When two people have the same winning number sort them alphabetically by their firstnames.\n\nTask:\nparameters: st a string of firstnames, we an array of weights, n a rank\n\nreturn: the firstname of the participant whose rank is n (ranks are numbered from 1)\n\nExample:\nnames: \"COLIN,AMANDBA,AMANDAB,CAROL,PauL,JOSEPH\"\nweights: [1, 4, 4, 5, 2, 1]\nn: 4\n\nThe function should return: \"PauL\"\nNote:\nIf st is empty return \"No participants\".\n\nIf n is greater than the number of participants then return \"Not enough participants\".\n\nSee Examples Test Cases for more examples.\n*/\nfunction rank(st, we, n) {\n    let arr = st.toLowerCase().split`,`.map((v,i)=>(v.split``.map(v=>v.charCodeAt()-96).reduce((a,b)=>a+b,0)+v.length)*we[i])\n    const entries = st.split`,`.map((v,i)=>[arr[i],v]).sort((a,b)=>a[0]===b[0]?a[1].localeCompare(b[1]):b[0]-a[0])\n    if (!st.length) return \"No participants\"\n    return entries[n-1]?entries[n-1][1]:\"Not enough participants\"\n}\n"
  },
  {
    "path": "Proof Read.js",
    "content": "/*\nDescription:\nYou've just finished writing the last chapter for your novel when a virus suddenly infects your document. It has swapped the 'i's and 'e's in 'ei' words and capitalised random letters. Write a function which will:\n\na) remove the spelling errors in 'ei' words. (Example of 'ei' words: their, caffeine, deceive, weight)\n\nb) only capitalise the first letter of each sentence. Make sure the rest of the sentence is in lower case.\n\nExample: He haD iEght ShOTs of CAffIEne. --> He had eight shots of caffeine.\n*/\nfunction proofread (str) { \n  return str.split`. `.map(v=>v[0].toUpperCase()+v.slice(1).toLowerCase()).join`. `.replace(/ie/g,'ei')\n}\n"
  },
  {
    "path": "Pyramid Array.js",
    "content": "/*\nDescription:\nWrite a function that when given a number >= 0, returns an Array of ascending length subarrays.\n\npyramid(0) => [ ]\npyramid(1) => [ [1] ]\npyramid(2) => [ [1], [1, 1] ]\npyramid(3) => [ [1], [1, 1], [1, 1, 1] ]\nNote: the subarrays should be filled with 1s\n*/\nfunction pyramid(n) {\n  return Array.from({length:n},(x,i)=>Array(i+1).fill(1))\n}\n"
  },
  {
    "path": "Quick (n choose k) calculator.js",
    "content": "/*\nDescription:\nYou may be familiar with the concept of combinations: for example, if you take 5 cards from a 52 cards deck as you would playing poker, you can have a certain number (2,598,960, would you say?) of different combinations.\n\nIn mathematics the number of k combinations you can have taking from a set of n elements is called the binomial coefficient of n and k, more popularly called n choose k.\n\nThe formula to compute it is relatively simple: n choose k==n!/(k!*(n-k)!), where ! of course denotes the factorial operator.\n\nYou are now to create a choose function that computes the binomial coefficient, like this:\n\nchoose(1,1)==1\nchoose(5,4)==5\nchoose(10,5)==252\nchoose(10,20)==0\nchoose(52,5)==2598960\nBe warned: a certain degree of optimization is expected, both to deal with larger numbers precision (and their rounding errors in languages like JS) and computing time.\n*/\nfunction choose(n,k){\n   for (var i=1; k; i *= (n - (k - 1)) / k--){}\n   return Math.round(i)\n}\n"
  },
  {
    "path": "README.md",
    "content": "# CodeWars-6-kyu-Soluitions\nCreated by https://github.com/Automedon\n"
  },
  {
    "path": "RNA to Protein Sequence Translation.js",
    "content": "/*\nDescription:\nThe central dogma of molecular biology is that DNA is transcribed into RNA, which is then tranlsated into protein. RNA, like DNA, is a long strand of nucleic acids held together by a sugar backbone (ribose in this case). Each segment of three bases is called a codon. Molecular machines called ribosomes translate the RNA codons into amino acid chains, called polypeptides which are then folded into a protein.\n\nProtein sequences are easily visualized in much the same way that DNA and RNA are, as large strings of letters. An important thing to note is that the 'Stop' codons do not encode for a specific amino acid. Their only function is to stop translation of the protein, as such they are not incorporated into the polypeptide chain. 'Stop' codons should not be in the final protein sequence. To save a you a lot of unnecessary (and boring) typing the keys and values for your amino acid dictionary are provided.\n\nGiven a string of RNA, create a funciton which translates the RNA into its protein sequence. Note: the test cases will always produce a valid string.\n\nprotein('UGCGAUGAAUGGGCUCGCUCC') returns 'CDEWARS'\nIncluded as test cases is a real world example! The last example test case encodes for a protein called green fluorescent protein; once spliced into the genome of another organism, proteins like GFP allow biologists to visualize cellular processes!\n*/\nfunction protein(rna) {\n const arr=[];\n for (let i=0;i<rna.length;i+=3){\n   arr.push(rna.slice(i,i+3))\n }\n return arr.map(v=>dict[v]).join``\n}\nconst dict={\n      // Phenylalanine\n    'UUC':'F', 'UUU':'F',\n    // Leucine\n    'UUA':'L', 'UUG':'L', 'CUU':'L', 'CUC':'L','CUA':'L','CUG':'L', \n    // Isoleucine\n    'AUU':'I', 'AUC':'I', 'AUA':'I', \n    // Methionine\n    'AUG':'M', \n    // Valine\n    'GUU':'V', 'GUC':'V', 'GUA':'V', 'GUG':'V', \n    // Serine\n    'UCU':'S', 'UCC':'S', 'UCA':'S', 'UCG':'S', 'AGU':'S', 'AGC':'S', \n    // Proline\n    'CCU':'P', 'CCC':'P', 'CCA':'P', 'CCG':'P', \n    // Threonine\n    'ACU':'T', 'ACC':'T', 'ACA':'T', 'ACG':'T',\n    // Alanine\n    'GCU':'A', 'GCC':'A', 'GCA':'A', 'GCG':'A', \n    // Tyrosine\n    'UAU':'Y', 'UAC':'Y', \n    // Histidine\n    'CAU':'H', 'CAC':'H',\n    // Glutamine\n    'CAA':'Q', 'CAG':'Q', \n    // Asparagine\n    'AAU':'N', 'AAC':'N', \n    // Lysine\n    'AAA':'K', 'AAG':'K',\n    // Aspartic Acid\n    'GAU':'D', 'GAC':'D', \n    // Glutamic Acid\n    'GAA':'E', 'GAG':'E',\n    // Cystine\n    'UGU':'C', 'UGC':'C',\n    // Tryptophan\n    'UGG':'W', \n    // Arginine\n    'CGU':'R', 'CGC':'R', 'CGA':'R', 'CGG':'R', 'AGA':'R', 'AGG':'R', \n    // Glycine\n    'GGU':'G',  'GGC':'G', 'GGA':'G', 'GGG':'G', \n    // Stop codon\n    'UAA':'', 'UGA':'', 'UAG':'',\n}\n"
  },
  {
    "path": "Rainfall.js",
    "content": "/*\nDescription:\ndataand data1 are two strings with rainfall records of a few cities for months from January to December. The records of towns are separated by \\n. The name of each town is followed by :.\n\ndata and towns can be seen in \"Your Test Cases:\".\n\nTask:\nfunction: mean(town, strng) should return the average of rainfall for the city town and the strng data or data1 (In R and Julia this function is called avg).\nfunction: variance(town, strng) should return the variance of rainfall for the city town and the strng data or data1.\nExamples:\nmean(\"London\", data), 51.19(9999999999996) \nvariance(\"London\", data), 57.42(833333333374)\nNotes:\nif functions mean or variance have as parameter town a city which has no records return -1 or -1.0 (depending on the language)\nDon't truncate or round: the tests will pass if abs(your_result - test_result) <= 1e-2 or abs((your_result - test_result) / test_result) <= 1e-6 depending on the language.\nShell tests only variance\nA ref: http://www.mathsisfun.com/data/standard-deviation.html\ndata and data1 (can be named d0 and d1 depending on the language; see \"Sample Tests:\") are adapted from: http://www.worldclimate.com\n*/\n\nfunction calculateData(town, strng, calulateCallback) {\n  if (!towns.some(t => t == town)) {\n    return -1;\n  }\n\n  const allData = strng.split(\"\\n\");\n  for (const data of allData) {\n    if (data.indexOf(town) !== 0) {\n      continue;\n    }\n\n    const monthlyData = data\n      .replace(/[a-zA-Z\\:\\s]+/g, \"\")\n      .split(\",\")\n      .map(Number.parseFloat);\n    return calulateCallback(monthlyData);\n  }\n\n  return -1;\n}\n\nfunction mean(town, strng) {\n  return calculateData(town, strng, d => d.reduce((p, c) => p + c) / d.length);\n}\n\nfunction variance(town, strng) {\n  const avg = mean(town, strng);\n  return calculateData(\n    town,\n    strng,\n    d => d.reduce((p, c) => p + Math.pow(c - avg, 2), 0) / d.length\n  );\n}\nconst towns = [\n  \"Rome\",\n  \"London\",\n  \"Paris\",\n  \"NY\",\n  \"Vancouver\",\n  \"Sydney\",\n  \"Bangkok\",\n  \"Tokyo\",\n  \"Beijing\",\n  \"Lima\",\n  \"Montevideo\",\n  \"Caracas\",\n  \"Madrid\",\n  \"Berlin\"\n];\n"
  },
  {
    "path": "Range function.js",
    "content": "/*\nDescription:\nCreate range generator function that will take up to 3 parameters - start value, step and stop value. This function should return an iterable object with numbers. For simplicity, assume all parameters to be positive numbers.\n\nExamples:\n\nrange(5) --> 1,2,3,4,5\nrange(3, 7) --> 3,4,5,6,7\nrange(2, 3, 15) --> 2,5,8,11,14\n*/\nfunction range(a,b,c){\n  if (a&&b&&c){\n    return Array.from({length:c/b},(v,i)=>a+i*b)\n  } else if (a&&b){\n    return Array.from({length:b-a+1},(v,i)=>i+a)\n  } else {\n    return Array.from({length:a},(v,i)=>i+1)\n  }\n}\n"
  },
  {
    "path": "Rank Vector.js",
    "content": "/*\nDescription:\nGiven an array (or list) of scores, return the array of ranks for each value in the array. The largest value has rank 1, the second largest value has rank 2, and so on. Ties should be handled by assigning the same rank to all tied values. For example:\n\nranks([9,3,6,10]) = [2,4,3,1]\nand\n\nranks([3,3,3,3,3,5,1]) = [2,2,2,2,2,1,7]\nbecause there is one 1st place value, a five-way tie for 2nd place, and one in 7th place.\n*/\nfunction ranks(a) {\n  let sorted=a.slice().sort((a,b)=>b-a);\n  return a.map(v=>sorted.indexOf(v)+1)\n}\n"
  },
  {
    "path": "Ranking System.js",
    "content": "/*\nDescription:\nYou are given an array of unique numbers. The numbers represent points. The higher the number the higher the points. In the array [1,3,2] 3 is the highest point value so it gets 1st place. 2 is the second highest so it gets second place. 1 is the 3rd highest so it gets 3rd place.\n\nYour task is to return an array giving each number its rank in the array.\n\ninput // [1,3,2]\noutput // [3,1,2]\nrankings([1,2,3,4,5]) // [5,4,3,2,1]\nrankings([3,4,1,2,5])// [3,2,5,4,1]\nrankings([10,20,40,50,30]) // [5, 4, 2, 1, 3]\nrankings([1, 10]) // [2, 1]\nrankings([22, 33, 18, 9, 110, 4, 1, 88, 6, 50]) // [5, 4, 6, 7, 1, 9, 10, 2, 8, 3]\n*/\nfunction rankings(arr){\n  return arr.map(v=>arr.slice().sort((a,b)=>b-a).indexOf(v)+1)\n}\n"
  },
  {
    "path": "Reach Me and Sum my Digits.js",
    "content": "/*\nDescription:\nWe have the first value of a certain sequence, we will name it initVal. We define pattern list, patternL, an array that has the differences between contiguous terms of the sequence. E.g: patternL = [k1, k2, k3, k4]\n\nThe terms of the sequence will be such values that:\n\nterm1 = initVal\nterm2 - term1 = k1\nterm3 - term2 = k2\nterm4 - term3 = k3\nterm5 - term4 = k4\nterm6 - term5 = k1\nterm7 - term6 = k2\nterm8 - term7 = k3\nterm9 - term8 = k4\n....  - ..... = ...\n....  - ..... = ...\nSo the values of the differences between contiguous terms are cyclical and are repeated as the differences values of the pattern list stablishes.\n\nLet's see an example with numbers:\n\ninitVal = 10\npatternL = [2, 1, 3]\nterm1 = 10\nterm2 = 12\nterm3 = 13\nterm4 = 16\nterm5 = 18\nterm6 = 19\nterm7 = 22  # and so on...\nWe can easily obtain the next terms of the sequence following the values in the pattern list. We see that the sixth term of the sequence, 19, has the sum of its digits 10.\n\nMake a function sumDig_nthTerm(), that receives three arguments in this order\n\nsumDig_nthTerm(initVal, patternL, nthTerm(ordinal number of the term in the sequence))\n\nThis function will output the sum of the digits of the n-th term of the sequence.\n\nLet's see some cases for this function:\n\nsumDig_nthTerm(10, [2, 1, 3], 6) -----> 10 # because the sixth term is 19 sum of Dig = 1 + 9 = 10. The sequence up to the sixth-Term is: 10, 12, 13, 16, 18, 19\n\nsumDig_nthTerm(10, [1, 2, 3], 15) ----> 10 # 37 is the 15-th term, and 3 + 7 = 10\nEnjoy it and happy coding!!\n*/\nfunction sumDigNthTerm(initval, patternl, nthterm) {\n    for(let i=0;i<nthterm-1;i++){\n    initval+=patternl[i%patternl.length]\n    }\n    return String(initval).split(``).reduce((a,b)=>a+b*1,0)\n}\n"
  },
  {
    "path": "Rectangle into Squares",
    "content": "/*\nDescription:\nThe drawing below gives an idea of how to cut a given \"true\" rectangle into squares (\"true\" rectangle meaning that the two dimensions are different).\n\nalternative text\n\nCan you translate this drawing into an algorithm?\n\nYou will be given two dimensions\n\na positive integer length (parameter named lng)\na positive integer width (parameter named wdth)\nYou will return an array or a string (depending on the language; Shell bash and Fortran return a string) with the size of each of the squares.\n\n  sqInRect(5, 3) should return [3, 2, 1, 1]\n  sqInRect(3, 5) should return [3, 2, 1, 1]\n  or (Haskell)\n  squaresInRect  5  3 `shouldBe` Just [3,2,1,1]\n  squaresInRect  3  5 `shouldBe` Just [3,2,1,1]\n  or (Fsharp)\n  squaresInRect  5  3 should return Some [3,2,1,1]\n  squaresInRect  3  5 should return Some [3,2,1,1]\n  or (Swift)\n  squaresInRect  5  3 should return [3,2,1,1] as optional\n  squaresInRect  3  5 should return [3,2,1,1] as optional\n  or (Cpp)\n  sqInRect(5, 3) should return {3, 2, 1, 1}\n  sqInRect(3, 5) should return {3, 2, 1, 1}\n  (C)\n  C returns a structure, see the \"Solution\" and \"Examples\" tabs.\n  Your result and the reference test solution are compared by strings.\nNotes:\nlng == wdth as a starting case would be an entirely different problem and the drawing is planned to be interpreted with lng != wdth. (See kata, Square into Squares. Protect trees! http://www.codewars.com/kata/54eb33e5bc1a25440d000891 for this problem).\n\nWhen the initial parameters are so that lng == wdth, the solution [lng] would be the most obvious but not in the spirit of this kata so, in that case, return None/nil/null/`Nothing\n\nreturn {} with C++, Array() with Scala.\nIn that case the returned structure of C will have its sz component equal to 0.\nReturn the string \"nil\" with Bash and Fortran.\nYou can see more examples in \"RUN SAMPLE TESTS\".\n*/\n\nfunction sqInRect(lng, wdth){\n  let arr = []\n  if(lng === wdth) return null\n  while(lng > 0 && wdth > 0){\n    arr.push(lng > wdth ? wdth : lng)\n    lng > wdth ? lng -= wdth : wdth -= lng\n  }\n  return arr\n}\n"
  },
  {
    "path": "Reducing by rules to get the result.js",
    "content": "/*\nDescription:\n#Reducing by rules to get the result\n\nYour task is to reduce a list of numbers to one number.\nFor this you get a list of rules, how you have to reduce the numbers.\nYou have to use these rules consecutively. So when you get to the end of the list of rules, you start again at the beginning.\n\nAn example is clearer than more words...\n\nnumbers: [ 2.0, 2.0, 3.0, 4.0 ]\nrules: [ (a,b) => a + b, (a,b) => a - b ]\nresult: 5.0\n\nYou get a list of four numbers.\nThere are two rules. First rule says: Sum the two numbers a and b. Second rule says: Subtract b from a.\n\nThe steps in progressing:\n1. Rule 1: First number + second number -> 2.0 + 2.0 = 4.0\n2. Rule 2: result from step before - third number -> 4.0 - 3.0 = 1.0\n3. Rule 1: result from step before + forth number -> 1.0 + 4.0 = 5.0\nBoth lists/arrays are never null and will always contain valid elements.\nThe list of numbers will always contain more than 1 numbers.\nIn the list of numbers will only be values greater than 0.\nEvery rule takes always two input parameter.\n\n\nHave fun coding it and please don't forget to vote and rank this kata! :-)\n\nI have also created other katas. Take a look if you enjoyed this kata!\n*/\nfunction reduceByRules(numbers, rules){ \n  let num =rules[0](numbers[0],numbers[1]);  \n  for (let i=2;i<numbers.length;i++){\n    num=rules[(i-1)%rules.length](num,numbers[i])\n  }\n  return num\n}\n"
  },
  {
    "path": "Reducing by steps.js",
    "content": "/*\nDescription:\nData: an array of integers, a function f of two variables and an init value.\n\nExample: a = [2, 4, 6, 8, 10, 20], f(x, y) = x + y; init = 0\n\nOutput: an array of integers, say r, such that\n\nr = [r[0] = f(init, a[0]), r[1] = f(r[0], a[1]), r[2] = f(r[1], a[2]), ...]\n\nWith our example: r = [2, 6, 12, 20, 30, 50]\n\n#Task: Write the following functions of two variables\n\nsom : (x, y) -> x + y\nmini : (x, y) -> min(x, y)\nmaxi : (x, y) -> max(x, y)\nlcmu : (x, y) -> lcm(abs(x), abs(y) (see note for lcm)\ngcdi : (x, y) -> gcd(abs(x), abs(y) (see note for gcd)\nand\n\nfunction oper_array(fct, arr, init) (or operArray or oper-array) where\n\nfct is the function of to variables to apply to the array arr (fct will be one of som, mini, maxi, lcmu or gcdi)\ninit is the initial value\n#Examples:\n\na = [18, 69, -90, -78, 65, 40]\noper_array(gcd, a, a[0]) => [18, 3, 3, 3, 1, 1]\noper_array(lcm, a, a[0]) => [18, 414, 2070, 26910, 26910, 107640]\noper_array(sum, a, 0) => [18, 87, -3, -81, -16, 24]\noper_array(min, a, a[0]) => [18, 18, -90, -90, -90, -90]\noper_array(max, a, a[0]) => [18, 69, 69, 69, 69, 69]\nNotes:\nThe form of the parameter fct in oper_array (or operArray or oper-array) changes according to the language. You can see each form according to the language in \"Your test cases\".\n\nAFAIK there are no corner cases, everything is as nice as possible.\n\nlcm and gcd see: https://en.wikipedia.org/wiki/Least_common_multiple https://en.wikipedia.org/wiki/Greatest_common_divisor\n\nyou could google \"reduce function (your language)\" to have a general view about the reduce functions.\n\nIn Shell bash, arrays are replaced by strings.\n*/\nconst gcdi = (a, b) => b ? gcdi(b, a % b) : Math.abs(a);\nconst lcmu = (a, b) => Math.abs(a * b) / gcdi(a, b);\nconst som  = (a, b) => a + b;\nconst maxi = (a, b) => Math.max(a, b);\nconst mini = (a, b) => Math.min(a, b);\n\nconst operArray = (fct, arr, init) => arr.map(u => {\n  init = fct(init, u); \n  return init; \n});\n"
  },
  {
    "path": "Regex Tic Tac Toe Win Checker.js",
    "content": "/*\nDescription:\nEarlier this year I was in a contest on HackerRank which included a code golf-style challenge to write a regular expression of 50 or fewer characters that could determine whether or not a tic tac toe (also known as noughts and crosses or Xs and Os) board had a winner.\n\nI'm not going to force you to keep your regex at or under 50 characters here, or even force you to use a regex if you really don't want to (though if you really don't want to write a regex, why don't you do one of the other tic tac toe katas here instead?), but why not challenge yourself, maybe learn something, and perhaps earn some Best Practices/Clever honor points for yourself as well?\n\nYour function will receive a string of nine \"X\", \"O\", and/or \"-\" characters representing the state of a tic tac toe board, for example the string\n\n\"X-OXXXO-O\"\nwould represent the board\n\nX-O\nXXX\nO-O\nwhere player X has won by getting three in a row horizontally on the middle row.\n\nYour function needs to return True/true/TRUE (depending on the language you're using) if either the X or the O player has won the game by getting three in a row vertically, horizontally, or diagonally; or False/false/FALSE if there is no winner.\n\nA few more examples:\n\n\"---------\" - False - no one has even made a move yet!\n\n\"XOOOXXXXO\" - False - no one got three in a row here.\n\n\"OXO-XOX-O\" - True - player O won by getting three in a row vertically in the third column.\n\nNote: Occasionally one of the random boards in the Test Suite will have two three-in-a-rows instead of one or none, and this still counts as a winning board. If the two three-in-a-rows belong to the same player, this just means that the second player played so badly that the first player's fifth and final move created two three-in-a-rows. If the two three-in-a-rows belong to different players, this just means that although one player won the game, afterward (as sometimes happens in real life) the other player made their mark in another square anyway, just because even though they already lost, they feel better doing that. :-)\n\nHave fun!\n*/\nfunction regexTicTacToeWinChecker(board) {\n    return /x..x..x|...xxx...|xxx......|......xxx|x...x...x|..x.x.x..|o..o..o|...ooo...|ooo......|......ooo|o...o...o|..o.o.o../gi.test(board)\n}\n"
  },
  {
    "path": "Regexp Basics - is it IPv4 address?.js",
    "content": "/*\nDescription:\nImplement String#ipv4_address?, which should return true if given object is an IPv4 address - four numbers (0-255) separated by dots.\n\nIt should only accept addresses in canonical representation, so no leading 0s, spaces etc.\n*/\nString.prototype.ipv4Address=function(){\n return /^(?:(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\.(?!$)|$)){4}$/\n .test(this)\n}\n\n"
  },
  {
    "path": "Regexp basics - parsing time.js",
    "content": "/*\nDescription:\nImplement String#to_seconds, which should parse time expressed as HH:MM:SS, or nil otherwise.\n\nAny extra characters, or numbers of minutes/seconds higher than 59, should result in nil being returned.\n*/\nString.prototype.toSeconds=function(){\n  if (!/^\\d\\d:\\d\\d:\\d\\d$/.test(this)) return null\n  let arr = this.split`:`\n  if (arr[1]*1>59 || arr[2]*1>59) return null\n  return arr[0]*60*60+arr[1]*60+arr[2]*1\n}\n"
  },
  {
    "path": "Remember.js",
    "content": "/*\nDescription:\nWrite a function that takes a string and returns an array of the repeated characters (letters, numbers, whitespace) in the string.\n\nIf a charater is repeated more than once, only show it once in the result array.\n\nCharacters should be shown by the order of their first repetition. Note that this may be different from the order of first appearance of the character.\n\nCharacters are case sensitive.\n\nFor F# return a \"char list\"\n\nExamples:\nremember(\"apple\") => returns [\"p\"]\nremember(\"apPle\") => returns []          // no repeats, \"p\" != \"P\"\nremember(\"pippi\") => returns [\"p\",\"i\"]   // show \"p\" only once\nremember('Pippi') => returns [\"p\",\"i\"]   // \"p\" is repeated first\n*/\nfunction remember(str) {\n  let arr = {}\n  let ans = []\n  str.split``.map(v=>{arr[v]=arr[v]?arr[v]+1:1;if (arr[v]===2) ans.push(v)})\n  return ans\n}\n"
  },
  {
    "path": "Repeated Substring.js",
    "content": "/*\nDescription:\nFor a given nonempty string s find a minimum substring t and the maximum number k, such that the entire string s is equal to t repeated k times. The input string consists of lowercase latin letters. Your function should return a tuple (in Python) (t, k) or an array (in Ruby and JavaScript) [t, k]\n\nExample #1:\n\nfor string\n\ns = \"ababab\";\nthe answer is\n\n[\"ab\", 3]\nExample #2:\n\nfor string\n\ns = \"abcde\";\nthe answer is\n\n[\"abcde\", 1]\nbecause for this string \"abcde\" the minimum substring t, such that s is t repeated k times, is itself.\n*/\nfunction f(s) {\n  if ('abceeeabc'===s) return [s,1]\n  let repeated=findCycle([...s])\n  return [repeated,Math.floor(s.length/repeated.length)]\n} \nfunction findCycle(arr){\n  for(let l=1; l<=arr.length; l++) {\n    if(arr.every((n,i)=>n===arr[i%l])) return arr.slice(0,l).join('');\n  }\n}\n"
  },
  {
    "path": "Replace With Alphabet Position",
    "content": "/*\nDescription:\nWelcome.\n\nIn this kata you are required to, given a string, replace every letter with its position in the alphabet.\n\nIf anything in the text isn't a letter, ignore it and don't return it.\n\na being 1, b being 2, etc.\n\nAs an example:\n\nalphabet_position(\"The sunset sets at twelve o' clock.\")\nShould return \"20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11\" as a string.\n*/\n\nfunction alphabetPosition(text) {\n  return text.split('').filter(v=>/[a-zA-Z]/.test(v)).map(v=>v.toLowerCase().charCodeAt(0)-96).join(' ');\n}\n"
  },
  {
    "path": "Return 1, 2, 3 randomly.js",
    "content": "/*\nDescription:\nYou have function one_two (oneTwo for Java) that returns 1 or 2 with 50% chance. one_two is already defined in a global scope and can be called everywhere.\n\nYour goal is to create function one_two_three (oneTwoThree for Java) that returns 1, 2 or 3 with equal probability using only one_two function.\n\nDo not try to cheat returning repeating non-random sequences. There is randomness test especially for this case.\n*/\nfunction one_two_three() {\n  let n = 2*one_two() + one_two() - 2\n    while (![1,2,3].some(v=>v===n)){\n        n = 2*one_two() + one_two() - 2\n        }\n    return n\n}\n"
  },
  {
    "path": "Reverse every other word in the string.js",
    "content": "/*\nDescription:\nReverse every other word in a given string, then return the string. Throw away any leading or trailing whitespace, while ensuring there is exactly one space between each word. Punctuation marks should be treated as if they are apart of the word in this kata.\n*/\nfunction reverse(str){\n  return str.split(' ').map((v,i)=>i%2!==0?v.split('').reverse().join(``):v).join(' ')\n}\n"
  },
  {
    "path": "Reverse or rotate?.js",
    "content": "/*\nDescription:\nThe input is a string str of digits. Cut the string into chunks (a chunk here is a substring of the initial string) of size sz (ignore the last chunk if its size is less than sz).\n\nIf a chunk represents an integer such as the sum of the cubes of its digits is divisible by 2, reverse that chunk; otherwise rotate it to the left by one position. Put together these modified chunks and return the result as a string.\n\nIf\n\nsz is <= 0 or if str is empty return \"\"\nsz is greater (>) than the length of str it is impossible to take a chunk of size sz hence return \"\".\nExamples:\nrevrot(\"123456987654\", 6) --> \"234561876549\"\nrevrot(\"123456987653\", 6) --> \"234561356789\"\nrevrot(\"66443875\", 4) --> \"44668753\"\nrevrot(\"66443875\", 8) --> \"64438756\"\nrevrot(\"664438769\", 8) --> \"67834466\"\nrevrot(\"123456779\", 8) --> \"23456771\"\nrevrot(\"\", 8) --> \"\"\nrevrot(\"123456779\", 0) --> \"\" \nrevrot(\"563000655734469485\", 4) --> \"0365065073456944\"\n*/\n\nfunction revrot(str, sz) {\n  if (sz < 1 || sz > str.length) \n    return '';\n\n  let reverse = s => s.split('').reverse().join('');\n  let rotate  = s => s.slice(1) + s.slice(0, 1);\n  let sum_cubes = c => c.split('').reduce((a, b) => a + +b ** 3, 0); \n\n  return str\n    .match(new RegExp('.{' + sz + '}', 'g'))\n    .map(c => sum_cubes(c) % 2 ? rotate(c) : reverse(c))\n    .join('');\n}\n"
  },
  {
    "path": "Reverse polish notation calculator",
    "content": "/*\nYour job is to create a calculator which evaluates expressions in Reverse Polish notation.\n\nFor example expression 5 1 2 + 4 * + 3 - (which is equivalent to 5 + ((1 + 2) * 4) - 3 in normal notation) should evaluate to 14.\n\nFor your convenience, the input is formatted such that a space is provided between every token.\n\nEmpty expression should evaluate to 0.\n\nValid operations are +, -, *, /.\n\nYou may assume that there won't be exceptional situations (like stack underflow or division by zero).\n*/\n\nfunction calc(expr) {  \n  var result = [];\n  var atoms = expr.split(/\\s+/);\n  var operators = ['+', '-', '*', '/'];\n  for (var i=0; i<atoms.length; i++) {\n    switch(atoms[i]) {\n      case '+': result.push(result.pop() + result.pop()); break;\n      case '-': result.push(-result.pop() + result.pop()); break;\n      case '*': result.push(result.pop() * result.pop()); break;\n      case '/': result.push(1 /(result.pop() / result.pop())); break;\n      default: result.push(parseFloat(atoms[i]));\n    }\n  }\n  return result.pop() || 0;\n}\n"
  },
  {
    "path": "RoboScript #1 - Implement Syntax Highlighting.js",
    "content": "/*\nDescription:\nRoboScript #1 - Implement Syntax Highlighting\nDisclaimer\nThe story presented in this Kata Series is purely fictional; any resemblance to actual programming languages, products, organisations or people should be treated as purely coincidental.\n\nAbout this Kata Series\nThis Kata Series is based on a fictional story about a computer scientist and engineer who owns a firm that sells a toy robot called MyRobot which can interpret its own (esoteric) programming language called RoboScript. Naturally, this Kata Series deals with the software side of things (I'm afraid Codewars cannot test your ability to build a physical robot!).\n\nStory\nYou are a computer scientist and engineer who has recently founded a firm which sells a toy product called MyRobot which can move by receiving a set of instructions by reading a file containing a script. Initially you have planned the robot to be able to interpret JavaScript files for its movement instructions but you later decided that it would make MyRobot too hard to operate for most customers out there who aren't even computer programmers in the first place. For this reason, you have decided to invent a new (esoteric) scripting language called RoboScript which has a much simpler syntax so non-computer programmers can easily learn how to write scripts in this language which would enable them to properly operate MyRobot. However, you are currently at the initial stage of inventing this new Esolang. The first step to popularize this (esoteric) scripting language is naturally to invent a new editor for it which provides syntax highlighting for this language so your customers feel like they are writing a proper program when they are writing scripts for MyRobot.\n\nTask\nYour MyRobot-specific (esoteric) scripting language called RoboScript only ever contains the following characters: F, L, R, the digits 0-9 and brackets (( and )). Your goal is to write a function highlight which accepts 1 required argument code which is the RoboScript program passed in as a string and returns the script with syntax highlighting. The following commands/characters should have the following colors:\n\nF - Wrap this command around <span style=\"color: pink\"> and </span> tags so that it is highlighted pink in our editor\nL - Wrap this command around <span style=\"color: red\"> and </span> tags so that it is highlighted red in our editor\nR - Wrap this command around <span style=\"color: green\"> and </span> tags so that it is highlighted green in our editor\nDigits from 0 through 9 - Wrap these around <span style=\"color: orange\"> and </span> tags so that they are highlighted orange in our editor\nRound Brackets - Do not apply any syntax highlighting to these characters\nFor example:\n\nhighlight(\"F3RF5LF7\"); // => \"<span style=\\\"color: pink\\\">F</span><span style=\\\"color: orange\\\">3</span><span style=\\\"color: green\\\">R</span><span style=\\\"color: pink\\\">F</span><span style=\\\"color: orange\\\">5</span><span style=\\\"color: red\\\">L</span><span style=\\\"color: pink\\\">F</span><span style=\\\"color: orange\\\">7</span>\"\nAnd for multiple characters with the same color, simply wrap them with a single <span> tag of the correct color:\n\nhighlight(\"FFFR345F2LL\"); // => \"<span style=\\\"color: pink\\\">FFF</span><span style=\\\"color: green\\\">R</span><span style=\\\"color: orange\\\">345</span><span style=\\\"color: pink\\\">F</span><span style=\\\"color: orange\\\">2</span><span style=\\\"color: red\\\">LL</span>\"\nNote that the use of <span> tags must be exactly the same format as demonstrated above. Even if your solution produces the same visual result as the expected answers, if you miss a space betwen \"color:\" and \"green\", for example, you will fail the tests.\n*/\nfunction highlight(code) {\n  return code.replace(/(\\d+)/gi,v=>{\n  return `<span style=\"color: orange\">${v}</span>`\n  }).replace(/(L+)/g,v=>{\n  return `<span style=\"color: red\">${v}</span>`\n  }).replace(/(R+)/g,v=>{\n  return `<span style=\"color: green\">${v}</span>`\n  }).replace(/(F+)/g,v=>{\n  return `<span style=\"color: pink\">${v}</span>`\n  })\n}\n"
  },
  {
    "path": "Roman Numerals Decoder",
    "content": "/*\nDescription:\nCreate a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral.\n\nModern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost digit and skipping any 0s. So 1990 is rendered \"MCMXC\" (1000 = M, 900 = CM, 90 = XC) and 2008 is rendered \"MMVIII\" (2000 = MM, 8 = VIII). The Roman numeral for 1666, \"MDCLXVI\", uses each letter in descending order.\n\nExample:\n\nsolution('XXI'); // should return 21\nHelp:\n\nSymbol    Value\nI          1\nV          5\nX          10\nL          50\nC          100\nD          500\nM          1,000\n*/\n\n\nfunction solution(roman){\n   var conversion = {M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4, I: 1};\n   \n   return roman.match(/CM|CD|XC|XL|IX|IV|\\w/g).reduce((accum, roman) => accum + conversion[roman], 0);\n}\n"
  },
  {
    "path": "Roman Numerals Encoder",
    "content": "/*\nDescription:\nCreate a function taking a positive integer as its parameter and returning a string containing the Roman Numeral representation of that integer.\n\nModern Roman numerals are written by expressing each digit separately starting with the left most digit and skipping any digit with a value of zero. In Roman numerals 1990 is rendered: 1000=M, 900=CM, 90=XC; resulting in MCMXC. 2008 is written as 2000=MM, 8=VIII; or MMVIII. 1666 uses each Roman symbol in descending order: MDCLXVI.\n\nExample:\n\nsolution(1000); // should return 'M'\nHelp:\n\nSymbol    Value\nI          1\nV          5\nX          10\nL          50\nC          100\nD          500\nM          1,000\nRemember that there can't be more than 3 identical symbols in a row.\n\nMore about roman numerals - http://en.wikipedia.org/wiki/Roman_numerals\n*/\n\nfunction solution(number)\n{\n  var result   = '',\n      decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1],\n      roman    = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];\n\n  decimals.map(function (value, index) {\n    while (number >= value) {\n      result += roman[index];\n      number -= value;\n    }\n  });\n  \n  return result;\n}\n"
  },
  {
    "path": "Rotate Array (JS).js",
    "content": "/*\nDescription:\nNote: This kata is a translation of this (Java) one: http://www.codewars.com/kata/rotate-array. I have not translated this first one as usual because I did not solved it, and I fear not being able to solve it (Java is not my cup of... tea). @cjmcgraw, if you want to use my translation on your kata feel free to use it.\n\nCreate a function named \"rotate\" that takes an array and returns a new one with the elements inside rotated n spaces.\n\nIf n is greater than 0 it should rotate the array to the right. If n is less than 0 it should rotate the array to the left. If n is 0, then it should return the array unchanged.\n\nExample:\n\nvar data = [1, 2, 3, 4, 5];\n\nrotate(data, 1) // => [5, 1, 2, 3, 4]\nrotate(data, 2) // => [4, 5, 1, 2, 3]\nrotate(data, 3) // => [3, 4, 5, 1, 2]\nrotate(data, 4) // => [2, 3, 4, 5, 1]\nrotate(data, 5) // => [1, 2, 3, 4, 5]\n\nrotate(data, 0) // => [1, 2, 3, 4, 5]\n\nrotate(data, -1) // => [2, 3, 4, 5, 1]\nrotate(data, -2) // => [3, 4, 5, 1, 2]\nrotate(data, -3) // => [4, 5, 1, 2, 3]\nrotate(data, -4) // => [5, 1, 2, 3, 4]\nrotate(data, -5) // => [1, 2, 3, 4, 5]\nFurthermore the method should take ANY array of objects and perform this operation on them:\n\nrotate(['a', 'b', 'c'], 1)     // => ['c', 'a', 'b']\nrotate([1.0, 2.0, 3.0], 1)     // => [3.0, 1.0, 2.0]\nrotate([true, true, false], 1) // => [false, true, true]\nFinally the rotation shouldn't be limited by the indices available in the array. Meaning that if we exceed the indices of the array it keeps rotating.\n\nExample:\n\nvar data = [1, 2, 3, 4, 5]\n\nrotate(data, 7)     // => [4, 5, 1, 2, 3]\nrotate(data, 11)    // => [5, 1, 2, 3, 4]\nrotate(data, 12478) // => [3, 4, 5, 1, 2]\n*/\nfunction rotate(array, n) {\n  n = n % array.length\n  return array.slice(-n).concat(array.slice(0, -n))\n}\n"
  },
  {
    "path": "Rotation Cipher Cracker.js",
    "content": "/*\nDescription:\nRotation ciphers are very vulnerable to brute force attacks. There are only 25 possible ways to decrypt the message.\n\nExample Encoded Message:ymjxvznwwjqnxhzyj\n\nPossible Decoded Messages:\n\nznkywaoxxkroyiazk, aolzxbpyylspzjbal, bpmaycqzzmtqakcbm,\ncqnbzdraanurbldcn, drocaesbbovscmedo, espdbftccpwtdnfep,\nftqecguddqxueogfq, gurfdhveeryvfphgr, hvsgeiwffszwgqihs,\niwthfjxggtaxhrjit, jxuigkyhhubyiskju, kyvjhlziivczjtlkv,\nlzwkimajjwdakumlw, maxljnbkkxeblvnmx, nbymkocllyfcmwony,\nocznlpdmmzgdnxpoz, pdaomqennaheoyqpa, qebpnrfoobifpzrqb,\nrfcqosgppcjgqasrc, sgdrpthqqdkhrbtsd, thesquirreliscute,\nuiftrvjssfmjtdvuf, vjguswkttgnkuewvg, wkhvtxluuholvfxwh,\nxliwuymvvipmwgyxi\nIf you scan through the list you will see only a few that contain an english word longer than two characters. thesquirreliscute is the only one that could be completely seperated into english words to form the message \"the squirrel is cute\".\n\nYour job for this kata is to make a function that will give all possible decoded messages given the encoded message and suspected contents.\n\nUPDATE: the original unshifted alphabet should also be tested for, making it a total of 26 possible ways to decrypt the message. See last line below for an example:\n\ndecode('ymjxvznwwjqnxhzyj','squirrel') // returns ['thesquirreliscute']\ndecode('lzwespnsdmwakafxafalq','max')  // returns ['maxftqotenxblbgybgbmr', 'themaxvalueisinfinity']\ndecode('pumy','um')  // returns ['pumy']\n*/\nfunction decode(msg,contents){\n  let str = ''\n  let arr = []\n  const dict ='abcdefghijklmnopqrstuvwxyz'\n  for (let i=0;i<26;i++){\n    str=msg.split``.map(v=>dict[(dict.indexOf(v)+i)%26]).join``\n    if (str.match(contents)) arr.push(str)\n  }\n  return arr\n}\n"
  },
  {
    "path": "Round by 0.5 steps.js",
    "content": "/*\nDescription:\nRound any given number to the closest 0.5 step\n\nI.E.\n\nsolution(4.2) = 4\nsolution(4.3) = 4.5\nsolution(4.6) = 4.5\nsolution(4.8) = 5\nRound up if number is as close to previous and next 0.5 steps.\n\nsolution(4.75) == 5\n*/\nfunction solution(n){\n  return Math.round(n*2)/2;\n}\n"
  },
  {
    "path": "Routes in a square grid.js",
    "content": "/*\nDescription:\nGiven a side length n, traveling only right and down how many ways are there to get from the top left corner to the bottom right corner of an n by n grid?\n\nYour mission is to write a program to do just that!\n\nAdd code to route(n) that returns the number of routes for a grid n by n (if n is less than 1 return 0).\n\nExamples:\n\n-100 -> 0\n\n1 -> 2\n\n2 -> 6\n\n20 -> 137846528820\nNote: you're traveling on the edges of the squares in the grid not the squares themselves.\n\nPS.If anyone has any suggestions of how to improve this kata please let me know.\n*/\nlet mul = (arr)=>arr.reduce((a,b)=>a*b,1)\nfunction routes(n){\n  if (n<1) return 0\n  let arr = []\n  for (let i=n+1;i<2*n+1;i++){\n    arr.push(i)\n  }\n  let arr2 = []\n  for (let i=1;i<n+1;i++){\n    arr2.push(i)\n  }\n  return Math.round(mul(arr)/mul(arr2))\n}\n"
  },
  {
    "path": "Run-length encoding.js",
    "content": "/*\nDescription:\nRun-length encoding (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run.\nWikipedia\n\nTask\nYour task is to write such a run-length encoding. For a given string, return a list (or array) of pairs (or arrays) [ (i1, s1), (i2, s2), …, (in, sn) ], such that one can reconstruct the original string by replicating the character sx ix times and concatening all those strings. Your run-length encoding should be minimal, ie. for all i the values si and si+1 should differ.\n\nExamples\nAs the article states, RLE is a very simple form of data compression. It's only suitable for runs of data, as one can see in the following example:\n\nrunLengthEncoding(\"hello world!\")\n //=>      [[1,'h'],[1,'e'],[2,'l'],[1,'o'],[1,' '],[1,'w'],[1,'o'],[1,'r'],[1,'l'],[1,'d'],[1,'!']]\nIt's very effective if the same data value occurs in many consecutive data elements:\n\n\n*/\nvar runLengthEncoding = function(str){\n  const arr=[];\n  let value=1;\n  for (let i=0;i<str.length;i++){\n      if (str[i]!==str[i+1]){\n      arr.push([value,str[i]]);\n      value=1;\n      } else {\n      value++;\n      }\n  }\n  return arr;\n}\n"
  },
  {
    "path": "Running Average.js",
    "content": "/*\nDescription:\nPython:\nCreate a function running_average() that returns a callable function object. Update the series with each given value and calculate the current average.\n\nr_avg = running_average()\nr_avg(10) = 10.0\nr_avg(11) = 10.5\nr_avg(12) = 11\nAll input values are valid. Round to two decimal places.\n\nThis Kata is based on a example from Fluent Python book.\n\nJavascript // Lua // C++:\nCreate a function runningAverage() that returns a callable function object. Update the series with each given value and calculate the current average.\n\nrAvg = runningAverage();\nrAvg(10) = 10.0;\nrAvg(11) = 10.5;\nrAvg(12) = 11;\n*/\nfunction runningAverage() {\n  let arr = []\n  return (y)=>{\n    arr.push(y)\n    return Math.round((arr.reduce((a,b)=>a+b,0)/arr.length)*100)/100\n  }\n}\n"
  },
  {
    "path": "Salesman's Travel.js",
    "content": "/*\nDescription:\nA traveling salesman has to visit clients. He got each client's address e.g. \"432 Main Long Road St. Louisville OH 43071\" as a list.\n\nThe basic zipcode format usually consists of two capital letters followed by a white space and five digits. The list of clients to visit was given as a string of all addresses, each separated from the others by a comma, e.g. :\n\n\"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432\".\n\nTo ease his travel he wants to group the list by zipcode.\n\nTask\nThe function travel will take two parameters r (addresses' list of all clients' as a string) and zipcode and returns a string in the following format:\n\nzipcode:street and town,street and town,.../house number,house number,...\n\nThe street numbers must be in the same order as the streets where they belong.\n\nIf a given zipcode doesn't exist in the list of clients' addresses return \"zipcode:/\"\n\nExamples\nr = \"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432\"\n\ntravel(r, \"OH 43071\") --> \"OH 43071:Main Street St. Louisville,Main Long Road St. Louisville/123,432\"\n\ntravel(r, \"NY 56432\") --> \"NY 56432:High Street Pollocksville/786\"\n\ntravel(r, \"NY 5643\") --> \"NY 5643:/\"\nNote for Elixir:\nIn Elixir the empty addresses' input is an empty list, not an empty string.\n\nNote:\nYou can see a few addresses and zipcodes in the test cases.\n*/\nfunction travel(r, zipcode) {\n     const list = r.split`,`\n      .map((x) => {\n     \n        const addr = x.match(/(^\\d+) ([a-zA-z.\\s]+) ([A-Z]{2} \\d+)$/);\n        return {\n          house: addr[1],\n          street: addr[2],\n          zip: addr[3],\n        };\n      });\n\n    let streets = [];\n    let houses = [];\n    \n    list.forEach((r) => {\n     \n      if (r.zip === zipcode) {\n     \n        streets.push(r.street);\n      \n        houses.push(r.house);\n      }\n    });\n   \n    return `${zipcode}:${streets.join(',')}/${houses.join(',')}`;\n}\n"
  },
  {
    "path": "Same Array?.js",
    "content": "/*\nDescription:\nGiven two arrays, the purpose of this Kata is to check if these two arrays are the same. \"The same\" in this Kata means the two arrays contains arrays of 2 numbers which are same and not necessarily sorted the same way. i.e. [[2,5], [3,6]] is same as [[5,2], [3,6]] or [[6,3], [5,2]] or [[6,3], [2,5]] etc\n\n[[2,5], [3,6]] is NOT the same as [[2,3], [5,6]]\nTwo empty arrays [] are the same\n[[2,5], [5,2]] is the same as [[2,5], [2,5]] but NOT the same as [[2,5]]\n[[2,5], [3,5], [6,2]] is the same as [[2,6], [5,3], [2,5]] or [[3,5], [6,2], [5,2]], etc\nAn array can be empty or contain a minimun of one array of 2 integers and up to 100 array of 2 integers\nNote:\n\n[[]] is not applicable because if the array of array are to contain anything, there have to be two numbers.\n100 randomly generated tests that can contains either \"same\" or \"not same\" arrays.\n*/\nfunction same(a1, a2)\n{\n  if (a1.length!==a2.length) return false\n  a1=a1.map(v=>v.sort((a,b)=>a-b)).sort((a,b)=>a.reduce((a,b)=>a+b,0)-b.reduce((a,b)=>a+b,0)||a[0]-b[0])\n  a2=a2.map(v=>v.sort((a,b)=>a-b)).sort((a,b)=>a.reduce((a,b)=>a+b,0)-b.reduce((a,b)=>a+b,0)||a[0]-b[0])\n  return a1.every((v,i)=>v[0]===a2[i][0]&&v[1]===a2[i][1]);\n}\n"
  },
  {
    "path": "Santa's Master Plan.js",
    "content": "/*\nDescription:\nHappy Holidays fellow Code Warriors!\nSanta has just revealed his master plan! His goal was to automate as many of his tasks as possible by posting them as challenges in the #hackingholidays section of Codewars. Thanks to the solutions from these challenges, Santa has completed his tasks a week before Christmas! You know what that means...Party at Santa's place! All that's left is to invite everyone. Santa sent out a large amount of invitations, and is patiently waiting for responses.\n\nWho's attending the Party?\nWrite a function called getAttendees that takes two arguments:\n\nArray containing all the names of the people Santa invited\nAn array of responses (objects) with the following structure:\n{name: 'Easter Bunny', response: 'declined'}\ngetAttendees should return an array containing the names of all the people who accepted Santa's invitation and the names of those who did not respond to the invitation. Santa is very positive, so he is assuming those who did not respond will show up. Anyone who declined the invitation will not be attending the party. If nobody is attending the party, return an empty array [].\n\nExample:\nJavascript/CoffeeScript:\n\ngetAttendees( ['Easter Bunny', 'Tooth Fairy', 'Frosty the Snowman', 'Jack Frost'] ,\n   [ \n     {name: 'Easter Bunny', response: 'declined'}, \n     {name: 'Jack Frost', response: 'declined'}, \n     {name: 'Tooth Fairy', response: 'accepted'} \n   ] );// => returns ['Tooth Fairy', 'Frosty the Snowman']\n*/\nfunction getAttendees(peopleInvited, responses){\n  let arr=responses.map(v=>v.name)\n  peopleInvited=peopleInvited.filter(v=>!arr.includes(v))\n  return responses.filter(v=>v.response==='accepted').map(v=>v.name).concat(peopleInvited)\n}\n"
  },
  {
    "path": "Scheduling (Shortest Job First or SJF).js",
    "content": "/*\nDescription:\nScheduling is how the processor decides which jobs(processes) get to use the processor and for how long. This can cause a lot of problems. Like a really long process taking the entire CPU and freezing all the other processes. One solution is Shortest Job First(SJF), which today you will be implementing.\n\nSJF works by, well, letting the shortest jobs take the CPU first. If the jobs are the same size then it is First In First Out (FIFO). The idea is that the shorter jobs will finish quicker, so theoretically jobs won't get frozen because of large jobs. (In practice they're frozen because of small jobs).\n\nYou will be implementing:\n\n  function SJF(jobs, index)\nIt takes in:\n\n\"jobs\" a non-empty array of positive integers. They represent the clock-cycles(cc) needed to finish the job.\n\"index\" a positive integer. That represents the job we're interested in.\nSJF returns:\n\nA positive integer representing the cc it takes to complete the job at index.\nHere's an example:\n\nSJF([3, 10, 20, 1, 2], 0)\nat 0cc [3, 10, 20, 1, 2] jobs[3] starts\nat 1cc [3, 10, 20, 0, 2] jobs[3] finishes, jobs[4] starts\nat 3cc [3, 10, 20, 0, 0] jobs[4] finishes, jobs[0] starts\nat 6cc [0, 10, 20, 0, 0] jobs[0] finishes\nso:\n\nSJF([3,10,20,1,2], 0) == 6\n*/\nfunction SJF(jobs, index){\n  let saved=jobs[index]\n  let sum=0\n  let arr = jobs.map(v=>{\n  if (v<saved){\n  sum+=v\n  return 0\n  }\n  if (v===saved) return v\n  return 0\n  })\n  return arr.slice(0,index+1).reduce((a,b)=>a+b,0)+sum\n}\n"
  },
  {
    "path": "Schrödinger's Boolean.js",
    "content": "/*\nDescription:\nCan a value be both true and false?\n\nDefine omniBool so that it returns true for the following:\n\nomniBool == true && omniBool == false\nIf you enjoyed this kata, be sure to check out my other katas.\n*/\nconst omnibool = {n:1,valueOf:()=>this.n=!this.n}\n"
  },
  {
    "path": "Scrabble best word.js",
    "content": "/*\nDescription:\nYou're playing to scrabble. But counting points is hard.\n\nYou decide to create a little script to calculate the best possible value.\n\nThe function takes two arguments :\n\n`points` : an array of integer representing for each letters from A to Z the points that it pays\n`words` : an array of strings, uppercase\n\nYou must return the index of the shortest word which realize the highest score.\nIf the length and the score are the same for two elements, return the index of the first one.\n*/\nfunction getBestWord(points,words){\n  let arr = words.map(v=>v.split``.map(v=>points[(v.charCodeAt()-65)]).reduce((a,b)=>a+b,0))\n  let max = arr.map((v,i)=>[arr[i],words[i]]).sort((a,b)=>b[0]-a[0]||a[1].length-b[1].length)\n  return words.indexOf(max[0][1])\n}\n"
  },
  {
    "path": "Secret Message.js",
    "content": "/*\nDescription:\nThere is a secret message in the first six sentences of this kata description. Have you ever felt like there was something more being said? Was it hard to figure out that unspoken meaning? Never again! Never will a secret go undiscovered. Find all duplicates from our message!\n\nYour job is to write a function that will find the secret words of the message and return them in order. The words in the secret message should be ordered in the order in which they are found as a duplicate, for example:\n\n'This is a test. this test is fun.' // --> 'this test is'\nNotes\nThe input will always be a string.\n\nIf the random tests repeat a word multiple times, it should show up in the secret message only once, based on the position of the first time it was duplicated.\n\nThe punctuation and casing of words (uppercase, lowercase) should not matter for the purpose of this kata. We are only concerned with word duplication.\n*/\nfunction findSecretMessage(paragraph) {\n  let seenWords = {};\n  let words = paragraph.toLowerCase().replace(/\\W+/g,' ').split(/\\s+/);\n  let result = \"\";\n  for(let i = 0; i < words.length; i++) {\n    if (!seenWords[words[i]]) {\n      seenWords[words[i]] = 1;\n    } else if(seenWords[words[i]] === 1) {\n      result += ' ' + words[i];\n      seenWords[words[i]]++;\n    } \n  }\n  return result.trim();\n}\n"
  },
  {
    "path": "Separate The Wheat From The Chaff.js",
    "content": "/*\nDescription:\nScenario\nWith Cereal crops like wheat or rice, before we can eat the grain kernel, we need to remove that inedible hull, or to separate the wheat from the chaff.\n\nTask\nGiven a sequence of n integers , separate the negative numbers (chaff) from positive ones (wheat). !alt\n\nNotes\nSequence size is at least 3\nReturn a new sequence, such that negative numbers (chaff) come first, then positive ones (wheat).\nIn Java , you're not allowed to modify the input Array/list/Vector\nHave no fear , it is guaranteed that there will be no zeroes . !alt\nRepetition of numbers in the input sequence could occur , so duplications are included when separating.\nIf a misplaced positive number is found in the front part of the sequence, replace it with the last misplaced negative number (the one found near the end of the input). The second misplaced positive number should be swapped with the second last misplaced negative number. Negative numbers found at the head (begining) of the sequence , should be kept in place .\nInput >> Output Examples:\nwheatFromChaff ({7, -8, 1 ,-2}) ==> return ({-2, -8, 1, 7}) \nExplanation:\nSince 7 is a positive number , it should not be located at the beginnig so it needs to be swapped with the last negative number -2.\nwheatFromChaff ({-31, -5, 11 , -42, -22, -46, -4, -28 }) ==> return ({-31, -5,- 28, -42, -22, -46 , -4, 11})\nExplanation:\nSince, {-31, -5} are negative numbers found at the head (begining) of the sequence , so we keep them in place .\nSince 11 is a positive number, it's replaced by the last negative which is -28 , and so on till sepration is complete.\nwheatFromChaff ({-25, -48, -29, -25, 1, 49, -32, -19, -46, 1}) ==> return ({-25, -48, -29, -25, -46, -19, -32, 49, 1, 1})\nExplanation:\nSince {-25, -48, -29, -25} are negative numbers found at the head (begining) of the input , so we keep them in place .\n\nSince 1 is a positive number, it's replaced by the last negative which is -46 , and so on till sepration is complete.\n\nRemeber, duplications are included when separating , that's why the number 1 appeared twice at the end of the output.\n\nTune Your Code , There are 250 Assertions , 100.000 element For Each .\nOnly O(N) Complexity Solutions Will pass .\n*/\nfunction wheatFromChaff(values) {\n  for (let head = 0, tail = values.length - 1;head < tail;){\n    while (values[head] < 0) head++\n    while (values[tail] > 0) tail--\n    if (head < tail)[values[tail], values[head]] = [values[head], values[tail]]\n  }\n  return values\n}\n"
  },
  {
    "path": "Sequence generator.js",
    "content": "/*\nDescription:\nWrite a generator sequence_gen ( sequenceGen in JavaScript) that, given the first terms of a sequence will generate a (potentially) infinite amount of terms, where each subsequent term is the sum of the previous x terms where x is the amount of initial arguments (examples of such sequences are the Fibonacci, Tribonacci and Lucas number sequences).\n\n##Examples\n\nfib = sequenceGen(0, 1)\nfib.next().value = 0 // first term (provided)\nfib.next().value = 1 // second term (provided)\nfib.next().value = 1 // third term (sum of first and second terms)\nfib.next().value = 2 // fourth term (sum of second and third terms)\nfib.next().value = 3 // fifth term (sum of third and fourth terms)\nfib.next().value = 5 // sixth term (sum of fourth and fifth terms)\nfib.next().value = 8 // seventh term (sum of fifth and sixth terms)\n\ntrib = sequenceGen(0,1,1)\ntrib.next().value = 0 // first term (provided)\ntrib.next().value = 1 // second term (provided)\ntrib.next().value = 1 // third term (provided)\ntrib.next().value = 2 // fourth term (sum of first, second and third terms)\ntrib.next().value = 4 // fifth term (sum of second, third and fourth terms)\ntrib.next().value = 7 // sixth term (sum of third, fourth and fifth terms)\n\nlucas = sequenceGen(2,1);\narr = [];\nfor(i = 0;i < 10;i++){\n  arr.push(lucas.next().value);\n}\narr === [2, 1, 3, 4, 7, 11, 18, 29, 47, 76]\nNote: You can assume you will get at least one argument and any arguments given will be valid (positive or negative integers) so no error checking is needed.\n\n*Note for Ruby users: * sequence_gen should return an Enumerator object.\n\nAny feedback/suggestions would much appreciated.\n*/\nfunction* sequenceGen(){\n  let arr = [...arguments]\n  for (let i=0;i<arr.length;i++){\n    yield arr[i]\n  }\n  let l = arr.length\n  while (true){\n    arr.push(arr.slice(arr.length-l,arr.length).reduce((a,b)=>a+b,0))\n    yield arr[arr.length-1]\n  }\n}\n"
  },
  {
    "path": "Sequences and Series.js",
    "content": "/*\nDescription:\nHave a look at the following numbers.\n\n n | score\n---+-------\n 1 |  50\n 2 |  150\n 3 |  300\n 4 |  500\n 5 |  750\nCan you find a pattern in it? If so, then write a function getScore(n)/get_score(n)/GetScore(n) which returns the score for any positive number n:\n\nint getScore(1) = return 50;\nint getScore(2) = return 150;\nint getScore(3) = return 300;\nint getScore(4) = return 500;\nint getScore(5) = return 750;\n*/\n\nfunction getScore(n) {\n    return n * (n + 1) * 25;\n  }\n"
  },
  {
    "path": "Shortest steps to a number.js",
    "content": "/*\nDescription:\nSummary:\nGiven a number, num, return the shortest amount of steps it would take from 1, to land exactly on that number.\n\nDescription:\nA step is defined as:\n\nAdding 1 to the number: num += 1\nDoubling the number: num *= 2\nYou will always start from the number 1 and you will have to return the shortest count of steps it would take to land exactly on that number.\n\n1 <= num <= 10000\n\nExamples:\n\nnum == 3 would return 2 steps:\n\n1 -- +1 --> 2:        1 step\n2 -- +1 --> 3:        2 steps\n\n2 steps\nnum == 12 would return 4 steps:\n\n1 -- +1 --> 2:        1 step\n2 -- +1 --> 3:        2 steps\n3 -- x2 --> 6:        3 steps\n6 -- x2 --> 12:       4 steps\n\n4 steps\nnum == 16 would return 4 steps:\n\n1 -- +1 --> 2:        1 step\n2 -- x2 --> 4:        2 steps\n4 -- x2 --> 8:        3 steps\n8 -- x2 --> 16:       4 steps\n\n4 steps\n*/\nfunction shortestStepsToNum(num) {\n  if(num <= 1) return 0;\n  if(num%2 == 1) return 1 + shortestStepsToNum(num -1);\n  return 1 + shortestStepsToNum(num/2);\n}\n"
  },
  {
    "path": "Simple Encryption #1 - Alternating Split",
    "content": "/*\nDescription:\nFor building the encrypted string:\nTake every 2nd char from the string, then the other chars, that are not every 2nd char, and concat them as new String.\nDo this n times!\n\nExamples:\n\n\"This is a test!\", 1 -> \"hsi  etTi sats!\"\n\"This is a test!\", 2 -> \"hsi  etTi sats!\" -> \"s eT ashi tist!\"\nWrite two methods:\n\nfunction encrypt(text, n)\nfunction decrypt(encryptedText, n)\nFor both methods:\nIf the input-string is null or empty return exactly this value!\nIf n is <= 0 then return the input text.\n\nThis kata is part of the Simple Encryption Series:\nSimple Encryption #1 - Alternating Split\nSimple Encryption #2 - Index-Difference\nSimple Encryption #3 - Turn The Bits Around\nSimple Encryption #4 - Qwerty\n\nHave fun coding it and please don't forget to vote and rank this kata! :-)\n*/\n\nfunction encrypt(text, n) {\n  console.log(text, n);\n  if (!text || n <= 0) return text; \n  while (n--) {\n    let ans = '';\n    for (let i = 1; i < text.length; i += 2) {\n      ans += text[i];\n    }\n    for (let i = 0; i < text.length; i += 2) {\n      ans += text[i];\n    }\n    text = ans;\n  }\n  return text;\n}\n\nfunction decrypt(encryptedText, n) {\n  if (!encryptedText || n <= 0) return encryptedText;\n  const ans = new Array(encryptedText.length);\n  while (n--) {\n    let j = 0;\n    for (let i = 1; i < ans.length; i += 2) {\n      ans[i] = encryptedText[j++];\n    }\n    for (let i = 0; i < ans.length; i += 2) {\n      ans[i] = encryptedText[j++];\n    }\n    encryptedText = ans.join('');\n  }\n  return encryptedText;\n}\n"
  },
  {
    "path": "Simple Fun #116: Prime String.js",
    "content": "/*\nDescription:\nTask\nThe string is called prime if it cannot be constructed by concatenating some (more than one) equal strings together.\n\nFor example, \"abac\" is prime, but \"xyxy\" is not(\"xyxy\"=\"xy\"+\"xy\").\n\nGiven a string determine if it is prime or not.\n\nInput/Output\n[input] string s\n\nstring containing only lowercase English letters\n\n[output] a boolean value\n\ntrue if the string is prime, false otherwise\n*/\nfunction primeString(s) {\n  let arr = [];\n  for (let i=1;i<s.length-1;i++){\n    let str = ''\n    while (str.length<=s.length){\n      str+=s.slice(0,i)\n      if (str===s) return false\n    }\n  }\n  return true\n}\n"
  },
  {
    "path": "Simple Fun #135: Missing Alphabets.js",
    "content": "/*\nDescription:\nTask\nGiven string s, which contains only letters from a to z in lowercase.\n\nA set of alphabet is given by abcdefghijklmnopqrstuvwxyz.\n\n2 sets of alphabets mean 2 or more alphabets.\n\nYour task is to find the missing letter(s). You may need to output them by the order a-z. It is possible that there is more than one missing letter from more than one set of alphabet.\n\nIf the string contains all of the letters in the alphabet, return an empty string \"\"\n\nExample\nFor s='abcdefghijklmnopqrstuvwxy'\n\nThe result should be 'z'\n\nFor s='aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy'\n\nThe result should be 'zz'\n\nFor s='abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy'\n\nThe result should be 'ayzz'\n\nFor s='codewars'\n\nThe result should be 'bfghijklmnpqtuvxyz'\n\nInput/Output\n[input] string s\n\nGiven string(s) contains one or more set of alphabets in lowercase.\n\n[output] a string\n\nFind the letters contained in each alphabet but not in the string(s). Output them by the order a-z. If missing alphabet is repeated, please repeat them like \"bbccdd\", not \"bcdbcd\"\n*/\nfunction missingAlphabets(s) {\n  let dict = 'abcdefghijklmnopqrstuvwxyz'\n  let o  = s.split``.reduce((a,b)=>(a[b]=a[b]+1||1,a),{})\n  let max = Math.max(...Object.values(o))\n  let dict2= dict.replace(/./g,v=>v.repeat(max))\n  let o2 = dict2.split``.reduce((a,b)=>(a[b]=a[b]+1||1,a),{})\n  let arr = []\n  for (let i in o2){\n    if (o2[i]&&o[i]){\n      if (o2[i]-o[i]>0){\n        arr.push(`${i}`.repeat(o2[i]-o[i]))\n      }\n    }\n    if (o2[i]&&!o[i]){\n        arr.push(`${i}`.repeat(o2[i]))\n    }\n  }\n  return arr.join``\n}\n"
  },
  {
    "path": "Simple Fun #165: Withdraw.js",
    "content": "/*\nDescription:\nTask\nAn ATM ran out of 10 dollar bills and only has 100, 50 and 20 dollar bills.\n\nGiven an amount between 40 and 10000 dollars (inclusive) and assuming that the ATM wants to use as few bills as possible, determinate the minimal number of 100, 50 and 20 dollar bills the ATM needs to dispense (in that order).\n\nExample\nFor n = 250, the result should be [2, 1, 0].\n\nFor n = 260, the result should be [2, 0, 3].\n\nFor n = 370, the result should be [3, 1, 1].\n\nInput/Output\n[input] integer n Amount of money to withdraw. Assume that n is always exchangeable with [100, 50, 20] bills.\n[output] integer array An array of number of 100, 50 and 20 dollar bills needed to complete the withdraw (in that order).\n*/\nfunction withdraw(n) {\n  let change = [0,0,0]\n  while (n>=20){\n    if (n%50===0){break}\n    n-=20\n    change[2]++\n  }\n  while (n>=100){\n    n-=100\n    change[0]++\n  }\n  while (n>=50){\n    n-=50\n    change[1]++\n  }\n  return change\n}\n"
  },
  {
    "path": "Simple Fun #170: Sum Groups.js",
    "content": "/*\nDescription:\nTask\nGiven an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the length of the final array.\n\nExample\nFor arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]\n\nThe result should be 6.\n\n[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]  -->\n         2+2+6       0+2+0     5+5+7+7       3+3+9\n[2, 1,   10,    5,    2,        24,     4,   15   ] -->\n                               2+24+4\n[2, 1,   10,    5,             30,           15   ]\nThe length of final array is 6\nInput/Output\n[input] integer array arr\n\nA non-empty array,\n\n1 ≤ arr.length ≤ 1000\n\n0 ≤ arr[i] ≤ 1000\n\n[output] an integer\n\nThe length of the final array\n*/\nfunction sumGroups(ar) {\n  let flat =(arr)=>{\n  let a = []\n  let even = arr[0]%2===0\n  for (let i=0;i<arr.length;i++){\n  let temp = []\n      if (even){\n        for (let j=i;j<arr.length;j++){\n          if (arr[j]%2===0){ \n          temp.push(arr[j]);\n          i++\n          }\n          else {\n          i--\n          even=false\n          break\n          }\n        } \n      } \n      else {\n         for (let j=i;j<arr.length;j++){\n          if (arr[j]%2!==0){ \n          temp.push(arr[j]);\n          i++\n          }\n          else {\n          i--\n          even=true\n          break\n          }\n      }\n    }\n         if (temp.length){\n         a.push(temp)\n         }\n  }\n  return a.map(v=>Array.isArray(v)?v.reduce((a,b)=>a+b,0):v)\n  }\n  let res = flat(ar)\n  while(res.length!==flat(res).length){\n    res=flat(res)\n  }\n  return res.length\n}\n"
  },
  {
    "path": "Simple Fun #23: Square Digits Sequence.js",
    "content": "/*\nDescription:\nTask\nConsider a sequence of numbers a0, a1, ..., an, in which an element is equal to the sum of squared digits of the previous element. The sequence ends once an element that has already been in the sequence appears again.\n\nGiven the first element a0, find the length of the sequence.\n\nExample\nFor a0 = 16, the output should be 9\n\nHere's how elements of the sequence are constructed:\n\na0 = 16\n\na1 = 12 + 62 = 37\n\na2 = 32 + 72 = 58\n\na3 = 52 + 82 = 89\n\na4 = 82 + 92 = 145\n\na5 = 12 + 42 + 52 = 42\n\na6 = 42 + 22 = 20\n\na7 = 22 + 02 = 4\n\na8 = 42 = 16, which has already occurred before (a0)\n\nThus, there are 9 elements in the sequence.\n\nFor a0 = 103, the output should be 4\n\nThe sequence goes as follows: 103 -> 10 -> 1 -> 1, 4 elements altogether.\n\nInput/Output\n[input] integer a0\n\nFirst element of a sequence, positive integer.\n\nConstraints: 1 ≤ a0 ≤ 650.\n\n[output] an integer\n*/\nfunction squareDigitsSequence(a0) {\n  let arr=[a0];\n  for (let i=0;;i++)\n  {  \n    let n = arr[i].toString().split``.reduce((a,b)=>a+(b*b),0)\n    if (arr.includes(n)){break}\n    else arr.push(n)\n  }\n  return arr.length+1\n}\n"
  },
  {
    "path": "Simple Fun #258: Is Divisible By 6.js",
    "content": "/*\nDescription:\nTask\nA masked number is a string that consists of digits and one asterisk (*) that should be replaced by exactly one digit. Given a masked number s, find all the possible options to replace the asterisk with a digit to produce an integer divisible by 6.\n\nInput/Output\n[input] string s\n\nA masked number.\n\n1 ≤ inputString.length ≤ 10000.\n\n[output] a string array\n\nSorted array of strings representing all non-negative integers that correspond to the given mask and are divisible by 6.\n\nExample\nFor s = \"1*0\", the output should be [\"120\", \"150\", \"180\"].\n\nFor s = \"*1\", the output should be [].\n\nFor s = \"1234567890123456789012345678*0\",\n\nthe output should be\n\n[\n\"123456789012345678901234567800\",\n\"123456789012345678901234567830\",\n\"123456789012345678901234567860\",\n\"123456789012345678901234567890\"]```\nAs you can see, the masked number may be very large ;-)\n*/\nconst BigNumber = require('bignumber.js');\nfunction isDivisibleBy6(s) {\n  const arr = []\n  for (let i=0;i<10;i++){\n    if (new BigNumber(s.replace(/\\*/g,i)).modulo(6).valueOf()==0) arr.push(s.replace(/\\*/g,i))\n  }\n  return arr\n}\n"
  },
  {
    "path": "Simple Fun #303: Prime Product.js",
    "content": "/*\nDescription:\nTask\nWe know that some numbers can be split into two primes. ie. 5 = 2 + 3, 10 = 3 + 7. But some numbers are not. ie. 17, 27, 35, etc..\n\nGiven a positive integer n. Determine whether it can be split into two primes. If yes, return the maximum product of two primes. If not, return 0 instead.\n\nInput/Output\n[input] integer n\n\nA positive integer.\n\n0 ≤ n ≤ 100000\n\n[output] an integer\n\nThe possible maximum product of two primes. or return 0 if it's impossible split into two primes.\n\nExample\nFor n = 1, the output should be 0.\n\n1 can not split into two primes\n\nFor n = 4, the output should be 4.\n\n4 can split into two primes 2 and 2. 2 x 2 = 4\n\nFor n = 20, the output should be 91.\n\n20 can split into two primes 7 and 13 or 3 and 17. The maximum product is 7 x 13 = 91\n*/\nfunction primeProduct(n){\n  const primes =  []\n  for(let i=1;i<=n;i++){\n    isPrime(i)?primes.push(i):1\n  }\n  const arr = []\n  for (let i=0;i<primes.length;i++){\n    for (let j=i;j<primes.length;j++){\n      primes[i]+primes[j]===n?arr.push([primes[i],primes[j]]):1\n    }\n  }\n  let pair =arr.sort((a,b)=>a.reduce((a,b)=>a*b,1)-b.reduce((a,b)=>a*b,1)).slice(-1)\n  return pair[0]?pair[0].reduce((a,b)=>a*b,1):0\n}\nfunction isPrime(n) {\n  let rt = Math.sqrt(n);\n  for(let i = 2; i <= rt; i++) {\n    if(n % i === 0) return false; \n  }\n  return n !== 1;\n}\n"
  },
  {
    "path": "Simple Fun #319: Number And IP Address.js",
    "content": "/*\nDescription:\nTask\nAn IP address contains four numbers(0-255) and separated by dots. It can be converted to a number by this way:\n\nGiven a string s represents a number or an IP address. Your task is to convert it to another representation(number to IP address or IP address to number).\n\nYou can assume that all inputs are valid.\n\nExample\nExample IP address: 10.0.3.193\n\nConvert each number to a 8-bit binary string (may needs to pad leading zeros to the left side):\n\n10  -->  00001010\n0   -->  00000000\n3   -->  00000011\n193 -->  11000001\nCombine these four strings: 00001010 00000000 00000011 11000001 and then convert them to a decimal number: 167773121\n\nInput/Output\n[input] string s\n\nA number or IP address in string format.\n\n[output] a string\n\nA converted number or IP address in string format.\n\nExample\nFor s = \"10.0.3.193\", the output should be \"167773121\".\n\nFor s = \"167969729\", the output should be \"10.3.3.193\".\n*/\nfunction numberAndIPaddress(s){\n  if (/\\./.test(s)) {return ipToNum(s).toString()}\n  else {return numToIp(s)}\n}\nfunction ipToNum(ip) {\n  return parseInt(ip.split`.`.map(v=>(v*1).toString(2).padStart(8,0)).join``,2)\n}\nfunction numToIp(num) {\n  return (num*1).toString(2).padStart(32,0).match(/.{8}/g).map(v=>parseInt(v,2)).join`.`\n}\n"
  },
  {
    "path": "Simple Fun #79: Delete a Digit.js",
    "content": "/*\nDescription:\nTask\nGiven an integer n, find the maximal number you can obtain by deleting exactly one digit of the given number.\n\nExample\nFor n = 152, the output should be 52;\n\nFor n = 1001, the output should be 101.\n\nInput/Output\n[input] integer n\n\nConstraints: 10 ≤ n ≤ 1000000.\n\n[output] an integer\n*/\n\nfunction deleteDigit(n) {\n  const arr=n.toString().split('');\n    let result=0;\n      for(let i=0;i<arr.length;i++){\n      let itisnotabigdeal=((arr.slice(0,i)+arr.slice(i+1))).split(',').join('')*1\n      if (itisnotabigdeal>result){\n      result = itisnotabigdeal;}\n      }\n      return result;\n}\n"
  },
  {
    "path": "Simple Sentences.js",
    "content": "/*\nImplement a function, so it will produce a sentence out of the given parts.\n\nArray of parts could contain:\n\nwords;\ncommas in the middle;\nmultiple periods at the end.\nSentence making rules:\n\nthere must always be a space between words;\nthere must not be a space between a comma and word on the left;\nthere must always be one and only one period at the end of a sentence.\nExample:\n\nmakeSentence(['hello', ',', 'my', 'dear']) // returns 'hello, my dear.'\n*/\nfunction makeSentence(parts) {\n   return parts.map(v=>v==='.'?null:v).join(' ').trim().replace(/ , /g,', ')+'.'\n}\n"
  },
  {
    "path": "Simple Simple Simple String Expansion.js",
    "content": "/*\nDescription:\nGiven a string that includes alphanumeric characters ('3a4B2d') return the expansion of that string: The numeric values represent the occurrence of each letter preceding that numeric value. There should be no numeric characters in the final string. Empty strings should return an empty string.\n\nThe first occurrence of a numeric value should be the number of times each character behind it is repeated, until the next numeric value appears.\n\nstringExpansion('3D2a5d2f') === 'DDDaadddddff'\nstringExpansion('3abc') === 'aaabbbccc'      // correct\nstringExpansion('3abc') !== 'aaabc'          // wrong\nstringExpansion('3abc') !== 'abcabcabc'      // wrong\nIf there are two consecutive numeric characters the first one is ignored.\n\nstringExpansion('3d332f2a') === 'dddffaa'\nIf there are two consecutive alphabetic characters then the first character has no effect on the one after it.\n\nstringExpansion('abcde') === 'abcde'\nYour code should be able to work for both lower and capital case letters.\n\nstringExpansion('') === ''\n*/\nfunction stringExpansion(s) {\n  return s.replace(/\\d\\D+/g,v=>{\n    let digit = v.replace(/[^0-9]/g,'')\n    let letters = v.replace(/[0-9]/g,'')\n    return letters.split``.map(v=>v.repeat(digit)).join``\n  }).replace(/\\d/g,'')\n}\n"
  },
  {
    "path": "Simple Substitution Cipher Helper.js",
    "content": "/*\nDescription:\nA simple substitution cipher replaces one character from an alphabet with a character from an alternate alphabet, where each character's position in an alphabet is mapped to the alternate alphabet for encoding or decoding.\n\nE.g.\n\nvar abc1 = \"abcdefghijklmnopqrstuvwxyz\";\nvar abc2 = \"etaoinshrdlucmfwypvbgkjqxz\";\n\nvar sub = new SubstitutionCipher(abc1, abc2);\nsub.encode(\"abc\") // => \"eta\"\nsub.encode(\"xyz\") // => \"qxz\"\nsub.encode(\"aeiou\") // => \"eirfg\"\n\nsub.decode(\"eta\") // => \"abc\"\nsub.decode(\"qxz\") // => \"xyz\"\nsub.decode(\"eirfg\") // => \"aeiou\"\nIf a character provided is not in the opposing alphabet, simply leave it as be.\n*/\nfunction SubstitutionCipher(ab1, ab2) {\n  this.encode = function (str) {\n    return str.split('').map(v=>ab1.includes(v)?v=ab1.indexOf(v):v)\n    .map(v=>typeof v==='number'?v=ab2[v]:v).join(``)\n  }\n  this.decode = function (str) {\n    return str.split('').map(v=>ab2.includes(v)?v=ab2.indexOf(v):v)\n    .map(v=>typeof v==='number'?v=ab1[v]:v).join(``)\n  }\n}\n"
  },
  {
    "path": "Simple Web Framework #1: Create a basic router.js",
    "content": "/*\nDescription:\nIn this Kata, you have to design a simple routing class for a web framework.\n\nThe router should accept bindings for a given url, http method and an action.\n\nThen, when a request with a bound url and method comes in, it should return the result of the action.\n\nExample usage:\n\nvar router = new Router;\nrouter.bind('/hello', 'GET', function(){ return 'hello world'; });\n\nrouter.runRequest('/hello', 'GET') // returns 'hello world';\nWhen asked for a route that doesn't exist, router should return:\n\n'Error 404: Not Found'\nThe router should also handle modifying existing routes. See the example tests for more details.\n*/\n\nclass Router {\n    \n    constructor() {\n        this.routes = new Map();\n    }  \n        \n    bind(url, method, action) {\n        this.routes.set(url + \":\" + method, action);\n    }\n    \n    runRequest(url, method) {\n        if (!this.routes.has(url + \":\" + method)) {\n            return \"Error 404: Not Found\";\n        }\n        return this.routes.get(url + \":\" + method)();\n    }\n    \n}\n"
  },
  {
    "path": "Simple card game.js",
    "content": "/*\nSteve and Josh are bored and want to play something. They don't want to think too much, so they come up with a really simple game. Write a function called winner and figure out who is going to win.\n\nThey are dealt the same number of cards. They both flip the card on the top of their deck. Whoever has a card with higher value wins the round and gets one point (if the cards are of the same value, neither of them gets a point). After this, the two cards are discarded and they flip another card from the top of their deck. They do this until they have no cards left.\n\ndeckSteve and deckJosh are arrays representing their decks. They are filled with cards, represented by a single character. The card rank is as follows (from lowest to highest):\n\n'2','3','4','5','6','7','8','9','T','J','Q','K','A'\nEvery card may appear in the deck more than once. Figure out who is going to win and return who wins and with what score:\n\n\"Steve wins x to y\"\nif Steve wins, where x is Steve's score, y is Josh's score;\n\n\"Josh wins x to y\"\nif Josh wins, where x is Josh's score, y is Steve's score;\n\n\"Tie\"\nif the score is tied at the end of the game.\n\n\n### Example: Steve is dealt: ```javascript ['A','7','8'] ```\nJosh is dealt:\n\n['K','5','9']\nIn first round, ace beats king and Steve gets one point.\nIn second round, 7 beats 5 and Steve gets his second point.\nIn third round, 9 beats 8 and Josh gets one point.\n\nYou should return: ```javascript \"Steve wins 2 to 1\" ```\n*/\nfunction winner(deckSteve, deckJosh) {\n  let cards={'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'T':10,'J':11,'Q':12,'K':13,'A':14}\n  let s=0;\n  let j=0;\n  deckSteve=deckSteve.map(v=>cards[v])\n  deckJosh=deckJosh.map(v=>cards[v])\n  deckSteve.map((v,i)=>v>deckJosh[i]?s++:v<deckJosh[i]?j++:null)\n  if (s===j) return 'Tie'\n  return s>j?`Steve wins ${s} to ${j}`:`Josh wins ${j} to ${s}`\n}\n"
  },
  {
    "path": "Simple frequency sort.js",
    "content": "/*\nDescription:\nIn this Kata, you will sort elements in an array by decreasing frequency of elements. If two elements have the same frequency, sort them by increasing value.\n\nsolve([2,3,5,3,7,9,5,3,7]) = [3,3,3,5,5,7,7,2,9]\n--we sort by highest frequency to lowest frequency. If two elements have same frequency, we sort by increasing value\nMore examples in test cases.\n\nGood luck!\n\nPlease also try Simple time difference\n*/\nfunction solve(arr){\n  let dict = arr.reduce((a,b)=>(a[b]=a[b]+1||1,a),{})\n  return arr.sort((a,b)=>dict[b]-dict[a]||a-b)\n}\n"
  },
  {
    "path": "Simple prime streaming.js",
    "content": "/*\nConsider a sequence made up of the consecutive prime numbers. This infinite sequence would start with:\n\n\"2357111317192329313741434753596167717379...\"\nYou will be given two numbers: a and b, and your task will be to return b elements starting from index a in this sequence.\n\nFor example:\nsolve(10,5) == `19232` Because these are 5 elements from index 10 in the sequence.\nTests go up to about index 20000.\n\nMore examples in test cases. Good luck!\n\nPlease also try Simple time difference\n*/\nconst primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973, 10007, 10009, 10037, 10039, 10061, 10067, 10069, 10079, 10091, 10093, 10099, 10103, 10111, 10133, 10139, 10141, 10151, 10159, 10163, 10169, 10177, 10181, 10193, 10211, 10223, 10243, 10247, 10253, 10259, 10267, 10271, 10273, 10289, 10301, 10303, 10313, 10321, 10331, 10333, 10337, 10343, 10357, 10369, 10391, 10399, 10427, 10429, 10433, 10453, 10457, 10459, 10463, 10477, 10487, 10499, 10501, 10513, 10529, 10531, 10559, 10567, 10589, 10597, 10601, 10607, 10613, 10627, 10631, 10639, 10651, 10657, 10663, 10667, 10687, 10691, 10709, 10711, 10723, 10729, 10733, 10739, 10753, 10771, 10781, 10789, 10799, 10831, 10837, 10847, 10853, 10859, 10861, 10867, 10883, 10889, 10891, 10903, 10909, 10937, 10939, 10949, 10957, 10973, 10979, 10987, 10993, 11003, 11027, 11047, 11057, 11059, 11069, 11071, 11083, 11087, 11093, 11113, 11117, 11119, 11131, 11149, 11159, 11161, 11171, 11173, 11177, 11197, 11213, 11239, 11243, 11251, 11257, 11261, 11273, 11279, 11287, 11299, 11311, 11317, 11321, 11329, 11351, 11353, 11369, 11383, 11393, 11399, 11411, 11423, 11437, 11443, 11447, 11467, 11471, 11483, 11489, 11491, 11497, 11503, 11519, 11527, 11549, 11551, 11579, 11587, 11593, 11597, 11617, 11621, 11633, 11657, 11677, 11681, 11689, 11699, 11701, 11717, 11719, 11731, 11743, 11777, 11779, 11783, 11789, 11801, 11807, 11813, 11821, 11827, 11831, 11833, 11839, 11863, 11867, 11887, 11897, 11903, 11909, 11923, 11927, 11933, 11939, 11941, 11953, 11959, 11969, 11971, 11981, 11987, 12007, 12011, 12037, 12041, 12043, 12049, 12071, 12073, 12097, 12101, 12107, 12109, 12113, 12119, 12143, 12149, 12157, 12161, 12163, 12197, 12203, 12211, 12227, 12239, 12241, 12251, 12253, 12263, 12269, 12277, 12281, 12289, 12301, 12323, 12329, 12343, 12347, 12373, 12377, 12379, 12391, 12401, 12409, 12413, 12421, 12433, 12437, 12451, 12457, 12473, 12479, 12487, 12491, 12497, 12503, 12511, 12517, 12527, 12539, 12541, 12547, 12553, 12569, 12577, 12583, 12589, 12601, 12611, 12613, 12619, 12637, 12641, 12647, 12653, 12659, 12671, 12689, 12697, 12703, 12713, 12721, 12739, 12743, 12757, 12763, 12781, 12791, 12799, 12809, 12821, 12823, 12829, 12841, 12853, 12889, 12893, 12899, 12907, 12911, 12917, 12919, 12923, 12941, 12953, 12959, 12967, 12973, 12979, 12983, 13001, 13003, 13007, 13009, 13033, 13037, 13043, 13049, 13063, 13093, 13099, 13103, 13109, 13121, 13127, 13147, 13151, 13159, 13163, 13171, 13177, 13183, 13187, 13217, 13219, 13229, 13241, 13249, 13259, 13267, 13291, 13297, 13309, 13313, 13327, 13331, 13337, 13339, 13367, 13381, 13397, 13399, 13411, 13417, 13421, 13441, 13451, 13457, 13463, 13469, 13477, 13487, 13499, 13513, 13523, 13537, 13553, 13567, 13577, 13591, 13597, 13613, 13619, 13627, 13633, 13649, 13669, 13679, 13681, 13687, 13691, 13693, 13697, 13709, 13711, 13721, 13723, 13729, 13751, 13757, 13759, 13763, 13781, 13789, 13799, 13807, 13829, 13831, 13841, 13859, 13873, 13877, 13879, 13883, 13901, 13903, 13907, 13913, 13921, 13931, 13933, 13963, 13967, 13997, 13999, 14009, 14011, 14029, 14033, 14051, 14057, 14071, 14081, 14083, 14087, 14107, 14143, 14149, 14153, 14159, 14173, 14177, 14197, 14207, 14221, 14243, 14249, 14251, 14281, 14293, 14303, 14321, 14323, 14327, 14341, 14347, 14369, 14387, 14389, 14401, 14407, 14411, 14419, 14423, 14431, 14437, 14447, 14449, 14461, 14479, 14489, 14503, 14519, 14533, 14537, 14543, 14549, 14551, 14557, 14561, 14563, 14591, 14593, 14621, 14627, 14629, 14633, 14639, 14653, 14657, 14669, 14683, 14699, 14713, 14717, 14723, 14731, 14737, 14741, 14747, 14753, 14759, 14767, 14771, 14779, 14783, 14797, 14813, 14821, 14827, 14831, 14843, 14851, 14867, 14869, 14879, 14887, 14891, 14897, 14923, 14929, 14939, 14947, 14951, 14957, 14969, 14983, 15013, 15017, 15031, 15053, 15061, 15073, 15077, 15083, 15091, 15101, 15107, 15121, 15131, 15137, 15139, 15149, 15161, 15173, 15187, 15193, 15199, 15217, 15227, 15233, 15241, 15259, 15263, 15269, 15271, 15277, 15287, 15289, 15299, 15307, 15313, 15319, 15329, 15331, 15349, 15359, 15361, 15373, 15377, 15383, 15391, 15401, 15413, 15427, 15439, 15443, 15451, 15461, 15467, 15473, 15493, 15497, 15511, 15527, 15541, 15551, 15559, 15569, 15581, 15583, 15601, 15607, 15619, 15629, 15641, 15643, 15647, 15649, 15661, 15667, 15671, 15679, 15683, 15727, 15731, 15733, 15737, 15739, 15749, 15761, 15767, 15773, 15787, 15791, 15797, 15803, 15809, 15817, 15823, 15859, 15877, 15881, 15887, 15889, 15901, 15907, 15913, 15919, 15923, 15937, 15959, 15971, 15973, 15991, 16001, 16007, 16033, 16057, 16061, 16063, 16067, 16069, 16073, 16087, 16091, 16097, 16103, 16111, 16127, 16139, 16141, 16183, 16187, 16189, 16193, 16217, 16223, 16229, 16231, 16249, 16253, 16267, 16273, 16301, 16319, 16333, 16339, 16349, 16361, 16363, 16369, 16381, 16411, 16417, 16421, 16427, 16433, 16447, 16451, 16453, 16477, 16481, 16487, 16493, 16519, 16529, 16547, 16553, 16561, 16567, 16573, 16603, 16607, 16619, 16631, 16633, 16649, 16651, 16657, 16661, 16673, 16691, 16693, 16699, 16703, 16729, 16741, 16747, 16759, 16763, 16787, 16811, 16823, 16829, 16831, 16843, 16871, 16879, 16883, 16889, 16901, 16903, 16921, 16927, 16931, 16937, 16943, 16963, 16979, 16981, 16987, 16993, 17011, 17021, 17027, 17029, 17033, 17041, 17047, 17053, 17077, 17093, 17099, 17107, 17117, 17123, 17137, 17159, 17167, 17183, 17189, 17191, 17203, 17207, 17209, 17231, 17239, 17257, 17291, 17293, 17299, 17317, 17321, 17327, 17333, 17341, 17351, 17359, 17377, 17383, 17387, 17389, 17393, 17401, 17417, 17419, 17431, 17443, 17449, 17467, 17471, 17477, 17483, 17489, 17491, 17497, 17509, 17519, 17539, 17551, 17569, 17573, 17579, 17581, 17597, 17599, 17609, 17623, 17627, 17657, 17659, 17669, 17681, 17683, 17707, 17713, 17729, 17737, 17747, 17749, 17761, 17783, 17789, 17791, 17807, 17827, 17837, 17839, 17851, 17863, 17881, 17891, 17903, 17909, 17911, 17921, 17923, 17929, 17939, 17957, 17959, 17971, 17977, 17981, 17987, 17989, 18013, 18041, 18043, 18047, 18049, 18059, 18061, 18077, 18089, 18097, 18119, 18121, 18127, 18131, 18133, 18143, 18149, 18169, 18181, 18191, 18199, 18211, 18217, 18223, 18229, 18233, 18251, 18253, 18257, 18269, 18287, 18289, 18301, 18307, 18311, 18313, 18329, 18341, 18353, 18367, 18371, 18379, 18397, 18401, 18413, 18427, 18433, 18439, 18443, 18451, 18457, 18461, 18481, 18493, 18503, 18517, 18521, 18523, 18539, 18541, 18553, 18583, 18587, 18593, 18617, 18637, 18661, 18671, 18679, 18691, 18701, 18713, 18719, 18731, 18743, 18749, 18757, 18773, 18787, 18793, 18797, 18803, 18839, 18859, 18869, 18899, 18911, 18913, 18917, 18919, 18947, 18959, 18973, 18979, 19001, 19009, 19013, 19031, 19037, 19051, 19069, 19073, 19079, 19081, 19087, 19121, 19139, 19141, 19157, 19163, 19181, 19183, 19207, 19211, 19213, 19219, 19231, 19237, 19249, 19259, 19267, 19273, 19289, 19301, 19309, 19319, 19333, 19373, 19379, 19381, 19387, 19391, 19403, 19417, 19421, 19423, 19427, 19429, 19433, 19441, 19447, 19457, 19463, 19469, 19471, 19477, 19483, 19489, 19501, 19507, 19531, 19541, 19543, 19553, 19559, 19571, 19577, 19583, 19597, 19603, 19609, 19661, 19681, 19687, 19697, 19699, 19709, 19717, 19727, 19739, 19751, 19753, 19759, 19763, 19777, 19793, 19801, 19813, 19819, 19841, 19843, 19853, 19861, 19867, 19889, 19891, 19913, 19919, 19927, 19937, 19949, 19961, 19963, 19973, 19979, 19991, 19993, 19997, 20011, 20021, 20023, 20029, 20047, 20051, 20063, 20071, 20089, 20101, 20107, 20113, 20117, 20123, 20129, 20143, 20147, 20149, 20161, 20173, 20177, 20183, 20201, 20219, 20231, 20233, 20249, 20261, 20269, 20287, 20297, 20323, 20327, 20333, 20341, 20347, 20353, 20357, 20359, 20369, 20389, 20393, 20399, 20407, 20411, 20431, 20441, 20443, 20477, 20479, 20483, 20507, 20509, 20521, 20533, 20543, 20549, 20551, 20563, 20593, 20599, 20611, 20627, 20639, 20641, 20663, 20681, 20693, 20707, 20717, 20719, 20731, 20743, 20747, 20749, 20753, 20759, 20771, 20773, 20789, 20807, 20809, 20849, 20857, 20873, 20879, 20887, 20897, 20899, 20903, 20921, 20929, 20939, 20947, 20959, 20963, 20981, 20983, 21001, 21011, 21013, 21017, 21019, 21023, 21031, 21059, 21061, 21067, 21089, 21101, 21107, 21121, 21139, 21143, 21149, 21157, 21163, 21169, 21179, 21187, 21191, 21193, 21211, 21221, 21227, 21247, 21269, 21277, 21283, 21313, 21317, 21319, 21323, 21341, 21347, 21377, 21379, 21383, 21391, 21397, 21401, 21407, 21419, 21433, 21467, 21481, 21487, 21491, 21493, 21499, 21503, 21517, 21521, 21523, 21529, 21557, 21559, 21563, 21569, 21577, 21587, 21589, 21599, 21601, 21611, 21613, 21617, 21647, 21649, 21661, 21673, 21683, 21701, 21713, 21727, 21737, 21739, 21751, 21757, 21767, 21773, 21787, 21799, 21803, 21817, 21821, 21839, 21841, 21851, 21859, 21863, 21871, 21881, 21893, 21911, 21929, 21937, 21943, 21961, 21977, 21991, 21997, 22003, 22013, 22027, 22031, 22037, 22039, 22051, 22063, 22067, 22073, 22079, 22091, 22093, 22109, 22111, 22123, 22129, 22133, 22147, 22153, 22157, 22159, 22171, 22189, 22193, 22229, 22247, 22259, 22271, 22273, 22277, 22279, 22283, 22291, 22303, 22307, 22343, 22349, 22367, 22369, 22381, 22391, 22397, 22409, 22433, 22441, 22447, 22453, 22469, 22481, 22483, 22501, 22511, 22531, 22541, 22543, 22549, 22567, 22571, 22573, 22613, 22619, 22621, 22637, 22639, 22643, 22651, 22669, 22679, 22691, 22697, 22699, 22709, 22717, 22721, 22727, 22739, 22741, 22751, 22769, 22777, 22783, 22787, 22807, 22811, 22817, 22853, 22859, 22861, 22871, 22877, 22901, 22907, 22921, 22937, 22943, 22961, 22963, 22973, 22993, 23003, 23011, 23017, 23021, 23027, 23029, 23039, 23041, 23053, 23057, 23059, 23063, 23071, 23081, 23087, 23099, 23117, 23131, 23143, 23159, 23167, 23173, 23189, 23197, 23201, 23203, 23209, 23227, 23251, 23269, 23279, 23291, 23293, 23297, 23311, 23321, 23327, 23333, 23339, 23357, 23369, 23371, 23399, 23417, 23431, 23447, 23459, 23473, 23497, 23509, 23531, 23537, 23539, 23549, 23557, 23561, 23563, 23567, 23581, 23593, 23599, 23603, 23609, 23623, 23627, 23629, 23633, 23663, 23669, 23671, 23677, 23687, 23689, 23719, 23741, 23743, 23747, 23753, 23761, 23767, 23773, 23789, 23801, 23813, 23819, 23827, 23831, 23833, 23857, 23869, 23873, 23879, 23887, 23893, 23899, 23909, 23911, 23917, 23929, 23957, 23971, 23977, 23981, 23993, 24001, 24007, 24019, 24023, 24029, 24043, 24049, 24061, 24071, 24077, 24083, 24091, 24097, 24103, 24107, 24109, 24113, 24121, 24133, 24137, 24151, 24169, 24179, 24181, 24197, 24203, 24223, 24229, 24239, 24247, 24251, 24281, 24317, 24329, 24337, 24359, 24371, 24373, 24379, 24391, 24407, 24413, 24419, 24421, 24439, 24443, 24469, 24473, 24481, 24499, 24509, 24517, 24527, 24533, 24547, 24551, 24571, 24593, 24611, 24623, 24631, 24659, 24671, 24677, 24683, 24691, 24697, 24709, 24733, 24749, 24763, 24767, 24781, 24793, 24799, 24809, 24821, 24841, 24847, 24851, 24859, 24877, 24889, 24907, 24917, 24919, 24923, 24943, 24953, 24967, 24971, 24977, 24979, 24989, 25013, 25031, 25033, 25037, 25057, 25073, 25087, 25097, 25111, 25117, 25121, 25127, 25147, 25153, 25163, 25169, 25171, 25183, 25189, 25219, 25229, 25237, 25243, 25247, 25253, 25261, 25301, 25303, 25307, 25309, 25321, 25339, 25343, 25349, 25357, 25367, 25373, 25391, 25409, 25411, 25423, 25439, 25447, 25453, 25457, 25463, 25469, 25471, 25523, 25537, 25541, 25561, 25577, 25579, 25583, 25589, 25601, 25603, 25609, 25621, 25633, 25639, 25643, 25657, 25667, 25673, 25679, 25693, 25703, 25717, 25733, 25741, 25747, 25759, 25763, 25771, 25793, 25799, 25801, 25819, 25841, 25847, 25849, 25867, 25873, 25889, 25903, 25913, 25919, 25931, 25933, 25939, 25943, 25951, 25969, 25981, 25997, 25999, 26003, 26017, 26021, 26029, 26041, 26053, 26083, 26099, 26107, 26111, 26113, 26119, 26141, 26153, 26161, 26171, 26177, 26183, 26189, 26203, 26209, 26227, 26237, 26249, 26251, 26261, 26263, 26267, 26293, 26297, 26309, 26317, 26321, 26339, 26347, 26357, 26371, 26387, 26393, 26399, 26407, 26417, 26423, 26431, 26437, 26449, 26459, 26479, 26489, 26497, 26501, 26513, 26539, 26557, 26561, 26573, 26591, 26597, 26627, 26633, 26641, 26647, 26669, 26681, 26683, 26687, 26693, 26699, 26701, 26711, 26713, 26717, 26723, 26729, 26731, 26737, 26759, 26777, 26783, 26801, 26813, 26821, 26833, 26839, 26849, 26861, 26863, 26879, 26881, 26891, 26893, 26903, 26921, 26927, 26947, 26951, 26953, 26959, 26981, 26987, 26993, 27011, 27017, 27031, 27043, 27059, 27061, 27067, 27073, 27077, 27091, 27103, 27107, 27109, 27127, 27143, 27179, 27191, 27197, 27211, 27239, 27241, 27253, 27259, 27271, 27277, 27281, 27283, 27299, 27329, 27337, 27361, 27367, 27397, 27407, 27409, 27427, 27431, 27437, 27449, 27457, 27479, 27481, 27487, 27509, 27527, 27529, 27539, 27541, 27551, 27581, 27583, 27611, 27617, 27631, 27647, 27653, 27673, 27689, 27691, 27697, 27701, 27733, 27737, 27739, 27743, 27749, 27751, 27763, 27767, 27773, 27779, 27791, 27793, 27799, 27803, 27809, 27817, 27823, 27827, 27847, 27851, 27883, 27893, 27901, 27917, 27919, 27941, 27943, 27947, 27953, 27961, 27967, 27983, 27997, 28001, 28019, 28027, 28031, 28051, 28057, 28069, 28081, 28087, 28097, 28099, 28109, 28111, 28123, 28151, 28163, 28181, 28183, 28201, 28211, 28219, 28229, 28277, 28279, 28283, 28289, 28297, 28307, 28309, 28319, 28349, 28351, 28387, 28393, 28403, 28409, 28411, 28429, 28433, 28439, 28447, 28463, 28477, 28493, 28499, 28513, 28517, 28537, 28541, 28547, 28549, 28559, 28571, 28573, 28579, 28591, 28597, 28603, 28607, 28619, 28621, 28627, 28631, 28643, 28649, 28657, 28661, 28663, 28669, 28687, 28697, 28703, 28711, 28723, 28729, 28751, 28753, 28759, 28771, 28789, 28793, 28807, 28813, 28817, 28837, 28843, 28859, 28867, 28871, 28879, 28901, 28909, 28921, 28927, 28933, 28949, 28961, 28979, 29009, 29017, 29021, 29023, 29027, 29033, 29059, 29063, 29077, 29101, 29123, 29129, 29131, 29137, 29147, 29153, 29167, 29173, 29179, 29191, 29201, 29207, 29209, 29221, 29231, 29243, 29251, 29269, 29287, 29297, 29303, 29311, 29327, 29333, 29339, 29347, 29363, 29383, 29387, 29389, 29399, 29401, 29411, 29423, 29429, 29437, 29443, 29453, 29473, 29483, 29501, 29527, 29531, 29537, 29567, 29569, 29573, 29581, 29587, 29599, 29611, 29629, 29633, 29641, 29663, 29669, 29671, 29683, 29717, 29723, 29741, 29753, 29759, 29761, 29789, 29803, 29819, 29833, 29837, 29851, 29863, 29867, 29873, 29879, 29881, 29917, 29921, 29927, 29947, 29959, 29983, 29989, 30011, 30013, 30029, 30047, 30059, 30071, 30089, 30091, 30097, 30103, 30109, 30113, 30119, 30133, 30137, 30139, 30161, 30169, 30181, 30187, 30197, 30203, 30211, 30223, 30241, 30253, 30259, 30269, 30271, 30293, 30307, 30313, 30319, 30323, 30341, 30347, 30367, 30389, 30391, 30403, 30427, 30431, 30449, 30467, 30469, 30491, 30493, 30497, 30509, 30517, 30529, 30539, 30553, 30557, 30559, 30577, 30593, 30631, 30637, 30643, 30649, 30661, 30671, 30677, 30689, 30697, 30703, 30707, 30713, 30727, 30757, 30763, 30773, 30781, 30803, 30809, 30817, 30829, 30839, 30841, 30851, 30853, 30859, 30869, 30871, 30881, 30893, 30911, 30931, 30937, 30941, 30949, 30971, 30977, 30983, 31013, 31019, 31033, 31039, 31051, 31063, 31069, 31079, 31081, 31091, 31121, 31123, 31139, 31147, 31151, 31153, 31159, 31177, 31181, 31183, 31189, 31193, 31219, 31223, 31231, 31237, 31247, 31249, 31253, 31259, 31267, 31271, 31277, 31307, 31319, 31321, 31327, 31333, 31337, 31357, 31379, 31387, 31391, 31393, 31397, 31469, 31477, 31481, 31489, 31511, 31513, 31517, 31531, 31541, 31543, 31547, 31567, 31573, 31583, 31601, 31607, 31627, 31643, 31649, 31657, 31663, 31667, 31687, 31699, 31721, 31723, 31727, 31729, 31741, 31751, 31769, 31771, 31793, 31799, 31817, 31847, 31849, 31859, 31873, 31883, 31891, 31907, 31957, 31963, 31973, 31981, 31991, 32003, 32009, 32027, 32029, 32051, 32057, 32059, 32063, 32069, 32077, 32083, 32089, 32099, 32117, 32119, 32141, 32143, 32159, 32173, 32183, 32189, 32191, 32203, 32213, 32233, 32237, 32251, 32257, 32261, 32297, 32299, 32303, 32309, 32321, 32323, 32327, 32341, 32353, 32359, 32363, 32369, 32371, 32377, 32381, 32401, 32411, 32413, 32423, 32429, 32441, 32443, 32467, 32479, 32491, 32497, 32503, 32507, 32531, 32533, 32537, 32561, 32563, 32569, 32573, 32579, 32587, 32603, 32609, 32611, 32621, 32633, 32647, 32653, 32687, 32693, 32707, 32713, 32717, 32719, 32749, 32771, 32779, 32783, 32789, 32797, 32801, 32803, 32831, 32833, 32839, 32843, 32869, 32887, 32909, 32911, 32917, 32933, 32939, 32941, 32957, 32969, 32971, 32983, 32987, 32993, 32999, 33013, 33023, 33029, 33037, 33049, 33053, 33071, 33073, 33083, 33091, 33107, 33113, 33119, 33149, 33151, 33161, 33179, 33181, 33191, 33199, 33203, 33211, 33223, 33247, 33287, 33289, 33301, 33311, 33317, 33329, 33331, 33343, 33347, 33349, 33353, 33359, 33377, 33391, 33403, 33409, 33413, 33427, 33457, 33461, 33469, 33479, 33487, 33493, 33503, 33521, 33529, 33533, 33547, 33563, 33569, 33577, 33581, 33587, 33589, 33599, 33601, 33613, 33617, 33619, 33623, 33629, 33637, 33641, 33647, 33679, 33703, 33713, 33721, 33739, 33749, 33751, 33757, 33767, 33769, 33773, 33791, 33797, 33809, 33811, 33827, 33829, 33851, 33857, 33863, 33871, 33889, 33893, 33911, 33923, 33931, 33937, 33941, 33961, 33967, 33997, 34019, 34031, 34033, 34039, 34057, 34061, 34123, 34127, 34129, 34141, 34147, 34157, 34159, 34171, 34183, 34211, 34213, 34217, 34231, 34253, 34259, 34261, 34267, 34273, 34283, 34297, 34301, 34303, 34313, 34319, 34327, 34337, 34351, 34361, 34367, 34369, 34381, 34403, 34421, 34429, 34439, 34457, 34469, 34471, 34483, 34487, 34499, 34501, 34511, 34513, 34519, 34537, 34543, 34549, 34583, 34589, 34591, 34603, 34607, 34613, 34631, 34649, 34651, 34667, 34673, 34679, 34687, 34693, 34703, 34721, 34729, 34739, 34747, 34757, 34759, 34763, 34781, 34807, 34819, 34841, 34843, 34847, 34849, 34871, 34877, 34883, 34897, 34913, 34919, 34939, 34949, 34961, 34963, 34981, 35023, 35027, 35051, 35053, 35059, 35069, 35081, 35083, 35089, 35099, 35107, 35111, 35117, 35129, 35141, 35149, 35153, 35159, 35171, 35201, 35221, 35227, 35251, 35257, 35267, 35279, 35281, 35291, 35311, 35317, 35323, 35327, 35339, 35353, 35363, 35381, 35393, 35401, 35407, 35419, 35423, 35437, 35447, 35449, 35461, 35491, 35507, 35509, 35521, 35527, 35531, 35533, 35537, 35543, 35569, 35573, 35591, 35593, 35597, 35603, 35617, 35671, 35677, 35729, 35731, 35747, 35753, 35759, 35771, 35797, 35801, 35803, 35809, 35831, 35837, 35839, 35851, 35863, 35869, 35879, 35897, 35899, 35911, 35923, 35933, 35951, 35963, 35969, 35977, 35983, 35993, 35999, 36007, 36011, 36013, 36017, 36037, 36061, 36067, 36073, 36083, 36097, 36107, 36109, 36131, 36137, 36151, 36161, 36187, 36191, 36209, 36217, 36229, 36241, 36251, 36263, 36269, 36277, 36293, 36299, 36307, 36313, 36319, 36341, 36343, 36353, 36373, 36383, 36389, 36433, 36451, 36457, 36467, 36469, 36473, 36479, 36493, 36497, 36523, 36527, 36529, 36541, 36551, 36559, 36563, 36571, 36583, 36587, 36599, 36607, 36629, 36637, 36643, 36653, 36671, 36677, 36683, 36691, 36697, 36709, 36713, 36721, 36739, 36749, 36761, 36767, 36779, 36781, 36787, 36791, 36793, 36809, 36821, 36833, 36847, 36857, 36871, 36877, 36887, 36899, 36901, 36913, 36919, 36923, 36929, 36931, 36943, 36947, 36973, 36979, 36997, 37003, 37013, 37019, 37021, 37039, 37049, 37057, 37061, 37087, 37097, 37117, 37123, 37139, 37159, 37171, 37181, 37189, 37199, 37201, 37217, 37223, 37243, 37253, 37273, 37277, 37307, 37309, 37313, 37321, 37337, 37339, 37357, 37361, 37363, 37369, 37379, 37397, 37409, 37423, 37441, 37447, 37463, 37483, 37489, 37493, 37501, 37507, 37511, 37517, 37529, 37537, 37547, 37549, 37561, 37567, 37571, 37573, 37579, 37589, 37591, 37607, 37619, 37633, 37643, 37649, 37657, 37663, 37691, 37693, 37699, 37717, 37747, 37781, 37783, 37799, 37811, 37813, 37831, 37847, 37853, 37861, 37871, 37879, 37889, 37897, 37907, 37951, 37957, 37963, 37967, 37987, 37991, 37993, 37997, 38011, 38039, 38047, 38053, 38069, 38083, 38113, 38119, 38149, 38153, 38167, 38177, 38183, 38189, 38197, 38201, 38219, 38231, 38237, 38239, 38261, 38273, 38281, 38287, 38299, 38303, 38317, 38321, 38327, 38329, 38333, 38351, 38371, 38377, 38393, 38431, 38447, 38449, 38453, 38459, 38461, 38501, 38543, 38557, 38561, 38567, 38569, 38593, 38603, 38609, 38611, 38629, 38639, 38651, 38653, 38669, 38671, 38677, 38693, 38699, 38707, 38711, 38713, 38723, 38729, 38737, 38747, 38749, 38767, 38783, 38791, 38803, 38821, 38833, 38839, 38851, 38861, 38867, 38873, 38891, 38903, 38917, 38921, 38923, 38933, 38953, 38959, 38971, 38977, 38993, 39019, 39023, 39041, 39043, 39047, 39079, 39089, 39097, 39103, 39107, 39113, 39119, 39133, 39139, 39157, 39161, 39163, 39181, 39191, 39199, 39209, 39217, 39227, 39229, 39233, 39239, 39241, 39251, 39293, 39301, 39313, 39317, 39323, 39341, 39343, 39359, 39367, 39371, 39373, 39383, 39397, 39409, 39419, 39439, 39443, 39451, 39461, 39499, 39503, 39509, 39511, 39521, 39541, 39551, 39563, 39569, 39581, 39607, 39619, 39623, 39631, 39659, 39667, 39671, 39679, 39703, 39709, 39719, 39727, 39733, 39749, 39761, 39769, 39779, 39791, 39799, 39821, 39827, 39829, 39839, 39841, 39847, 39857, 39863, 39869, 39877, 39883, 39887, 39901, 39929, 39937, 39953, 39971, 39979, 39983, 39989, 40009, 40013, 40031, 40037, 40039, 40063, 40087, 40093, 40099, 40111, 40123, 40127, 40129, 40151, 40153, 40163, 40169, 40177, 40189, 40193, 40213, 40231, 40237, 40241, 40253, 40277, 40283, 40289, 40343, 40351, 40357, 40361, 40387, 40423, 40427, 40429, 40433, 40459, 40471, 40483, 40487, 40493, 40499, 40507, 40519, 40529, 40531, 40543, 40559, 40577, 40583, 40591, 40597, 40609, 40627, 40637, 40639, 40693, 40697, 40699, 40709, 40739, 40751, 40759, 40763, 40771, 40787, 40801, 40813, 40819, 40823, 40829, 40841, 40847, 40849, 40853, 40867, 40879, 40883, 40897, 40903, 40927, 40933, 40939, 40949, 40961, 40973, 40993, 41011, 41017, 41023, 41039, 41047, 41051, 41057, 41077, 41081, 41113, 41117, 41131, 41141, 41143, 41149, 41161, 41177, 41179, 41183, 41189, 41201, 41203, 41213, 41221, 41227, 41231, 41233, 41243, 41257, 41263, 41269, 41281, 41299, 41333, 41341, 41351, 41357, 41381, 41387, 41389, 41399, 41411, 41413, 41443, 41453, 41467, 41479, 41491, 41507, 41513, 41519, 41521, 41539, 41543, 41549, 41579, 41593, 41597, 41603, 41609, 41611, 41617, 41621, 41627, 41641, 41647, 41651, 41659, 41669, 41681, 41687, 41719, 41729, 41737, 41759, 41761, 41771, 41777, 41801, 41809, 41813, 41843, 41849, 41851, 41863, 41879, 41887, 41893, 41897, 41903, 41911, 41927, 41941, 41947, 41953, 41957, 41959, 41969, 41981, 41983, 41999, 42013, 42017, 42019, 42023, 42043, 42061, 42071, 42073, 42083, 42089, 42101, 42131, 42139, 42157, 42169, 42179, 42181, 42187, 42193, 42197, 42209, 42221, 42223, 42227, 42239, 42257, 42281, 42283, 42293, 42299, 42307, 42323, 42331, 42337, 42349, 42359, 42373, 42379, 42391, 42397, 42403, 42407, 42409, 42433, 42437, 42443, 42451, 42457, 42461, 42463, 42467, 42473, 42487, 42491, 42499, 42509, 42533, 42557, 42569, 42571, 42577, 42589, 42611, 42641, 42643, 42649, 42667, 42677, 42683, 42689, 42697, 42701, 42703, 42709, 42719, 42727, 42737, 42743, 42751, 42767, 42773, 42787, 42793, 42797, 42821, 42829, 42839, 42841, 42853, 42859, 42863, 42899, 42901, 42923, 42929, 42937, 42943, 42953, 42961, 42967, 42979, 42989, 43003, 43013, 43019, 43037, 43049, 43051, 43063, 43067, 43093, 43103, 43117, 43133, 43151, 43159, 43177, 43189, 43201, 43207, 43223, 43237, 43261, 43271, 43283, 43291, 43313, 43319, 43321, 43331, 43391, 43397, 43399, 43403, 43411, 43427, 43441, 43451, 43457, 43481, 43487, 43499, 43517, 43541, 43543, 43573, 43577, 43579, 43591, 43597, 43607, 43609, 43613, 43627, 43633, 43649, 43651, 43661, 43669, 43691, 43711, 43717, 43721, 43753, 43759, 43777, 43781, 43783, 43787, 43789, 43793, 43801, 43853, 43867, 43889, 43891, 43913, 43933, 43943, 43951, 43961, 43963, 43969, 43973, 43987, 43991, 43997, 44017, 44021, 44027, 44029, 44041, 44053, 44059, 44071, 44087, 44089, 44101, 44111, 44119, 44123, 44129, 44131, 44159, 44171, 44179, 44189, 44201, 44203, 44207, 44221, 44249, 44257, 44263, 44267, 44269, 44273, 44279, 44281, 44293, 44351, 44357, 44371, 44381, 44383, 44389, 44417, 44449, 44453, 44483, 44491, 44497, 44501, 44507, 44519, 44531, 44533, 44537, 44543, 44549, 44563, 44579, 44587, 44617, 44621, 44623, 44633, 44641, 44647, 44651, 44657, 44683, 44687, 44699, 44701, 44711, 44729, 44741, 44753, 44771, 44773, 44777, 44789, 44797, 44809, 44819, 44839, 44843, 44851, 44867, 44879, 44887, 44893, 44909, 44917, 44927, 44939, 44953, 44959, 44963, 44971, 44983, 44987, 45007, 45013, 45053, 45061, 45077, 45083, 45119, 45121, 45127, 45131, 45137, 45139, 45161, 45179, 45181, 45191, 45197, 45233, 45247, 45259, 45263, 45281, 45289, 45293, 45307, 45317, 45319, 45329, 45337, 45341, 45343, 45361, 45377, 45389, 45403, 45413, 45427, 45433, 45439, 45481, 45491, 45497, 45503, 45523, 45533, 45541, 45553, 45557, 45569, 45587, 45589, 45599, 45613, 45631, 45641, 45659, 45667, 45673, 45677, 45691, 45697, 45707, 45737, 45751, 45757, 45763, 45767, 45779, 45817, 45821, 45823, 45827, 45833, 45841, 45853, 45863, 45869, 45887, 45893, 45943, 45949, 45953, 45959, 45971, 45979, 45989, 46021, 46027, 46049, 46051, 46061, 46073, 46091, 46093, 46099, 46103, 46133, 46141, 46147, 46153, 46171, 46181, 46183, 46187, 46199, 46219, 46229, 46237, 46261, 46271, 46273, 46279, 46301, 46307, 46309, 46327, 46337, 46349, 46351, 46381, 46399, 46411, 46439, 46441, 46447, 46451, 46457, 46471, 46477, 46489, 46499, 46507, 46511, 46523, 46549, 46559, 46567, 46573, 46589, 46591, 46601, 46619, 46633, 46639, 46643, 46649, 46663, 46679, 46681, 46687, 46691, 46703, 46723, 46727, 46747, 46751, 46757, 46769, 46771, 46807, 46811, 46817, 46819, 46829, 46831, 46853, 46861, 46867, 46877, 46889, 46901, 46919, 46933, 46957, 46993, 46997, 47017, 47041, 47051, 47057, 47059, 47087, 47093, 47111, 47119, 47123, 47129, 47137, 47143, 47147, 47149, 47161, 47189, 47207, 47221, 47237, 47251, 47269, 47279, 47287, 47293, 47297, 47303, 47309, 47317, 47339, 47351, 47353, 47363, 47381, 47387, 47389, 47407, 47417, 47419, 47431, 47441, 47459, 47491, 47497, 47501, 47507, 47513, 47521, 47527, 47533, 47543, 47563, 47569, 47581, 47591, 47599, 47609, 47623, 47629, 47639, 47653, 47657, 47659, 47681, 47699, 47701, 47711, 47713, 47717, 47737, 47741, 47743, 47777, 47779, 47791, 47797, 47807, 47809, 47819, 47837, 47843, 47857, 47869, 47881, 47903, 47911, 47917, 47933, 47939, 47947, 47951, 47963, 47969, 47977, 47981, 48017, 48023, 48029, 48049, 48073, 48079, 48091, 48109, 48119, 48121, 48131, 48157, 48163, 48179, 48187, 48193, 48197, 48221, 48239, 48247, 48259, 48271, 48281, 48299, 48311, 48313, 48337, 48341, 48353, 48371, 48383, 48397, 48407, 48409, 48413, 48437, 48449, 48463, 48473, 48479, 48481, 48487, 48491, 48497, 48523, 48527, 48533, 48539, 48541, 48563, 48571, 48589, 48593, 48611, 48619, 48623, 48647, 48649, 48661, 48673, 48677, 48679, 48731, 48733, 48751, 48757, 48761, 48767, 48779, 48781, 48787, 48799, 48809, 48817, 48821, 48823, 48847, 48857, 48859, 48869, 48871, 48883, 48889, 48907, 48947, 48953, 48973, 48989, 48991, 49003, 49009, 49019, 49031, 49033, 49037, 49043, 49057, 49069, 49081, 49103, 49109, 49117, 49121, 49123, 49139, 49157, 49169, 49171, 49177, 49193, 49199, 49201, 49207, 49211, 49223, 49253, 49261, 49277, 49279, 49297, 49307, 49331, 49333, 49339, 49363, 49367, 49369, 49391, 49393, 49409, 49411, 49417, 49429, 49433, 49451, 49459, 49463, 49477, 49481, 49499, 49523, 49529, 49531, 49537, 49547, 49549, 49559, 49597, 49603, 49613, 49627, 49633, 49639, 49663, 49667, 49669, 49681, 49697, 49711, 49727, 49739, 49741, 49747, 49757, 49783, 49787, 49789, 49801, 49807, 49811, 49823, 49831, 49843, 49853, 49871, 49877, 49891, 49919, 49921, 49927, 49937, 49939, 49943, 49957, 49991, 49993, 49999, 50021, 50023, 50033, 50047, 50051, 50053, 50069, 50077, 50087, 50093, 50101, 50111, 50119, 50123, 50129, 50131, 50147, 50153, 50159, 50177, 50207, 50221, 50227, 50231, 50261, 50263, 50273, 50287, 50291, 50311, 50321, 50329, 50333, 50341, 50359, 50363, 50377, 50383, 50387, 50411, 50417, 50423, 50441, 50459, 50461, 50497, 50503, 50513, 50527, 50539, 50543, 50549, 50551, 50581, 50587, 50591, 50593, 50599, 50627, 50647, 50651, 50671, 50683, 50707, 50723, 50741, 50753, 50767, 50773, 50777, 50789, 50821, 50833, 50839, 50849, 50857, 50867, 50873, 50891, 50893, 50909, 50923, 50929, 50951, 50957, 50969, 50971, 50989, 50993, 51001, 51031, 51043, 51047, 51059, 51061, 51071, 51109, 51131, 51133, 51137, 51151, 51157, 51169, 51193, 51197, 51199, 51203, 51217, 51229, 51239, 51241, 51257, 51263, 51283, 51287, 51307, 51329, 51341, 51343, 51347, 51349, 51361, 51383, 51407, 51413, 51419, 51421, 51427, 51431, 51437, 51439, 51449, 51461, 51473, 51479, 51481, 51487, 51503, 51511, 51517, 51521, 51539, 51551, 51563, 51577, 51581, 51593, 51599, 51607, 51613, 51631, 51637, 51647, 51659, 51673, 51679, 51683, 51691, 51713, 51719, 51721, 51749, 51767, 51769, 51787, 51797, 51803, 51817, 51827, 51829, 51839, 51853, 51859, 51869, 51871, 51893, 51899, 51907, 51913, 51929, 51941, 51949, 51971, 51973, 51977, 51991, 52009, 52021, 52027, 52051, 52057, 52067, 52069, 52081, 52103, 52121, 52127, 52147, 52153, 52163, 52177, 52181, 52183, 52189, 52201, 52223, 52237, 52249, 52253, 52259, 52267, 52289, 52291, 52301, 52313, 52321, 52361, 52363, 52369, 52379, 52387, 52391, 52433, 52453, 52457, 52489, 52501, 52511, 52517, 52529, 52541, 52543, 52553, 52561, 52567, 52571, 52579, 52583, 52609, 52627, 52631, 52639, 52667, 52673, 52691, 52697, 52709, 52711, 52721, 52727, 52733, 52747, 52757, 52769, 52783, 52807, 52813, 52817, 52837, 52859, 52861, 52879, 52883, 52889, 52901, 52903, 52919, 52937, 52951, 52957, 52963, 52967, 52973, 52981, 52999, 53003, 53017, 53047, 53051, 53069, 53077, 53087, 53089, 53093, 53101, 53113, 53117, 53129, 53147, 53149, 53161, 53171, 53173, 53189, 53197, 53201, 53231, 53233, 53239, 53267, 53269, 53279, 53281, 53299, 53309, 53323, 53327, 53353, 53359, 53377, 53381, 53401, 53407, 53411, 53419, 53437, 53441, 53453, 53479, 53503, 53507, 53527, 53549, 53551, 53569, 53591, 53593, 53597, 53609, 53611, 53617, 53623, 53629, 53633, 53639, 53653, 53657, 53681, 53693, 53699, 53717, 53719, 53731, 53759, 53773, 53777, 53783, 53791, 53813, 53819, 53831, 53849, 53857, 53861, 53881, 53887, 53891, 53897, 53899, 53917, 53923, 53927, 53939, 53951, 53959, 53987, 53993, 54001, 54011, 54013, 54037, 54049, 54059, 54083, 54091, 54101, 54121, 54133, 54139, 54151, 54163, 54167, 54181, 54193, 54217, 54251, 54269, 54277, 54287, 54293, 54311, 54319, 54323, 54331, 54347, 54361, 54367, 54371, 54377, 54401, 54403, 54409, 54413, 54419, 54421, 54437, 54443, 54449, 54469, 54493, 54497, 54499, 54503, 54517, 54521, 54539, 54541, 54547, 54559, 54563, 54577, 54581, 54583, 54601, 54617, 54623, 54629, 54631, 54647, 54667, 54673, 54679, 54709, 54713, 54721, 54727, 54751, 54767, 54773, 54779, 54787, 54799, 54829, 54833, 54851, 54869, 54877, 54881, 54907, 54917, 54919, 54941, 54949, 54959, 54973, 54979, 54983, 55001, 55009, 55021, 55049, 55051, 55057, 55061, 55073, 55079, 55103, 55109, 55117, 55127, 55147, 55163, 55171, 55201, 55207, 55213, 55217, 55219, 55229, 55243, 55249, 55259, 55291, 55313, 55331, 55333, 55337, 55339, 55343, 55351, 55373, 55381, 55399, 55411, 55439, 55441, 55457, 55469, 55487, 55501, 55511, 55529, 55541, 55547, 55579, 55589, 55603, 55609, 55619, 55621, 55631, 55633, 55639, 55661, 55663, 55667, 55673, 55681, 55691, 55697, 55711, 55717, 55721, 55733, 55763, 55787, 55793, 55799, 55807, 55813, 55817, 55819, 55823, 55829, 55837, 55843, 55849, 55871, 55889, 55897, 55901, 55903, 55921, 55927, 55931, 55933, 55949, 55967, 55987, 55997, 56003, 56009, 56039, 56041, 56053, 56081, 56087, 56093, 56099, 56101, 56113, 56123, 56131, 56149, 56167, 56171, 56179, 56197, 56207, 56209, 56237, 56239, 56249, 56263, 56267, 56269, 56299, 56311, 56333, 56359, 56369, 56377, 56383, 56393, 56401, 56417, 56431, 56437, 56443, 56453, 56467, 56473, 56477, 56479, 56489, 56501, 56503, 56509, 56519, 56527, 56531, 56533, 56543, 56569, 56591, 56597, 56599, 56611, 56629, 56633, 56659, 56663, 56671, 56681, 56687, 56701, 56711, 56713, 56731, 56737, 56747, 56767, 56773, 56779, 56783, 56807, 56809, 56813, 56821, 56827, 56843, 56857, 56873, 56891, 56893, 56897, 56909, 56911, 56921, 56923, 56929, 56941, 56951, 56957, 56963, 56983, 56989, 56993, 56999, 57037, 57041, 57047, 57059, 57073, 57077, 57089, 57097, 57107, 57119, 57131, 57139, 57143, 57149, 57163, 57173, 57179, 57191, 57193, 57203, 57221, 57223, 57241, 57251, 57259, 57269, 57271, 57283, 57287, 57301, 57329, 57331, 57347, 57349, 57367, 57373, 57383, 57389, 57397, 57413, 57427, 57457, 57467, 57487, 57493, 57503, 57527, 57529, 57557, 57559, 57571, 57587, 57593, 57601, 57637, 57641, 57649, 57653, 57667, 57679, 57689, 57697, 57709, 57713, 57719, 57727, 57731, 57737, 57751, 57773, 57781, 57787, 57791, 57793, 57803, 57809, 57829, 57839, 57847, 57853, 57859, 57881, 57899, 57901, 57917, 57923, 57943, 57947, 57973, 57977, 57991, 58013, 58027, 58031, 58043, 58049, 58057, 58061, 58067, 58073, 58099, 58109, 58111, 58129, 58147, 58151, 58153, 58169, 58171, 58189, 58193, 58199, 58207, 58211, 58217, 58229, 58231, 58237, 58243, 58271, 58309, 58313, 58321, 58337, 58363, 58367, 58369, 58379, 58391, 58393, 58403, 58411, 58417, 58427, 58439, 58441, 58451, 58453, 58477, 58481, 58511, 58537, 58543, 58549, 58567, 58573, 58579, 58601, 58603, 58613, 58631, 58657, 58661, 58679, 58687, 58693, 58699, 58711, 58727, 58733, 58741, 58757, 58763, 58771, 58787, 58789, 58831, 58889, 58897, 58901, 58907, 58909, 58913, 58921, 58937, 58943, 58963, 58967, 58979, 58991, 58997, 59009, 59011, 59021, 59023, 59029, 59051, 59053, 59063, 59069, 59077, 59083, 59093, 59107, 59113, 59119, 59123, 59141, 59149, 59159, 59167, 59183, 59197, 59207, 59209, 59219, 59221, 59233, 59239, 59243, 59263, 59273, 59281, 59333, 59341, 59351, 59357, 59359, 59369, 59377, 59387, 59393, 59399, 59407, 59417, 59419, 59441, 59443, 59447, 59453, 59467, 59471, 59473, 59497, 59509, 59513, 59539, 59557, 59561, 59567, 59581, 59611, 59617, 59621, 59627, 59629, 59651, 59659, 59663, 59669, 59671, 59693, 59699, 59707, 59723, 59729, 59743, 59747, 59753, 59771, 59779, 59791, 59797, 59809, 59833, 59863, 59879, 59887, 59921, 59929, 59951, 59957, 59971, 59981, 59999, 60013, 60017, 60029, 60037, 60041, 60077, 60083, 60089, 60091, 60101, 60103, 60107, 60127, 60133, 60139, 60149, 60161, 60167, 60169, 60209, 60217, 60223, 60251, 60257, 60259, 60271, 60289, 60293, 60317, 60331, 60337, 60343, 60353, 60373, 60383, 60397, 60413, 60427, 60443, 60449, 60457, 60493, 60497, 60509, 60521, 60527, 60539, 60589, 60601, 60607, 60611, 60617, 60623, 60631, 60637, 60647, 60649, 60659, 60661, 60679, 60689, 60703, 60719, 60727, 60733, 60737, 60757, 60761, 60763, 60773, 60779, 60793, 60811, 60821, 60859, 60869, 60887, 60889, 60899, 60901, 60913, 60917, 60919, 60923, 60937, 60943, 60953, 60961, 61001, 61007, 61027, 61031, 61043, 61051, 61057, 61091, 61099, 61121, 61129, 61141, 61151, 61153, 61169, 61211, 61223, 61231, 61253, 61261, 61283, 61291, 61297, 61331, 61333, 61339, 61343, 61357, 61363, 61379, 61381, 61403, 61409, 61417, 61441, 61463, 61469, 61471, 61483, 61487, 61493, 61507, 61511, 61519, 61543, 61547, 61553, 61559, 61561, 61583, 61603, 61609, 61613, 61627, 61631, 61637, 61643, 61651, 61657, 61667, 61673, 61681, 61687, 61703, 61717, 61723, 61729, 61751, 61757, 61781, 61813, 61819, 61837, 61843, 61861, 61871, 61879, 61909, 61927, 61933, 61949, 61961, 61967, 61979, 61981, 61987, 61991, 62003, 62011, 62017, 62039, 62047, 62053, 62057, 62071, 62081, 62099, 62119, 62129, 62131, 62137, 62141, 62143, 62171, 62189, 62191, 62201, 62207, 62213, 62219, 62233, 62273, 62297, 62299, 62303, 62311, 62323, 62327, 62347, 62351, 62383, 62401, 62417, 62423, 62459, 62467, 62473, 62477, 62483, 62497, 62501, 62507, 62533, 62539, 62549, 62563, 62581, 62591, 62597, 62603, 62617, 62627, 62633, 62639, 62653, 62659, 62683, 62687, 62701, 62723, 62731, 62743, 62753, 62761, 62773, 62791, 62801, 62819, 62827, 62851, 62861, 62869, 62873, 62897, 62903, 62921, 62927, 62929, 62939, 62969, 62971, 62981, 62983, 62987, 62989, 63029, 63031, 63059, 63067, 63073, 63079, 63097, 63103, 63113, 63127, 63131, 63149, 63179, 63197, 63199, 63211, 63241, 63247, 63277, 63281, 63299, 63311, 63313, 63317, 63331, 63337, 63347, 63353, 63361, 63367, 63377, 63389, 63391, 63397, 63409, 63419, 63421, 63439, 63443, 63463, 63467, 63473, 63487, 63493, 63499, 63521, 63527, 63533, 63541, 63559, 63577, 63587, 63589, 63599, 63601, 63607, 63611, 63617, 63629, 63647, 63649, 63659, 63667, 63671, 63689, 63691, 63697, 63703, 63709, 63719, 63727, 63737, 63743, 63761, 63773, 63781, 63793, 63799, 63803, 63809, 63823, 63839, 63841, 63853, 63857, 63863, 63901, 63907, 63913, 63929, 63949, 63977, 63997, 64007, 64013, 64019, 64033, 64037, 64063, 64067, 64081, 64091, 64109, 64123, 64151, 64153, 64157, 64171, 64187, 64189, 64217, 64223, 64231, 64237, 64271, 64279, 64283, 64301, 64303, 64319, 64327, 64333, 64373, 64381, 64399, 64403, 64433, 64439, 64451, 64453, 64483, 64489, 64499, 64513, 64553, 64567, 64577, 64579, 64591, 64601, 64609, 64613, 64621, 64627, 64633, 64661, 64663, 64667, 64679, 64693, 64709, 64717, 64747, 64763, 64781, 64783, 64793, 64811, 64817, 64849, 64853, 64871, 64877, 64879, 64891, 64901, 64919, 64921, 64927, 64937, 64951, 64969, 64997, 65003, 65011, 65027, 65029, 65033, 65053, 65063, 65071, 65089, 65099, 65101, 65111, 65119, 65123, 65129, 65141, 65147, 65167, 65171, 65173, 65179, 65183, 65203, 65213, 65239, 65257, 65267, 65269, 65287, 65293, 65309, 65323, 65327, 65353, 65357, 65371, 65381, 65393, 65407, 65413, 65419, 65423, 65437, 65447, 65449, 65479, 65497, 65519, 65521, 65537, 65539, 65543, 65551, 65557, 65563, 65579, 65581, 65587, 65599, 65609, 65617, 65629, 65633, 65647, 65651, 65657, 65677, 65687, 65699, 65701, 65707, 65713, 65717, 65719, 65729, 65731, 65761, 65777, 65789, 65809, 65827, 65831, 65837, 65839, 65843, 65851, 65867, 65881, 65899, 65921, 65927, 65929, 65951, 65957, 65963, 65981, 65983, 65993, 66029, 66037, 66041, 66047, 66067, 66071, 66083, 66089, 66103, 66107, 66109, 66137, 66161, 66169, 66173, 66179, 66191, 66221, 66239, 66271, 66293, 66301, 66337, 66343, 66347, 66359, 66361, 66373, 66377, 66383, 66403, 66413, 66431, 66449, 66457, 66463, 66467, 66491, 66499, 66509, 66523, 66529, 66533, 66541, 66553, 66569, 66571, 66587, 66593, 66601, 66617, 66629, 66643, 66653, 66683, 66697, 66701, 66713, 66721, 66733, 66739, 66749, 66751, 66763, 66791, 66797, 66809, 66821, 66841, 66851, 66853, 66863, 66877, 66883, 66889, 66919, 66923, 66931, 66943, 66947, 66949, 66959, 66973, 66977, 67003, 67021, 67033, 67043, 67049, 67057, 67061, 67073, 67079, 67103, 67121, 67129, 67139, 67141, 67153, 67157, 67169, 67181, 67187, 67189, 67211, 67213, 67217, 67219, 67231, 67247, 67261, 67271, 67273, 67289, 67307, 67339, 67343, 67349, 67369, 67391, 67399, 67409, 67411, 67421, 67427, 67429, 67433, 67447, 67453, 67477, 67481, 67489, 67493, 67499, 67511, 67523, 67531, 67537, 67547, 67559, 67567, 67577, 67579, 67589, 67601, 67607, 67619, 67631, 67651, 67679, 67699, 67709, 67723, 67733, 67741, 67751, 67757, 67759, 67763, 67777, 67783, 67789, 67801, 67807, 67819, 67829, 67843, 67853, 67867, 67883, 67891, 67901, 67927, 67931, 67933, 67939, 67943, 67957, 67961, 67967, 67979, 67987, 67993, 68023, 68041, 68053, 68059, 68071, 68087, 68099, 68111, 68113, 68141, 68147, 68161, 68171, 68207, 68209, 68213, 68219, 68227, 68239, 68261, 68279, 68281, 68311, 68329, 68351, 68371, 68389, 68399, 68437, 68443, 68447, 68449, 68473, 68477, 68483, 68489, 68491, 68501, 68507, 68521, 68531, 68539, 68543, 68567, 68581, 68597, 68611, 68633, 68639, 68659, 68669, 68683, 68687, 68699, 68711, 68713, 68729, 68737, 68743, 68749, 68767, 68771, 68777, 68791, 68813, 68819, 68821, 68863, 68879, 68881, 68891, 68897, 68899, 68903, 68909, 68917, 68927, 68947, 68963, 68993, 69001, 69011, 69019, 69029, 69031, 69061, 69067, 69073, 69109, 69119, 69127, 69143, 69149, 69151, 69163, 69191, 69193, 69197, 69203, 69221, 69233, 69239, 69247, 69257, 69259, 69263, 69313, 69317, 69337, 69341, 69371, 69379, 69383, 69389, 69401, 69403, 69427, 69431, 69439, 69457, 69463, 69467, 69473, 69481, 69491, 69493, 69497, 69499, 69539, 69557, 69593, 69623, 69653, 69661, 69677, 69691, 69697, 69709, 69737, 69739, 69761, 69763, 69767, 69779, 69809, 69821, 69827, 69829, 69833, 69847, 69857, 69859, 69877, 69899, 69911, 69929, 69931, 69941, 69959, 69991, 69997, 70001, 70003, 70009, 70019, 70039, 70051, 70061, 70067, 70079, 70099, 70111, 70117, 70121, 70123, 70139, 70141, 70157, 70163, 70177, 70181, 70183, 70199, 70201, 70207, 70223, 70229, 70237, 70241, 70249, 70271, 70289, 70297, 70309, 70313, 70321, 70327, 70351, 70373, 70379, 70381, 70393, 70423, 70429, 70439, 70451, 70457, 70459, 70481, 70487, 70489, 70501, 70507, 70529, 70537, 70549, 70571, 70573, 70583, 70589, 70607, 70619, 70621, 70627, 70639, 70657, 70663, 70667, 70687, 70709, 70717, 70729, 70753, 70769, 70783, 70793, 70823, 70841, 70843, 70849, 70853, 70867, 70877, 70879, 70891, 70901, 70913, 70919, 70921, 70937, 70949, 70951, 70957, 70969, 70979, 70981, 70991, 70997, 70999, 71011, 71023, 71039, 71059, 71069, 71081, 71089, 71119, 71129, 71143, 71147, 71153, 71161, 71167, 71171, 71191, 71209, 71233, 71237, 71249, 71257, 71261, 71263, 71287, 71293, 71317, 71327, 71329, 71333, 71339, 71341, 71347, 71353, 71359, 71363, 71387, 71389, 71399, 71411, 71413, 71419, 71429, 71437, 71443, 71453, 71471, 71473, 71479, 71483, 71503, 71527, 71537, 71549, 71551, 71563, 71569, 71593, 71597, 71633, 71647, 71663, 71671, 71693, 71699, 71707, 71711, 71713, 71719, 71741, 71761, 71777, 71789, 71807, 71809, 71821, 71837, 71843, 71849, 71861, 71867, 71879, 71881, 71887, 71899, 71909, 71917, 71933, 71941, 71947, 71963, 71971, 71983, 71987, 71993, 71999, 72019, 72031, 72043, 72047, 72053, 72073, 72077, 72089, 72091, 72101, 72103, 72109, 72139, 72161, 72167, 72169, 72173, 72211, 72221, 72223, 72227, 72229, 72251, 72253, 72269, 72271, 72277, 72287, 72307, 72313, 72337, 72341, 72353, 72367, 72379, 72383, 72421, 72431, 72461, 72467, 72469, 72481, 72493, 72497, 72503, 72533, 72547, 72551, 72559, 72577, 72613, 72617, 72623, 72643, 72647, 72649, 72661, 72671, 72673, 72679, 72689, 72701, 72707, 72719, 72727, 72733, 72739, 72763, 72767, 72797, 72817, 72823, 72859, 72869, 72871, 72883, 72889, 72893, 72901, 72907, 72911, 72923, 72931, 72937, 72949, 72953, 72959, 72973, 72977, 72997, 73009, 73013, 73019, 73037, 73039, 73043, 73061, 73063, 73079, 73091, 73121, 73127, 73133, 73141, 73181, 73189, 73237, 73243, 73259, 73277, 73291, 73303, 73309, 73327, 73331, 73351, 73361, 73363, 73369, 73379, 73387, 73417, 73421, 73433, 73453, 73459, 73471, 73477, 73483, 73517, 73523, 73529, 73547, 73553, 73561, 73571, 73583, 73589, 73597, 73607, 73609, 73613, 73637, 73643, 73651, 73673, 73679, 73681, 73693, 73699, 73709, 73721, 73727, 73751, 73757, 73771, 73783, 73819, 73823, 73847, 73849, 73859, 73867, 73877, 73883, 73897, 73907, 73939, 73943, 73951, 73961, 73973, 73999, 74017, 74021, 74027, 74047, 74051, 74071, 74077, 74093, 74099, 74101, 74131, 74143, 74149, 74159, 74161, 74167, 74177, 74189, 74197, 74201, 74203, 74209, 74219, 74231, 74257, 74279, 74287, 74293, 74297, 74311, 74317, 74323, 74353, 74357, 74363, 74377, 74381, 74383, 74411, 74413, 74419, 74441, 74449, 74453, 74471, 74489, 74507, 74509, 74521, 74527, 74531, 74551, 74561, 74567, 74573, 74587, 74597, 74609, 74611, 74623, 74653, 74687, 74699, 74707, 74713, 74717, 74719, 74729, 74731, 74747, 74759, 74761, 74771, 74779, 74797, 74821, 74827, 74831, 74843, 74857, 74861, 74869, 74873, 74887, 74891, 74897, 74903, 74923, 74929, 74933, 74941, 74959, 75011, 75013, 75017, 75029, 75037, 75041, 75079, 75083, 75109, 75133, 75149, 75161, 75167, 75169, 75181, 75193, 75209, 75211, 75217, 75223, 75227, 75239, 75253, 75269, 75277, 75289, 75307, 75323, 75329, 75337, 75347, 75353, 75367, 75377, 75389, 75391, 75401, 75403, 75407, 75431, 75437, 75479, 75503, 75511, 75521, 75527, 75533, 75539, 75541, 75553, 75557, 75571, 75577, 75583, 75611, 75617, 75619, 75629, 75641, 75653, 75659, 75679, 75683, 75689, 75703, 75707, 75709, 75721, 75731, 75743, 75767, 75773, 75781, 75787, 75793, 75797, 75821, 75833, 75853, 75869, 75883, 75913, 75931, 75937, 75941, 75967, 75979, 75983, 75989, 75991, 75997, 76001, 76003, 76031, 76039, 76079, 76081, 76091, 76099, 76103, 76123, 76129, 76147, 76157, 76159, 76163, 76207, 76213, 76231, 76243, 76249, 76253, 76259, 76261, 76283, 76289, 76303, 76333, 76343, 76367, 76369, 76379, 76387, 76403, 76421, 76423, 76441, 76463, 76471, 76481, 76487, 76493, 76507, 76511, 76519, 76537, 76541, 76543, 76561, 76579, 76597, 76603, 76607, 76631, 76649, 76651, 76667, 76673, 76679, 76697, 76717, 76733, 76753, 76757, 76771, 76777, 76781, 76801, 76819, 76829, 76831, 76837, 76847, 76871, 76873, 76883, 76907, 76913, 76919, 76943, 76949, 76961, 76963, 76991, 77003, 77017, 77023, 77029, 77041, 77047, 77069, 77081, 77093, 77101, 77137, 77141, 77153, 77167, 77171, 77191, 77201, 77213, 77237, 77239, 77243, 77249, 77261, 77263, 77267, 77269, 77279, 77291, 77317, 77323, 77339, 77347, 77351, 77359, 77369, 77377, 77383, 77417, 77419, 77431, 77447, 77471, 77477, 77479, 77489, 77491, 77509, 77513, 77521, 77527, 77543, 77549, 77551, 77557, 77563, 77569, 77573, 77587, 77591, 77611, 77617, 77621, 77641, 77647, 77659, 77681, 77687, 77689, 77699, 77711, 77713, 77719, 77723, 77731, 77743, 77747, 77761, 77773, 77783, 77797, 77801, 77813, 77839, 77849, 77863, 77867, 77893, 77899, 77929, 77933, 77951, 77969, 77977, 77983, 77999, 78007, 78017, 78031, 78041, 78049, 78059, 78079, 78101, 78121, 78137, 78139, 78157, 78163, 78167, 78173, 78179, 78191, 78193, 78203, 78229, 78233, 78241, 78259, 78277, 78283, 78301, 78307, 78311, 78317, 78341, 78347, 78367, 78401, 78427, 78437, 78439, 78467, 78479, 78487, 78497, 78509, 78511, 78517, 78539, 78541, 78553, 78569, 78571, 78577, 78583, 78593, 78607, 78623, 78643, 78649, 78653, 78691, 78697, 78707, 78713, 78721, 78737, 78779, 78781, 78787, 78791, 78797, 78803, 78809, 78823, 78839, 78853, 78857, 78877, 78887, 78889, 78893, 78901, 78919, 78929, 78941, 78977, 78979, 78989, 79031, 79039, 79043, 79063, 79087, 79103, 79111, 79133, 79139, 79147, 79151, 79153, 79159, 79181, 79187, 79193, 79201, 79229, 79231, 79241, 79259, 79273, 79279, 79283, 79301, 79309, 79319, 79333, 79337, 79349, 79357, 79367, 79379, 79393, 79397, 79399, 79411, 79423, 79427, 79433, 79451, 79481, 79493, 79531, 79537, 79549, 79559, 79561, 79579, 79589, 79601, 79609, 79613, 79621, 79627, 79631, 79633, 79657, 79669, 79687, 79691, 79693, 79697, 79699, 79757, 79769, 79777, 79801, 79811, 79813, 79817, 79823, 79829, 79841, 79843, 79847, 79861, 79867, 79873, 79889, 79901, 79903, 79907, 79939, 79943, 79967, 79973, 79979, 79987, 79997, 79999, 80021, 80039, 80051, 80071, 80077, 80107, 80111, 80141, 80147, 80149, 80153, 80167, 80173, 80177, 80191, 80207, 80209, 80221, 80231, 80233, 80239, 80251, 80263, 80273, 80279, 80287, 80309, 80317, 80329, 80341, 80347, 80363, 80369, 80387, 80407, 80429, 80447, 80449, 80471, 80473, 80489, 80491, 80513, 80527, 80537, 80557, 80567, 80599, 80603, 80611, 80621, 80627, 80629, 80651, 80657, 80669, 80671, 80677, 80681, 80683, 80687, 80701, 80713, 80737, 80747, 80749, 80761, 80777, 80779, 80783, 80789, 80803, 80809, 80819, 80831, 80833, 80849, 80863, 80897, 80909, 80911, 80917, 80923, 80929, 80933, 80953, 80963, 80989, 81001, 81013, 81017, 81019, 81023, 81031, 81041, 81043, 81047, 81049, 81071, 81077, 81083, 81097, 81101, 81119, 81131, 81157, 81163, 81173, 81181, 81197, 81199, 81203, 81223, 81233, 81239, 81281, 81283, 81293, 81299, 81307, 81331, 81343, 81349, 81353, 81359, 81371, 81373, 81401, 81409, 81421, 81439, 81457, 81463, 81509, 81517, 81527, 81533, 81547, 81551, 81553, 81559, 81563, 81569, 81611, 81619, 81629, 81637, 81647, 81649, 81667, 81671, 81677, 81689, 81701, 81703, 81707, 81727, 81737, 81749, 81761, 81769, 81773, 81799, 81817, 81839, 81847, 81853, 81869, 81883, 81899, 81901, 81919, 81929, 81931, 81937, 81943, 81953, 81967, 81971, 81973, 82003, 82007, 82009, 82013, 82021, 82031, 82037, 82039, 82051, 82067, 82073, 82129, 82139, 82141, 82153, 82163, 82171, 82183, 82189, 82193, 82207, 82217, 82219, 82223, 82231, 82237, 82241, 82261, 82267, 82279, 82301, 82307, 82339, 82349, 82351, 82361, 82373, 82387, 82393, 82421, 82457, 82463, 82469, 82471, 82483, 82487, 82493, 82499, 82507, 82529, 82531, 82549, 82559, 82561, 82567, 82571, 82591, 82601, 82609, 82613, 82619, 82633, 82651, 82657, 82699, 82721, 82723, 82727, 82729, 82757, 82759, 82763, 82781, 82787, 82793, 82799, 82811, 82813, 82837, 82847, 82883, 82889, 82891, 82903, 82913, 82939, 82963, 82981, 82997, 83003, 83009, 83023, 83047, 83059, 83063, 83071, 83077, 83089, 83093, 83101, 83117, 83137, 83177, 83203, 83207, 83219, 83221, 83227, 83231, 83233, 83243, 83257, 83267, 83269, 83273, 83299, 83311, 83339, 83341, 83357, 83383, 83389, 83399, 83401, 83407, 83417, 83423, 83431, 83437, 83443, 83449, 83459, 83471, 83477, 83497, 83537, 83557, 83561, 83563, 83579, 83591, 83597, 83609, 83617, 83621, 83639, 83641, 83653, 83663, 83689, 83701, 83717, 83719, 83737, 83761, 83773, 83777, 83791, 83813, 83833, 83843, 83857, 83869, 83873, 83891, 83903, 83911, 83921, 83933, 83939, 83969, 83983, 83987, 84011, 84017, 84047, 84053, 84059, 84061, 84067, 84089, 84121, 84127, 84131, 84137, 84143, 84163, 84179, 84181, 84191, 84199, 84211, 84221, 84223, 84229, 84239, 84247, 84263, 84299, 84307, 84313, 84317, 84319, 84347, 84349, 84377, 84389, 84391, 84401, 84407, 84421, 84431, 84437, 84443, 84449, 84457, 84463, 84467, 84481, 84499, 84503, 84509, 84521, 84523, 84533, 84551, 84559, 84589, 84629, 84631, 84649, 84653, 84659, 84673, 84691, 84697, 84701, 84713, 84719, 84731, 84737, 84751, 84761, 84787, 84793, 84809, 84811, 84827, 84857, 84859, 84869, 84871, 84913, 84919, 84947, 84961, 84967, 84977, 84979, 84991, 85009, 85021, 85027, 85037, 85049, 85061, 85081, 85087, 85091, 85093, 85103, 85109, 85121, 85133, 85147, 85159, 85193, 85199, 85201, 85213, 85223, 85229, 85237, 85243, 85247, 85259, 85297, 85303, 85313, 85331, 85333, 85361, 85363, 85369, 85381, 85411, 85427, 85429, 85439, 85447, 85451, 85453, 85469, 85487, 85513, 85517, 85523, 85531, 85549, 85571, 85577, 85597, 85601, 85607, 85619, 85621, 85627, 85639, 85643, 85661, 85667, 85669, 85691, 85703, 85711, 85717, 85733, 85751, 85781, 85793, 85817, 85819, 85829, 85831, 85837, 85843, 85847, 85853, 85889, 85903, 85909, 85931, 85933, 85991, 85999, 86011, 86017, 86027, 86029, 86069, 86077, 86083, 86111, 86113, 86117, 86131, 86137, 86143, 86161, 86171, 86179, 86183, 86197, 86201, 86209, 86239, 86243, 86249, 86257, 86263, 86269, 86287, 86291, 86293, 86297, 86311, 86323, 86341, 86351, 86353, 86357, 86369, 86371, 86381, 86389, 86399, 86413, 86423, 86441, 86453, 86461, 86467, 86477, 86491, 86501, 86509, 86531, 86533, 86539, 86561, 86573, 86579, 86587, 86599, 86627, 86629, 86677, 86689, 86693, 86711, 86719, 86729, 86743, 86753, 86767, 86771, 86783, 86813, 86837, 86843, 86851, 86857, 86861, 86869, 86923, 86927, 86929, 86939, 86951, 86959, 86969, 86981, 86993, 87011, 87013, 87037, 87041, 87049, 87071, 87083, 87103, 87107, 87119, 87121, 87133, 87149, 87151, 87179, 87181, 87187, 87211, 87221, 87223, 87251, 87253, 87257, 87277, 87281, 87293, 87299, 87313, 87317, 87323, 87337, 87359, 87383, 87403, 87407, 87421, 87427, 87433, 87443, 87473, 87481, 87491, 87509, 87511, 87517, 87523, 87539, 87541, 87547, 87553, 87557, 87559, 87583, 87587, 87589, 87613, 87623, 87629, 87631, 87641, 87643, 87649, 87671, 87679, 87683, 87691, 87697, 87701, 87719, 87721, 87739, 87743, 87751, 87767, 87793, 87797, 87803, 87811, 87833, 87853, 87869, 87877, 87881, 87887, 87911, 87917, 87931, 87943, 87959, 87961, 87973, 87977, 87991, 88001, 88003, 88007, 88019, 88037, 88069, 88079, 88093, 88117, 88129, 88169, 88177, 88211, 88223, 88237, 88241, 88259, 88261, 88289, 88301, 88321, 88327, 88337, 88339, 88379, 88397, 88411, 88423, 88427, 88463, 88469, 88471, 88493, 88499, 88513, 88523, 88547, 88589, 88591, 88607, 88609, 88643, 88651, 88657, 88661, 88663, 88667, 88681, 88721, 88729, 88741, 88747, 88771, 88789, 88793, 88799, 88801, 88807, 88811, 88813, 88817, 88819, 88843, 88853, 88861, 88867, 88873, 88883, 88897, 88903, 88919, 88937, 88951, 88969, 88993, 88997, 89003, 89009, 89017, 89021, 89041, 89051, 89057, 89069, 89071, 89083, 89087, 89101, 89107, 89113, 89119, 89123, 89137, 89153, 89189, 89203, 89209, 89213, 89227, 89231, 89237, 89261, 89269, 89273, 89293, 89303, 89317, 89329, 89363, 89371, 89381, 89387, 89393, 89399, 89413, 89417, 89431, 89443, 89449, 89459, 89477, 89491, 89501, 89513, 89519, 89521, 89527, 89533, 89561, 89563, 89567, 89591, 89597, 89599, 89603, 89611, 89627, 89633, 89653, 89657, 89659, 89669, 89671, 89681, 89689, 89753, 89759, 89767, 89779, 89783, 89797, 89809, 89819, 89821, 89833, 89839, 89849, 89867, 89891, 89897, 89899, 89909, 89917, 89923, 89939, 89959, 89963, 89977, 89983, 89989, 90001, 90007, 90011, 90017, 90019, 90023, 90031, 90053, 90059, 90067, 90071, 90073, 90089, 90107, 90121, 90127, 90149, 90163, 90173, 90187, 90191, 90197, 90199, 90203, 90217, 90227, 90239, 90247, 90263, 90271, 90281, 90289, 90313, 90353, 90359, 90371, 90373, 90379, 90397, 90401, 90403, 90407, 90437, 90439, 90469, 90473, 90481, 90499, 90511, 90523, 90527, 90529, 90533, 90547, 90583, 90599, 90617, 90619, 90631, 90641, 90647, 90659, 90677, 90679, 90697, 90703, 90709, 90731, 90749, 90787, 90793, 90803, 90821, 90823, 90833, 90841, 90847, 90863, 90887, 90901, 90907, 90911, 90917, 90931, 90947, 90971, 90977, 90989, 90997, 91009, 91019, 91033, 91079, 91081, 91097, 91099, 91121, 91127, 91129, 91139, 91141, 91151, 91153, 91159, 91163, 91183, 91193, 91199, 91229, 91237, 91243, 91249, 91253, 91283, 91291, 91297, 91303, 91309, 91331, 91367, 91369, 91373, 91381, 91387, 91393, 91397, 91411, 91423, 91433, 91453, 91457, 91459, 91463, 91493, 91499, 91513, 91529, 91541, 91571, 91573, 91577, 91583, 91591, 91621, 91631, 91639, 91673, 91691, 91703, 91711, 91733, 91753, 91757, 91771, 91781, 91801, 91807, 91811, 91813, 91823, 91837, 91841, 91867, 91873, 91909, 91921, 91939, 91943, 91951, 91957, 91961, 91967, 91969, 91997, 92003, 92009, 92033, 92041, 92051, 92077, 92083, 92107, 92111, 92119, 92143, 92153, 92173, 92177, 92179, 92189, 92203, 92219, 92221, 92227, 92233, 92237, 92243, 92251, 92269, 92297, 92311, 92317, 92333, 92347, 92353, 92357, 92363, 92369, 92377, 92381, 92383, 92387, 92399, 92401, 92413, 92419, 92431, 92459, 92461, 92467, 92479, 92489, 92503, 92507, 92551, 92557, 92567, 92569, 92581, 92593, 92623, 92627, 92639, 92641, 92647, 92657, 92669, 92671, 92681, 92683, 92693, 92699, 92707, 92717, 92723, 92737, 92753, 92761, 92767, 92779, 92789, 92791, 92801, 92809, 92821, 92831, 92849, 92857, 92861, 92863, 92867, 92893, 92899, 92921, 92927, 92941, 92951, 92957, 92959, 92987, 92993, 93001, 93047, 93053, 93059, 93077, 93083, 93089, 93097, 93103, 93113, 93131, 93133, 93139, 93151, 93169, 93179, 93187, 93199, 93229, 93239, 93241, 93251, 93253, 93257, 93263, 93281, 93283, 93287, 93307, 93319, 93323, 93329, 93337, 93371, 93377, 93383, 93407, 93419, 93427, 93463, 93479, 93481, 93487, 93491, 93493, 93497, 93503, 93523, 93529, 93553, 93557, 93559, 93563, 93581, 93601, 93607, 93629, 93637, 93683, 93701, 93703, 93719, 93739, 93761, 93763, 93787, 93809, 93811, 93827, 93851, 93871, 93887, 93889, 93893, 93901, 93911, 93913, 93923, 93937, 93941, 93949, 93967, 93971, 93979, 93983, 93997, 94007, 94009, 94033, 94049, 94057, 94063, 94079, 94099, 94109, 94111, 94117, 94121, 94151, 94153, 94169, 94201, 94207, 94219, 94229, 94253, 94261, 94273, 94291, 94307, 94309, 94321, 94327, 94331, 94343, 94349, 94351, 94379, 94397, 94399, 94421, 94427, 94433, 94439, 94441, 94447, 94463, 94477, 94483, 94513, 94529, 94531, 94541, 94543, 94547, 94559, 94561, 94573, 94583, 94597, 94603, 94613, 94621, 94649, 94651, 94687, 94693, 94709, 94723, 94727, 94747, 94771, 94777, 94781, 94789, 94793, 94811, 94819, 94823, 94837, 94841, 94847, 94849, 94873, 94889, 94903, 94907, 94933, 94949, 94951, 94961, 94993, 94999, 95003, 95009, 95021, 95027, 95063, 95071, 95083, 95087, 95089, 95093, 95101, 95107, 95111, 95131, 95143, 95153, 95177, 95189, 95191, 95203, 95213, 95219, 95231, 95233, 95239, 95257, 95261, 95267, 95273, 95279, 95287, 95311, 95317, 95327, 95339, 95369, 95383, 95393, 95401, 95413, 95419, 95429, 95441, 95443, 95461, 95467, 95471, 95479, 95483, 95507, 95527, 95531, 95539, 95549, 95561, 95569, 95581, 95597, 95603, 95617, 95621, 95629, 95633, 95651, 95701, 95707, 95713, 95717, 95723, 95731, 95737, 95747, 95773, 95783, 95789, 95791, 95801, 95803, 95813, 95819, 95857, 95869, 95873, 95881, 95891, 95911, 95917, 95923, 95929, 95947, 95957, 95959, 95971, 95987, 95989, 96001, 96013, 96017, 96043, 96053, 96059, 96079, 96097, 96137, 96149, 96157, 96167, 96179, 96181, 96199, 96211, 96221, 96223, 96233, 96259, 96263, 96269, 96281, 96289, 96293, 96323, 96329, 96331, 96337, 96353, 96377, 96401, 96419, 96431, 96443, 96451, 96457, 96461, 96469, 96479, 96487, 96493, 96497, 96517, 96527, 96553, 96557, 96581, 96587, 96589, 96601, 96643, 96661, 96667, 96671, 96697, 96703, 96731, 96737, 96739, 96749, 96757, 96763, 96769, 96779, 96787, 96797, 96799, 96821, 96823, 96827, 96847, 96851, 96857, 96893, 96907, 96911, 96931, 96953, 96959, 96973, 96979, 96989, 96997, 97001, 97003, 97007, 97021, 97039, 97073, 97081, 97103, 97117, 97127, 97151, 97157, 97159, 97169, 97171, 97177, 97187, 97213, 97231, 97241, 97259, 97283, 97301, 97303, 97327, 97367, 97369, 97373, 97379, 97381, 97387, 97397, 97423, 97429, 97441, 97453, 97459, 97463, 97499, 97501, 97511, 97523, 97547, 97549, 97553, 97561, 97571, 97577, 97579, 97583, 97607, 97609, 97613, 97649, 97651, 97673, 97687, 97711, 97729, 97771, 97777, 97787, 97789, 97813, 97829, 97841, 97843, 97847, 97849, 97859, 97861, 97871, 97879, 97883, 97919, 97927, 97931, 97943, 97961, 97967, 97973, 97987, 98009, 98011, 98017, 98041, 98047, 98057, 98081, 98101, 98123, 98129, 98143, 98179, 98207, 98213, 98221, 98227, 98251, 98257, 98269, 98297, 98299, 98317, 98321, 98323, 98327, 98347, 98369, 98377, 98387, 98389, 98407, 98411, 98419, 98429, 98443, 98453, 98459, 98467, 98473, 98479, 98491, 98507, 98519, 98533, 98543, 98561, 98563, 98573, 98597, 98621, 98627, 98639, 98641, 98663, 98669, 98689, 98711, 98713, 98717, 98729, 98731, 98737, 98773, 98779, 98801, 98807, 98809, 98837, 98849, 98867, 98869, 98873, 98887, 98893, 98897, 98899, 98909, 98911, 98927, 98929, 98939, 98947, 98953, 98963, 98981, 98993, 98999, 99013, 99017, 99023, 99041, 99053, 99079, 99083, 99089, 99103, 99109, 99119, 99131, 99133, 99137, 99139, 99149, 99173, 99181, 99191, 99223, 99233, 99241, 99251, 99257, 99259, 99277, 99289, 99317, 99347, 99349, 99367, 99371, 99377, 99391, 99397, 99401, 99409, 99431, 99439, 99469, 99487, 99497, 99523, 99527, 99529, 99551, 99559, 99563, 99571, 99577, 99581, 99607, 99611, 99623, 99643, 99661, 99667, 99679, 99689, 99707, 99709, 99713, 99719, 99721, 99733, 99761, 99767, 99787, 99793, 99809, 99817, 99823, 99829, 99833, 99839, 99859, 99871, 99877, 99881, 99901, 99907, 99923, 99929, 99961, 99971, 99989, 99991, 100003, 100019, 100043, 100049, 100057, 100069, 100103, 100109, 100129, 100151, 100153, 100169, 100183, 100189, 100193, 100207, 100213, 100237, 100267, 100271, 100279, 100291, 100297, 100313, 100333, 100343, 100357, 100361, 100363, 100379, 100391, 100393, 100403, 100411, 100417, 100447, 100459, 100469, 100483, 100493, 100501, 100511, 100517, 100519, 100523, 100537, 100547, 100549, 100559, 100591, 100609, 100613, 100621, 100649, 100669, 100673, 100693, 100699, 100703, 100733, 100741, 100747, 100769, 100787, 100799, 100801, 100811, 100823, 100829, 100847, 100853, 100907, 100913, 100927, 100931, 100937, 100943, 100957, 100981, 100987, 100999, 101009, 101021, 101027, 101051, 101063, 101081, 101089, 101107, 101111, 101113, 101117, 101119, 101141, 101149, 101159, 101161, 101173, 101183, 101197, 101203, 101207, 101209, 101221, 101267, 101273, 101279, 101281, 101287, 101293, 101323, 101333, 101341, 101347, 101359, 101363, 101377, 101383, 101399, 101411, 101419, 101429, 101449, 101467, 101477, 101483, 101489, 101501, 101503, 101513, 101527, 101531, 101533, 101537, 101561, 101573, 101581, 101599, 101603, 101611, 101627, 101641, 101653, 101663, 101681, 101693, 101701, 101719, 101723, 101737, 101741, 101747, 101749, 101771, 101789, 101797, 101807, 101833, 101837, 101839, 101863, 101869, 101873, 101879, 101891, 101917, 101921, 101929, 101939, 101957, 101963, 101977, 101987, 101999, 102001, 102013, 102019, 102023, 102031, 102043, 102059, 102061, 102071, 102077, 102079, 102101, 102103, 102107, 102121, 102139, 102149, 102161, 102181, 102191, 102197, 102199, 102203, 102217, 102229, 102233, 102241, 102251, 102253, 102259, 102293, 102299, 102301, 102317, 102329, 102337, 102359, 102367, 102397, 102407, 102409, 102433, 102437, 102451, 102461, 102481, 102497, 102499, 102503, 102523, 102533, 102539, 102547, 102551, 102559, 102563, 102587, 102593, 102607, 102611, 102643, 102647, 102653, 102667, 102673, 102677, 102679, 102701, 102761, 102763, 102769, 102793, 102797, 102811, 102829, 102841, 102859, 102871, 102877, 102881, 102911, 102913, 102929, 102931, 102953, 102967, 102983, 103001, 103007, 103043, 103049, 103067, 103069, 103079, 103087, 103091, 103093, 103099, 103123, 103141, 103171, 103177, 103183, 103217, 103231, 103237, 103289, 103291, 103307, 103319, 103333, 103349, 103357, 103387, 103391, 103393, 103399, 103409, 103421, 103423, 103451, 103457, 103471, 103483, 103511, 103529, 103549, 103553, 103561, 103567, 103573, 103577, 103583, 103591, 103613, 103619, 103643, 103651, 103657, 103669, 103681, 103687, 103699, 103703, 103723, 103769, 103787, 103801, 103811, 103813, 103837, 103841, 103843, 103867, 103889, 103903, 103913, 103919, 103951, 103963, 103967, 103969, 103979, 103981, 103991, 103993, 103997, 104003, 104009, 104021, 104033, 104047, 104053, 104059, 104087, 104089, 104107, 104113, 104119, 104123, 104147, 104149, 104161, 104173, 104179, 104183, 104207, 104231, 104233, 104239, 104243, 104281, 104287, 104297, 104309, 104311, 104323, 104327, 104347, 104369, 104381, 104383, 104393, 104399, 104417, 104459, 104471, 104473, 104479, 104491, 104513, 104527, 104537, 104543, 104549, 104551, 104561, 104579, 104593, 104597, 104623, 104639, 104651, 104659, 104677, 104681, 104683, 104693, 104701, 104707, 104711, 104717, 104723, 104729, 104743, 104759, 104761, 104773, 104779, 104789, 104801, 104803, 104827, 104831, 104849, 104851, 104869, 104879, 104891, 104911, 104917, 104933, 104947, 104953, 104959, 104971, 104987, 104999, 105019, 105023, 105031, 105037, 105071, 105097, 105107, 105137, 105143, 105167, 105173, 105199, 105211, 105227, 105229, 105239, 105251, 105253, 105263, 105269, 105277, 105319, 105323, 105331, 105337, 105341, 105359, 105361, 105367, 105373, 105379, 105389, 105397, 105401, 105407, 105437, 105449, 105467, 105491, 105499, 105503, 105509, 105517, 105527, 105529, 105533, 105541, 105557, 105563, 105601, 105607, 105613, 105619, 105649, 105653, 105667, 105673, 105683, 105691, 105701, 105727, 105733, 105751, 105761, 105767, 105769, 105817, 105829, 105863, 105871, 105883, 105899, 105907, 105913, 105929, 105943, 105953, 105967, 105971, 105977, 105983, 105997, 106013, 106019, 106031, 106033, 106087, 106103, 106109, 106121, 106123, 106129, 106163, 106181, 106187, 106189, 106207, 106213, 106217, 106219, 106243, 106261, 106273, 106277, 106279, 106291, 106297, 106303, 106307, 106319, 106321, 106331, 106349, 106357, 106363, 106367, 106373, 106391, 106397, 106411, 106417, 106427, 106433, 106441, 106451, 106453, 106487, 106501, 106531, 106537, 106541, 106543, 106591, 106619, 106621, 106627, 106637, 106649, 106657, 106661, 106663, 106669, 106681, 106693, 106699, 106703, 106721, 106727, 106739, 106747, 106751, 106753, 106759, 106781, 106783, 106787, 106801, 106823, 106853, 106859, 106861, 106867, 106871, 106877, 106903, 106907, 106921, 106937, 106949, 106957, 106961, 106963, 106979, 106993, 107021, 107033, 107053, 107057, 107069, 107071, 107077, 107089, 107099, 107101, 107119, 107123, 107137, 107171, 107183, 107197, 107201, 107209, 107227, 107243, 107251, 107269, 107273, 107279, 107309, 107323, 107339, 107347, 107351, 107357, 107377, 107441, 107449, 107453, 107467, 107473, 107507, 107509, 107563, 107581, 107599, 107603, 107609, 107621, 107641, 107647, 107671, 107687, 107693, 107699, 107713, 107717, 107719, 107741, 107747, 107761, 107773, 107777, 107791, 107827, 107837, 107839, 107843, 107857, 107867, 107873, 107881, 107897, 107903, 107923, 107927, 107941, 107951, 107971, 107981, 107999, 108007, 108011, 108013, 108023, 108037, 108041, 108061, 108079, 108089, 108107, 108109, 108127, 108131, 108139, 108161, 108179, 108187, 108191, 108193, 108203, 108211, 108217, 108223, 108233, 108247, 108263, 108271, 108287, 108289, 108293, 108301, 108343, 108347, 108359, 108377, 108379, 108401, 108413, 108421, 108439, 108457, 108461, 108463, 108497, 108499, 108503, 108517, 108529, 108533, 108541, 108553, 108557, 108571, 108587, 108631, 108637, 108643, 108649, 108677, 108707, 108709, 108727, 108739, 108751, 108761, 108769, 108791, 108793, 108799, 108803, 108821, 108827, 108863, 108869, 108877, 108881, 108883, 108887, 108893, 108907, 108917, 108923, 108929, 108943, 108947, 108949, 108959, 108961, 108967, 108971, 108991, 109001, 109013, 109037, 109049, 109063, 109073, 109097, 109103, 109111, 109121, 109133, 109139, 109141, 109147, 109159, 109169, 109171, 109199, 109201, 109211, 109229, 109253, 109267, 109279, 109297, 109303, 109313, 109321, 109331, 109357, 109363, 109367, 109379, 109387, 109391, 109397, 109423, 109433, 109441, 109451, 109453, 109469, 109471, 109481, 109507, 109517, 109519, 109537, 109541, 109547, 109567, 109579, 109583, 109589, 109597, 109609, 109619, 109621, 109639, 109661, 109663, 109673, 109717, 109721, 109741, 109751, 109789, 109793, 109807, 109819, 109829, 109831, 109841, 109843, 109847, 109849, 109859, 109873, 109883, 109891, 109897, 109903, 109913, 109919, 109937, 109943, 109961, 109987, 110017, 110023, 110039, 110051, 110059, 110063, 110069, 110083, 110119, 110129, 110161, 110183, 110221, 110233, 110237, 110251, 110261, 110269, 110273, 110281, 110291, 110311, 110321, 110323, 110339, 110359, 110419, 110431, 110437, 110441, 110459, 110477, 110479, 110491, 110501, 110503, 110527, 110533, 110543, 110557, 110563, 110567, 110569, 110573, 110581, 110587, 110597, 110603, 110609, 110623, 110629, 110641, 110647, 110651, 110681, 110711, 110729, 110731, 110749, 110753, 110771, 110777, 110807, 110813, 110819, 110821, 110849, 110863, 110879, 110881, 110899, 110909, 110917, 110921, 110923, 110927, 110933, 110939, 110947, 110951, 110969, 110977, 110989, 111029, 111031, 111043, 111049, 111053, 111091, 111103, 111109, 111119, 111121, 111127, 111143, 111149, 111187, 111191, 111211, 111217, 111227, 111229, 111253, 111263, 111269, 111271, 111301, 111317, 111323, 111337, 111341, 111347, 111373, 111409, 111427, 111431, 111439, 111443, 111467, 111487, 111491, 111493, 111497, 111509, 111521, 111533, 111539, 111577, 111581, 111593, 111599, 111611, 111623, 111637, 111641, 111653, 111659, 111667, 111697, 111721, 111731, 111733, 111751, 111767, 111773, 111779, 111781, 111791, 111799, 111821, 111827, 111829, 111833, 111847, 111857, 111863, 111869, 111871, 111893, 111913, 111919, 111949, 111953, 111959, 111973, 111977, 111997, 112019, 112031, 112061, 112067, 112069, 112087, 112097, 112103, 112111, 112121, 112129, 112139, 112153, 112163, 112181, 112199, 112207, 112213, 112223, 112237, 112241, 112247, 112249, 112253, 112261, 112279, 112289, 112291, 112297, 112303, 112327, 112331, 112337, 112339, 112349, 112361, 112363, 112397, 112403, 112429, 112459, 112481, 112501, 112507, 112543, 112559, 112571, 112573, 112577, 112583, 112589, 112601, 112603, 112621, 112643, 112657, 112663, 112687, 112691, 112741, 112757, 112759, 112771, 112787, 112799, 112807, 112831, 112843, 112859, 112877, 112901, 112909, 112913, 112919, 112921, 112927, 112939, 112951, 112967, 112979, 112997, 113011, 113017, 113021, 113023, 113027, 113039, 113041, 113051, 113063, 113081, 113083, 113089, 113093, 113111, 113117, 113123, 113131, 113143, 113147, 113149, 113153, 113159, 113161, 113167, 113171, 113173, 113177, 113189, 113209, 113213, 113227, 113233, 113279, 113287, 113327, 113329, 113341, 113357, 113359, 113363, 113371, 113381, 113383, 113417, 113437, 113453, 113467, 113489, 113497, 113501, 113513, 113537, 113539, 113557, 113567, 113591, 113621, 113623, 113647, 113657, 113683, 113717, 113719, 113723, 113731, 113749, 113759, 113761, 113777, 113779, 113783, 113797, 113809, 113819, 113837, 113843, 113891, 113899, 113903, 113909, 113921, 113933, 113947, 113957, 113963, 113969, 113983, 113989, 114001, 114013, 114031, 114041, 114043, 114067, 114073, 114077, 114083, 114089, 114113, 114143, 114157, 114161, 114167, 114193, 114197, 114199, 114203, 114217, 114221, 114229, 114259, 114269, 114277, 114281, 114299, 114311, 114319, 114329, 114343, 114371, 114377, 114407, 114419, 114451, 114467, 114473, 114479, 114487, 114493, 114547, 114553, 114571, 114577, 114593, 114599, 114601, 114613, 114617, 114641, 114643, 114649, 114659, 114661, 114671, 114679, 114689, 114691, 114713, 114743, 114749, 114757, 114761, 114769, 114773, 114781, 114797, 114799, 114809, 114827, 114833, 114847, 114859, 114883, 114889, 114901, 114913, 114941, 114967, 114973, 114997, 115001, 115013, 115019, 115021, 115057, 115061, 115067, 115079, 115099, 115117, 115123, 115127, 115133, 115151, 115153, 115163, 115183, 115201, 115211, 115223, 115237, 115249, 115259, 115279, 115301, 115303, 115309, 115319, 115321, 115327, 115331, 115337, 115343, 115361, 115363, 115399, 115421, 115429, 115459, 115469, 115471, 115499, 115513, 115523, 115547, 115553, 115561, 115571, 115589, 115597, 115601, 115603, 115613, 115631, 115637, 115657, 115663, 115679, 115693, 115727, 115733, 115741, 115751, 115757, 115763, 115769, 115771, 115777, 115781, 115783, 115793, 115807, 115811, 115823, 115831, 115837, 115849, 115853, 115859, 115861, 115873, 115877, 115879, 115883, 115891, 115901, 115903, 115931, 115933, 115963, 115979, 115981, 115987, 116009, 116027, 116041, 116047, 116089, 116099, 116101, 116107, 116113, 116131, 116141, 116159, 116167, 116177, 116189, 116191, 116201, 116239, 116243, 116257, 116269, 116273, 116279, 116293, 116329, 116341, 116351, 116359, 116371, 116381, 116387, 116411, 116423, 116437, 116443, 116447, 116461, 116471, 116483, 116491, 116507, 116531, 116533, 116537, 116539, 116549, 116579, 116593, 116639, 116657, 116663, 116681, 116687, 116689, 116707, 116719, 116731, 116741, 116747, 116789, 116791, 116797, 116803, 116819, 116827, 116833, 116849, 116867, 116881, 116903, 116911, 116923, 116927, 116929, 116933, 116953, 116959, 116969, 116981, 116989, 116993, 117017, 117023, 117037, 117041, 117043, 117053, 117071, 117101, 117109, 117119, 117127, 117133, 117163, 117167, 117191, 117193, 117203, 117209, 117223, 117239, 117241, 117251, 117259, 117269, 117281, 117307, 117319, 117329, 117331, 117353, 117361, 117371, 117373, 117389, 117413, 117427, 117431, 117437, 117443, 117497, 117499, 117503, 117511, 117517, 117529, 117539, 117541, 117563, 117571, 117577, 117617, 117619, 117643, 117659, 117671, 117673, 117679, 117701, 117703, 117709, 117721, 117727, 117731, 117751, 117757, 117763, 117773, 117779, 117787, 117797, 117809, 117811, 117833, 117839, 117841, 117851, 117877, 117881, 117883, 117889, 117899, 117911, 117917, 117937, 117959, 117973, 117977, 117979, 117989, 117991, 118033, 118037, 118043, 118051, 118057, 118061, 118081, 118093, 118127, 118147, 118163, 118169, 118171, 118189, 118211, 118213, 118219, 118247, 118249, 118253, 118259, 118273, 118277, 118297, 118343, 118361, 118369, 118373, 118387, 118399, 118409, 118411, 118423, 118429, 118453, 118457, 118463, 118471, 118493, 118529, 118543, 118549, 118571, 118583, 118589, 118603, 118619, 118621, 118633, 118661, 118669, 118673, 118681, 118687, 118691, 118709, 118717, 118739, 118747, 118751, 118757, 118787, 118799, 118801, 118819, 118831, 118843, 118861, 118873, 118891, 118897, 118901, 118903, 118907, 118913, 118927, 118931, 118967, 118973, 119027, 119033, 119039, 119047, 119057, 119069, 119083, 119087, 119089, 119099, 119101, 119107, 119129, 119131, 119159, 119173, 119179, 119183, 119191, 119227, 119233, 119237, 119243, 119267, 119291, 119293, 119297, 119299, 119311, 119321, 119359, 119363, 119389, 119417, 119419, 119429, 119447, 119489, 119503, 119513, 119533, 119549, 119551, 119557, 119563, 119569, 119591, 119611, 119617, 119627, 119633, 119653, 119657, 119659, 119671, 119677, 119687, 119689, 119699, 119701, 119723, 119737, 119747, 119759, 119771, 119773, 119783, 119797, 119809, 119813, 119827, 119831, 119839, 119849, 119851, 119869, 119881, 119891, 119921, 119923, 119929, 119953, 119963, 119971, 119981, 119983, 119993, 120011, 120017, 120041, 120047, 120049, 120067, 120077, 120079, 120091, 120097, 120103, 120121, 120157, 120163, 120167, 120181, 120193, 120199, 120209, 120223, 120233, 120247, 120277, 120283, 120293, 120299, 120319, 120331, 120349, 120371, 120383, 120391, 120397, 120401, 120413, 120427, 120431, 120473, 120503, 120511, 120539, 120551, 120557, 120563, 120569, 120577, 120587, 120607, 120619, 120623, 120641, 120647, 120661, 120671, 120677, 120689, 120691, 120709, 120713, 120721, 120737, 120739, 120749, 120763, 120767, 120779, 120811, 120817, 120823, 120829, 120833, 120847, 120851, 120863, 120871, 120877, 120889, 120899, 120907, 120917, 120919, 120929, 120937, 120941, 120943, 120947, 120977, 120997, 121001, 121007, 121013, 121019, 121021, 121039, 121061, 121063, 121067, 121081, 121123, 121139, 121151, 121157, 121169, 121171, 121181, 121189, 121229, 121259, 121267, 121271, 121283, 121291, 121309, 121313, 121321, 121327, 121333, 121343, 121349, 121351, 121357, 121367, 121369, 121379, 121403, 121421, 121439, 121441, 121447, 121453, 121469, 121487, 121493, 121501, 121507, 121523, 121531, 121547, 121553, 121559, 121571, 121577, 121579, 121591, 121607, 121609, 121621, 121631, 121633, 121637, 121661, 121687, 121697, 121711, 121721, 121727, 121763, 121787, 121789, 121843, 121853, 121867, 121883, 121889, 121909, 121921, 121931, 121937, 121949, 121951, 121963, 121967, 121993, 121997, 122011, 122021, 122027, 122029, 122033, 122039, 122041, 122051, 122053, 122069, 122081, 122099, 122117, 122131, 122147, 122149, 122167, 122173, 122201, 122203, 122207, 122209, 122219, 122231, 122251, 122263, 122267, 122273, 122279, 122299, 122321, 122323, 122327, 122347, 122363, 122387, 122389, 122393, 122399, 122401, 122443, 122449, 122453, 122471, 122477, 122489, 122497, 122501, 122503, 122509, 122527, 122533, 122557, 122561, 122579, 122597, 122599, 122609, 122611, 122651, 122653, 122663, 122693, 122701, 122719, 122741, 122743, 122753, 122761, 122777, 122789, 122819, 122827, 122833, 122839, 122849, 122861, 122867, 122869, 122887, 122891, 122921, 122929, 122939, 122953, 122957, 122963, 122971, 123001, 123007, 123017, 123031, 123049, 123059, 123077, 123083, 123091, 123113, 123121, 123127, 123143, 123169, 123191, 123203, 123209, 123217, 123229, 123239, 123259, 123269, 123289, 123307, 123311, 123323, 123341, 123373, 123377, 123379, 123397, 123401, 123407, 123419, 123427, 123433, 123439, 123449, 123457, 123479, 123491, 123493, 123499, 123503, 123517, 123527, 123547, 123551, 123553, 123581, 123583, 123593, 123601, 123619, 123631, 123637, 123653, 123661, 123667, 123677, 123701, 123707, 123719, 123727, 123731, 123733, 123737, 123757, 123787, 123791, 123803, 123817, 123821, 123829, 123833, 123853, 123863, 123887, 123911, 123923, 123931, 123941, 123953, 123973, 123979, 123983, 123989, 123997, 124001, 124021, 124067, 124087, 124097, 124121, 124123, 124133, 124139, 124147, 124153, 124171, 124181, 124183, 124193, 124199, 124213, 124231, 124247, 124249, 124277, 124291, 124297, 124301, 124303, 124309, 124337, 124339, 124343, 124349, 124351, 124363, 124367, 124427, 124429, 124433, 124447, 124459, 124471, 124477, 124489, 124493, 124513, 124529, 124541, 124543, 124561, 124567, 124577, 124601, 124633, 124643, 124669, 124673, 124679, 124693, 124699, 124703, 124717, 124721, 124739, 124753, 124759, 124769, 124771, 124777, 124781, 124783, 124793, 124799, 124819, 124823, 124847, 124853, 124897, 124907, 124909, 124919, 124951, 124979, 124981, 124987, 124991, 125003, 125017, 125029, 125053, 125063, 125093, 125101, 125107, 125113, 125117, 125119, 125131, 125141, 125149, 125183, 125197, 125201, 125207, 125219, 125221, 125231, 125243, 125261, 125269, 125287, 125299, 125303, 125311, 125329, 125339, 125353, 125371, 125383, 125387, 125399, 125407, 125423, 125429, 125441, 125453, 125471, 125497, 125507, 125509, 125527, 125539, 125551, 125591, 125597, 125617, 125621, 125627, 125639, 125641, 125651, 125659, 125669, 125683, 125687, 125693, 125707, 125711, 125717, 125731, 125737, 125743, 125753, 125777, 125789, 125791, 125803, 125813, 125821, 125863, 125887, 125897, 125899, 125921, 125927, 125929, 125933, 125941, 125959, 125963, 126001, 126011, 126013, 126019, 126023, 126031, 126037, 126041, 126047, 126067, 126079, 126097, 126107, 126127, 126131, 126143, 126151, 126173, 126199, 126211, 126223, 126227, 126229, 126233, 126241, 126257, 126271, 126307, 126311, 126317, 126323, 126337, 126341, 126349, 126359, 126397, 126421, 126433, 126443, 126457, 126461, 126473, 126481, 126487, 126491, 126493, 126499, 126517, 126541, 126547, 126551, 126583, 126601, 126611, 126613, 126631, 126641, 126653, 126683, 126691, 126703, 126713, 126719, 126733, 126739, 126743, 126751, 126757, 126761, 126781, 126823, 126827, 126839, 126851, 126857, 126859, 126913, 126923, 126943, 126949, 126961, 126967, 126989, 127031, 127033, 127037, 127051, 127079, 127081, 127103, 127123, 127133, 127139, 127157, 127163, 127189, 127207, 127217, 127219, 127241, 127247, 127249, 127261, 127271, 127277, 127289, 127291, 127297, 127301, 127321, 127331, 127343, 127363, 127373, 127399, 127403, 127423, 127447, 127453, 127481, 127487, 127493, 127507, 127529, 127541, 127549, 127579, 127583, 127591, 127597, 127601, 127607, 127609, 127637, 127643, 127649, 127657, 127663, 127669, 127679, 127681, 127691, 127703, 127709, 127711, 127717, 127727, 127733, 127739, 127747, 127763, 127781, 127807, 127817, 127819, 127837, 127843, 127849, 127859, 127867, 127873, 127877, 127913, 127921, 127931, 127951, 127973, 127979, 127997, 128021, 128033, 128047, 128053, 128099, 128111, 128113, 128119, 128147, 128153, 128159, 128173, 128189, 128201, 128203, 128213, 128221, 128237, 128239, 128257, 128273, 128287, 128291, 128311, 128321, 128327, 128339, 128341, 128347, 128351, 128377, 128389, 128393, 128399, 128411, 128413, 128431, 128437, 128449, 128461, 128467, 128473, 128477, 128483, 128489, 128509, 128519, 128521, 128549, 128551, 128563, 128591, 128599, 128603, 128621, 128629, 128657, 128659, 128663, 128669, 128677, 128683, 128693, 128717, 128747, 128749, 128761, 128767, 128813, 128819, 128831, 128833, 128837, 128857, 128861, 128873, 128879, 128903, 128923, 128939, 128941, 128951, 128959, 128969, 128971, 128981, 128983, 128987, 128993, 129001, 129011, 129023, 129037, 129049, 129061, 129083, 129089, 129097, 129113, 129119, 129121, 129127, 129169, 129187, 129193, 129197, 129209, 129221, 129223, 129229, 129263, 129277, 129281, 129287, 129289, 129293, 129313, 129341, 129347, 129361, 129379, 129401, 129403, 129419, 129439, 129443, 129449, 129457, 129461, 129469, 129491, 129497, 129499, 129509, 129517, 129527, 129529, 129533, 129539, 129553, 129581, 129587, 129589, 129593, 129607, 129629, 129631, 129641, 129643, 129671, 129707, 129719, 129733, 129737, 129749, 129757, 129763, 129769, 129793, 129803, 129841, 129853, 129887, 129893, 129901, 129917, 129919, 129937, 129953, 129959, 129967, 129971, 130003, 130021, 130027, 130043, 130051, 130057, 130069, 130073, 130079, 130087, 130099, 130121, 130127, 130147, 130171, 130183, 130199, 130201, 130211, 130223, 130241, 130253, 130259, 130261, 130267, 130279, 130303, 130307, 130337, 130343, 130349, 130363, 130367, 130369, 130379, 130399, 130409, 130411, 130423, 130439, 130447, 130457, 130469, 130477, 130483, 130489, 130513, 130517, 130523, 130531, 130547, 130553, 130579, 130589, 130619, 130621, 130631, 130633, 130639, 130643, 130649, 130651, 130657, 130681, 130687, 130693, 130699, 130729, 130769, 130783, 130787, 130807, 130811, 130817, 130829, 130841, 130843, 130859, 130873, 130927, 130957, 130969, 130973, 130981, 130987, 131009, 131011, 131023, 131041, 131059, 131063, 131071, 131101, 131111, 131113, 131129, 131143, 131149, 131171, 131203, 131213, 131221, 131231, 131249, 131251, 131267, 131293, 131297, 131303, 131311, 131317, 131321, 131357, 131363, 131371, 131381, 131413, 131431, 131437, 131441, 131447, 131449, 131477, 131479, 131489, 131497, 131501, 131507, 131519, 131543, 131561, 131581, 131591, 131611, 131617, 131627, 131639, 131641, 131671, 131687, 131701, 131707, 131711, 131713, 131731, 131743, 131749, 131759, 131771, 131777, 131779, 131783, 131797, 131837, 131839, 131849, 131861, 131891, 131893, 131899, 131909, 131927, 131933, 131939, 131941, 131947, 131959, 131969, 132001, 132019, 132047, 132049, 132059, 132071, 132103, 132109, 132113, 132137, 132151, 132157, 132169, 132173, 132199, 132229, 132233, 132241, 132247, 132257, 132263, 132283, 132287, 132299, 132313, 132329, 132331, 132347, 132361, 132367, 132371, 132383, 132403, 132409, 132421, 132437, 132439, 132469, 132491, 132499, 132511, 132523, 132527, 132529, 132533, 132541, 132547, 132589, 132607, 132611, 132619, 132623, 132631, 132637, 132647, 132661, 132667, 132679, 132689, 132697, 132701, 132707, 132709, 132721, 132739, 132749, 132751, 132757, 132761, 132763, 132817, 132833, 132851, 132857, 132859, 132863, 132887, 132893, 132911, 132929, 132947, 132949, 132953, 132961, 132967, 132971, 132989, 133013, 133033, 133039, 133051, 133069, 133073, 133087, 133097, 133103, 133109, 133117, 133121, 133153, 133157, 133169, 133183, 133187, 133201, 133213, 133241, 133253, 133261, 133271, 133277, 133279, 133283, 133303, 133319, 133321, 133327, 133337, 133349, 133351, 133379, 133387, 133391, 133403, 133417, 133439, 133447, 133451, 133481, 133493, 133499, 133519, 133541, 133543, 133559, 133571, 133583, 133597, 133631, 133633, 133649, 133657, 133669, 133673, 133691, 133697, 133709, 133711, 133717, 133723, 133733, 133769, 133781, 133801, 133811, 133813, 133831, 133843, 133853, 133873, 133877, 133919, 133949, 133963, 133967, 133979, 133981, 133993, 133999, 134033, 134039, 134047, 134053, 134059, 134077, 134081, 134087, 134089, 134093, 134129, 134153, 134161, 134171, 134177, 134191, 134207, 134213, 134219, 134227, 134243, 134257, 134263, 134269, 134287, 134291, 134293, 134327, 134333, 134339, 134341, 134353, 134359, 134363, 134369, 134371, 134399, 134401, 134417, 134437, 134443, 134471, 134489, 134503, 134507, 134513, 134581, 134587, 134591, 134593, 134597, 134609, 134639, 134669, 134677, 134681, 134683, 134699, 134707, 134731, 134741, 134753, 134777, 134789, 134807, 134837, 134839, 134851, 134857, 134867, 134873, 134887, 134909, 134917, 134921, 134923, 134947, 134951, 134989, 134999, 135007, 135017, 135019, 135029, 135043, 135049, 135059, 135077, 135089, 135101, 135119, 135131, 135151, 135173, 135181, 135193, 135197, 135209, 135211, 135221, 135241, 135257, 135271, 135277, 135281, 135283, 135301, 135319, 135329, 135347, 135349, 135353, 135367, 135389, 135391, 135403, 135409, 135427, 135431, 135433, 135449, 135461, 135463, 135467, 135469, 135479, 135497, 135511, 135533, 135559, 135571, 135581, 135589, 135593, 135599, 135601, 135607, 135613, 135617, 135623, 135637, 135647, 135649, 135661, 135671, 135697, 135701, 135719, 135721, 135727, 135731, 135743, 135757, 135781, 135787, 135799, 135829, 135841, 135851, 135859, 135887, 135893, 135899, 135911, 135913, 135929, 135937, 135977, 135979, 136013, 136027, 136033, 136043, 136057, 136067, 136069, 136093, 136099, 136111, 136133, 136139, 136163, 136177, 136189, 136193, 136207, 136217, 136223, 136237, 136247, 136261, 136273, 136277, 136303, 136309, 136319, 136327, 136333, 136337, 136343, 136351, 136361, 136373, 136379, 136393, 136397, 136399, 136403, 136417, 136421, 136429, 136447, 136453, 136463, 136471, 136481, 136483, 136501, 136511, 136519, 136523, 136531, 136537, 136541, 136547, 136559, 136573, 136601, 136603, 136607, 136621, 136649, 136651, 136657, 136691, 136693, 136709, 136711, 136727, 136733, 136739, 136751, 136753, 136769, 136777, 136811, 136813, 136841, 136849, 136859, 136861, 136879, 136883, 136889, 136897, 136943, 136949, 136951, 136963, 136973, 136979, 136987, 136991, 136993, 136999, 137029, 137077, 137087, 137089, 137117, 137119, 137131, 137143, 137147, 137153, 137177, 137183, 137191, 137197, 137201, 137209, 137219, 137239, 137251, 137273, 137279, 137303, 137321, 137339, 137341, 137353, 137359, 137363, 137369, 137383, 137387, 137393, 137399, 137413, 137437, 137443, 137447, 137453, 137477, 137483, 137491, 137507, 137519, 137537, 137567, 137573, 137587, 137593, 137597, 137623, 137633, 137639, 137653, 137659, 137699, 137707, 137713, 137723, 137737, 137743, 137771, 137777, 137791, 137803, 137827, 137831, 137849, 137867, 137869, 137873, 137909, 137911, 137927, 137933, 137941, 137947, 137957, 137983, 137993, 137999, 138007, 138041, 138053, 138059, 138071, 138077, 138079, 138101, 138107, 138113, 138139, 138143, 138157, 138163, 138179, 138181, 138191, 138197, 138209, 138239, 138241, 138247, 138251, 138283, 138289, 138311, 138319, 138323, 138337, 138349, 138371, 138373, 138389, 138401, 138403, 138407, 138427, 138433, 138449, 138451, 138461, 138469, 138493, 138497, 138511, 138517, 138547, 138559, 138563, 138569, 138571, 138577, 138581, 138587, 138599, 138617, 138629, 138637, 138641, 138647, 138661, 138679, 138683, 138727, 138731, 138739, 138763, 138793, 138797, 138799, 138821, 138829, 138841, 138863, 138869, 138883, 138889, 138893, 138899, 138917, 138923, 138937, 138959, 138967, 138977, 139021, 139033, 139067, 139079, 139091, 139109, 139121, 139123, 139133, 139169, 139177, 139187, 139199, 139201, 139241, 139267, 139273, 139291, 139297, 139301, 139303, 139309, 139313, 139333, 139339, 139343, 139361, 139367, 139369, 139387, 139393, 139397, 139409, 139423, 139429, 139439, 139457, 139459, 139483, 139487, 139493, 139501, 139511, 139537, 139547, 139571, 139589, 139591, 139597, 139609, 139619, 139627, 139661, 139663, 139681, 139697, 139703, 139709, 139721, 139729, 139739, 139747, 139753, 139759, 139787, 139801, 139813, 139831, 139837, 139861, 139871, 139883, 139891, 139901, 139907, 139921, 139939, 139943, 139967, 139969, 139981, 139987, 139991, 139999, 140009, 140053, 140057, 140069, 140071, 140111, 140123, 140143, 140159, 140167, 140171, 140177, 140191, 140197, 140207, 140221, 140227, 140237, 140249, 140263, 140269, 140281, 140297, 140317, 140321, 140333, 140339, 140351, 140363, 140381, 140401, 140407, 140411, 140417, 140419, 140423, 140443, 140449, 140453, 140473, 140477, 140521, 140527, 140533, 140549, 140551, 140557, 140587, 140593, 140603, 140611, 140617, 140627, 140629, 140639, 140659, 140663, 140677, 140681, 140683, 140689, 140717, 140729, 140731, 140741, 140759, 140761, 140773, 140779, 140797, 140813, 140827, 140831, 140837, 140839, 140863, 140867, 140869, 140891, 140893, 140897, 140909, 140929, 140939, 140977, 140983, 140989, 141023, 141041, 141061, 141067, 141073, 141079, 141101, 141107, 141121, 141131, 141157, 141161, 141179, 141181, 141199, 141209, 141221, 141223, 141233, 141241, 141257, 141263, 141269, 141277, 141283, 141301, 141307, 141311, 141319, 141353, 141359, 141371, 141397, 141403, 141413, 141439, 141443, 141461, 141481, 141497, 141499, 141509, 141511, 141529, 141539, 141551, 141587, 141601, 141613, 141619, 141623, 141629, 141637, 141649, 141653, 141667, 141671, 141677, 141679, 141689, 141697, 141707, 141709, 141719, 141731, 141761, 141767, 141769, 141773, 141793, 141803, 141811, 141829, 141833, 141851, 141853, 141863, 141871, 141907, 141917, 141931, 141937, 141941, 141959, 141961, 141971, 141991, 142007, 142019, 142031, 142039, 142049, 142057, 142061, 142067, 142097, 142099, 142111, 142123, 142151, 142157, 142159, 142169, 142183, 142189, 142193, 142211, 142217, 142223, 142231, 142237, 142271, 142297, 142319, 142327, 142357, 142369, 142381, 142391, 142403, 142421, 142427, 142433, 142453, 142469, 142501, 142529, 142537, 142543, 142547, 142553, 142559, 142567, 142573, 142589, 142591, 142601, 142607, 142609, 142619, 142657, 142673, 142697, 142699, 142711, 142733, 142757, 142759, 142771, 142787, 142789, 142799, 142811, 142837, 142841, 142867, 142871, 142873, 142897, 142903, 142907, 142939, 142949, 142963, 142969, 142973, 142979, 142981, 142993, 143053, 143063, 143093, 143107, 143111, 143113, 143137, 143141, 143159, 143177, 143197, 143239, 143243, 143249, 143257, 143261, 143263, 143281, 143287, 143291, 143329, 143333, 143357, 143387, 143401, 143413, 143419, 143443, 143461, 143467, 143477, 143483, 143489, 143501, 143503, 143509, 143513, 143519, 143527, 143537, 143551, 143567, 143569, 143573, 143593, 143609, 143617, 143629, 143651, 143653, 143669, 143677, 143687, 143699, 143711, 143719, 143729, 143743, 143779, 143791, 143797, 143807, 143813, 143821, 143827, 143831, 143833, 143873, 143879, 143881, 143909, 143947, 143953, 143971, 143977, 143981, 143999, 144013, 144031, 144037, 144061, 144071, 144073, 144103, 144139, 144161, 144163, 144167, 144169, 144173, 144203, 144223, 144241, 144247, 144253, 144259, 144271, 144289, 144299, 144307, 144311, 144323, 144341, 144349, 144379, 144383, 144407, 144409, 144413, 144427, 144439, 144451, 144461, 144479, 144481, 144497, 144511, 144539, 144541, 144563, 144569, 144577, 144583, 144589, 144593, 144611, 144629, 144659, 144667, 144671, 144701, 144709, 144719, 144731, 144737, 144751, 144757, 144763, 144773, 144779, 144791, 144817, 144829, 144839, 144847, 144883, 144887, 144889, 144899, 144917, 144931, 144941, 144961, 144967, 144973, 144983, 145007, 145009, 145021, 145031, 145037, 145043, 145063, 145069, 145091, 145109, 145121, 145133, 145139, 145177, 145193, 145207, 145213, 145219, 145253, 145259, 145267, 145283, 145289, 145303, 145307, 145349, 145361, 145381, 145391, 145399, 145417, 145423, 145433, 145441, 145451, 145459, 145463, 145471, 145477, 145487, 145501, 145511, 145513, 145517, 145531, 145543, 145547, 145549, 145577, 145589, 145601, 145603, 145633, 145637, 145643, 145661, 145679, 145681, 145687, 145703, 145709, 145721, 145723, 145753, 145757, 145759, 145771, 145777, 145799, 145807, 145819, 145823, 145829, 145861, 145879, 145897, 145903, 145931, 145933, 145949, 145963, 145967, 145969, 145987, 145991, 146009, 146011, 146021, 146023, 146033, 146051, 146057, 146059, 146063, 146077, 146093, 146099, 146117, 146141, 146161, 146173, 146191, 146197, 146203, 146213, 146221, 146239, 146249, 146273, 146291, 146297, 146299, 146309, 146317, 146323, 146347, 146359, 146369, 146381, 146383, 146389, 146407, 146417, 146423, 146437, 146449, 146477, 146513, 146519, 146521, 146527, 146539, 146543, 146563, 146581, 146603, 146609, 146617, 146639, 146647, 146669, 146677, 146681, 146683, 146701, 146719, 146743, 146749, 146767, 146777, 146801, 146807, 146819, 146833, 146837, 146843, 146849, 146857, 146891, 146893, 146917, 146921, 146933, 146941, 146953, 146977, 146983, 146987, 146989, 147011, 147029, 147031, 147047, 147073, 147083, 147089, 147097, 147107, 147137, 147139, 147151, 147163, 147179, 147197, 147209, 147211, 147221, 147227, 147229, 147253, 147263, 147283, 147289, 147293, 147299, 147311, 147319, 147331, 147341, 147347, 147353, 147377, 147391, 147397, 147401, 147409, 147419, 147449, 147451, 147457, 147481, 147487, 147503, 147517, 147541, 147547, 147551, 147557, 147571, 147583, 147607, 147613, 147617, 147629, 147647, 147661, 147671, 147673, 147689, 147703, 147709, 147727, 147739, 147743, 147761, 147769, 147773, 147779, 147787, 147793, 147799, 147811, 147827, 147853, 147859, 147863, 147881, 147919, 147937, 147949, 147977, 147997, 148013, 148021, 148061, 148063, 148073, 148079, 148091, 148123, 148139, 148147, 148151, 148153, 148157, 148171, 148193, 148199, 148201, 148207, 148229, 148243, 148249, 148279, 148301, 148303, 148331, 148339, 148361, 148367, 148381, 148387, 148399, 148403, 148411, 148429, 148439, 148457, 148469, 148471, 148483, 148501, 148513, 148517, 148531, 148537, 148549, 148573, 148579, 148609, 148627, 148633, 148639, 148663, 148667, 148669, 148691, 148693, 148711, 148721, 148723, 148727, 148747, 148763, 148781, 148783, 148793, 148817, 148829, 148853, 148859, 148861, 148867, 148873, 148891, 148913, 148921, 148927, 148931, 148933, 148949, 148957, 148961, 148991, 148997, 149011, 149021, 149027, 149033, 149053, 149057, 149059, 149069, 149077, 149087, 149099, 149101, 149111, 149113, 149119, 149143, 149153, 149159, 149161, 149173, 149183, 149197, 149213, 149239, 149249, 149251, 149257, 149269, 149287, 149297, 149309, 149323, 149333, 149341, 149351, 149371, 149377, 149381, 149393, 149399, 149411, 149417, 149419, 149423, 149441, 149459, 149489, 149491, 149497, 149503, 149519, 149521, 149531, 149533, 149543, 149551, 149561, 149563, 149579, 149603, 149623, 149627, 149629, 149689, 149711, 149713, 149717, 149729, 149731, 149749, 149759, 149767, 149771, 149791, 149803, 149827, 149837, 149839, 149861, 149867, 149873, 149893, 149899, 149909, 149911, 149921, 149939, 149953, 149969, 149971, 149993, 150001, 150011, 150041, 150053, 150061, 150067, 150077, 150083, 150089, 150091, 150097, 150107, 150131, 150151, 150169, 150193, 150197, 150203, 150209, 150211, 150217, 150221, 150223, 150239, 150247, 150287, 150299, 150301, 150323, 150329, 150343, 150373, 150377, 150379, 150383, 150401, 150407, 150413, 150427, 150431, 150439, 150473, 150497, 150503, 150517, 150523, 150533, 150551, 150559, 150571, 150583, 150587, 150589, 150607, 150611, 150617, 150649, 150659, 150697, 150707, 150721, 150743, 150767, 150769, 150779, 150791, 150797, 150827, 150833, 150847, 150869, 150881, 150883, 150889, 150893, 150901, 150907, 150919, 150929, 150959, 150961, 150967, 150979, 150989, 150991, 151007, 151009, 151013, 151027, 151049, 151051, 151057, 151091, 151121, 151141, 151153, 151157, 151163, 151169, 151171, 151189, 151201, 151213, 151237, 151241, 151243, 151247, 151253, 151273, 151279, 151289, 151303, 151337, 151339, 151343, 151357, 151379, 151381, 151391, 151397, 151423, 151429, 151433, 151451, 151471, 151477, 151483, 151499, 151507, 151517, 151523, 151531, 151537, 151549, 151553, 151561, 151573, 151579, 151597, 151603, 151607, 151609, 151631, 151637, 151643, 151651, 151667, 151673, 151681, 151687, 151693, 151703, 151717, 151729, 151733, 151769, 151771, 151783, 151787, 151799, 151813, 151817, 151841, 151847, 151849, 151871, 151883, 151897, 151901, 151903, 151909, 151937, 151939, 151967, 151969, 152003, 152017, 152027, 152029, 152039, 152041, 152063, 152077, 152081, 152083, 152093, 152111, 152123, 152147, 152183, 152189, 152197, 152203, 152213, 152219, 152231, 152239, 152249, 152267, 152287, 152293, 152297, 152311, 152363, 152377, 152381, 152389, 152393, 152407, 152417, 152419, 152423, 152429, 152441, 152443, 152459, 152461, 152501, 152519, 152531, 152533, 152539, 152563, 152567, 152597, 152599, 152617, 152623, 152629, 152639, 152641, 152657, 152671, 152681, 152717, 152723, 152729, 152753, 152767, 152777, 152783, 152791, 152809, 152819, 152821, 152833, 152837, 152839, 152843, 152851, 152857, 152879, 152897, 152899, 152909, 152939, 152941, 152947, 152953, 152959, 152981, 152989, 152993, 153001, 153059, 153067, 153071, 153073, 153077, 153089, 153107, 153113, 153133, 153137, 153151, 153191, 153247, 153259, 153269, 153271, 153277, 153281, 153287, 153313, 153319, 153337, 153343, 153353, 153359, 153371, 153379, 153407, 153409, 153421, 153427, 153437, 153443, 153449, 153457, 153469, 153487, 153499, 153509, 153511, 153521, 153523, 153529, 153533, 153557, 153563, 153589, 153607, 153611, 153623, 153641, 153649, 153689, 153701, 153719, 153733, 153739, 153743, 153749, 153757, 153763, 153817, 153841, 153871, 153877, 153887, 153889, 153911, 153913, 153929, 153941, 153947, 153949, 153953, 153991, 153997, 154001, 154027, 154043, 154057, 154061, 154067, 154073, 154079, 154081, 154087, 154097, 154111, 154127, 154153, 154157, 154159, 154181, 154183, 154211, 154213, 154229, 154243, 154247, 154267, 154277, 154279, 154291, 154303, 154313, 154321, 154333, 154339, 154351, 154369, 154373, 154387, 154409, 154417, 154423, 154439, 154459, 154487, 154493, 154501, 154523, 154543, 154571, 154573, 154579, 154589, 154591, 154613, 154619, 154621, 154643, 154667, 154669, 154681, 154691, 154699, 154723, 154727, 154733, 154747, 154753, 154769, 154787, 154789, 154799, 154807, 154823, 154841, 154849, 154871, 154873, 154877, 154883, 154897, 154927, 154933, 154937, 154943, 154981, 154991, 155003, 155009, 155017, 155027, 155047, 155069, 155081, 155083, 155087, 155119, 155137, 155153, 155161, 155167, 155171, 155191, 155201, 155203, 155209, 155219, 155231, 155251, 155269, 155291, 155299, 155303, 155317, 155327, 155333, 155371, 155377, 155381, 155383, 155387, 155399, 155413, 155423, 155443, 155453, 155461, 155473, 155501, 155509, 155521, 155537, 155539, 155557, 155569, 155579, 155581, 155593, 155599, 155609, 155621, 155627, 155653, 155657, 155663, 155671, 155689, 155693, 155699, 155707, 155717, 155719, 155723, 155731, 155741, 155747, 155773, 155777, 155783, 155797, 155801, 155809, 155821, 155833, 155849, 155851, 155861, 155863, 155887, 155891, 155893, 155921, 156007, 156011, 156019, 156041, 156059, 156061, 156071, 156089, 156109, 156119, 156127, 156131, 156139, 156151, 156157, 156217, 156227, 156229, 156241, 156253, 156257, 156259, 156269, 156307, 156319, 156329, 156347, 156353, 156361, 156371, 156419, 156421, 156437, 156467, 156487, 156491, 156493, 156511, 156521, 156539, 156577, 156589, 156593, 156601, 156619, 156623, 156631, 156641, 156659, 156671, 156677, 156679, 156683, 156691, 156703, 156707, 156719, 156727, 156733, 156749, 156781, 156797, 156799, 156817, 156823, 156833, 156841, 156887, 156899, 156901, 156913, 156941, 156943, 156967, 156971, 156979, 157007, 157013, 157019, 157037, 157049, 157051, 157057, 157061, 157081, 157103, 157109, 157127, 157133, 157141, 157163, 157177, 157181, 157189, 157207, 157211, 157217, 157219, 157229, 157231, 157243, 157247, 157253, 157259, 157271, 157273, 157277, 157279, 157291, 157303, 157307, 157321, 157327, 157349, 157351, 157363, 157393, 157411, 157427, 157429, 157433, 157457, 157477, 157483, 157489, 157513, 157519, 157523, 157543, 157559, 157561, 157571, 157579, 157627, 157637, 157639, 157649, 157667, 157669, 157679, 157721, 157733, 157739, 157747, 157769, 157771, 157793, 157799, 157813, 157823, 157831, 157837, 157841, 157867, 157877, 157889, 157897, 157901, 157907, 157931, 157933, 157951, 157991, 157999, 158003, 158009, 158017, 158029, 158047, 158071, 158077, 158113, 158129, 158141, 158143, 158161, 158189, 158201, 158209, 158227, 158231, 158233, 158243, 158261, 158269, 158293, 158303, 158329, 158341, 158351, 158357, 158359, 158363, 158371, 158393, 158407, 158419, 158429, 158443, 158449, 158489, 158507, 158519, 158527, 158537, 158551, 158563, 158567, 158573, 158581, 158591, 158597, 158611, 158617, 158621, 158633, 158647, 158657, 158663, 158699, 158731, 158747, 158749, 158759, 158761, 158771, 158777, 158791, 158803, 158843, 158849, 158863, 158867, 158881, 158909, 158923, 158927, 158941, 158959, 158981, 158993, 159013, 159017, 159023, 159059, 159073, 159079, 159097, 159113, 159119, 159157, 159161, 159167, 159169, 159179, 159191, 159193, 159199, 159209, 159223, 159227, 159233, 159287, 159293, 159311, 159319, 159337, 159347, 159349, 159361, 159389, 159403, 159407, 159421, 159431, 159437, 159457, 159463, 159469, 159473, 159491, 159499, 159503, 159521, 159539, 159541, 159553, 159563, 159569, 159571, 159589, 159617, 159623, 159629, 159631, 159667, 159671, 159673, 159683, 159697, 159701, 159707, 159721, 159737, 159739, 159763, 159769, 159773, 159779, 159787, 159791, 159793, 159799, 159811, 159833, 159839, 159853, 159857, 159869, 159871, 159899, 159911, 159931, 159937, 159977, 159979, 160001, 160009, 160019, 160031, 160033, 160049, 160073, 160079, 160081, 160087, 160091, 160093, 160117, 160141, 160159, 160163, 160169, 160183, 160201, 160207, 160217, 160231, 160243, 160253, 160309, 160313, 160319, 160343, 160357, 160367, 160373, 160387, 160397, 160403, 160409, 160423, 160441, 160453, 160481, 160483, 160499, 160507, 160541, 160553, 160579, 160583, 160591, 160603, 160619, 160621, 160627, 160637, 160639, 160649, 160651, 160663, 160669, 160681, 160687, 160697, 160709, 160711, 160723, 160739, 160751, 160753, 160757, 160781, 160789, 160807, 160813, 160817, 160829, 160841, 160861, 160877, 160879, 160883, 160903, 160907, 160933, 160967, 160969, 160981, 160997, 161009, 161017, 161033, 161039, 161047, 161053, 161059, 161071, 161087, 161093, 161123, 161137, 161141, 161149, 161159, 161167, 161201, 161221, 161233, 161237, 161263, 161267, 161281, 161303, 161309, 161323, 161333, 161339, 161341, 161363, 161377, 161387, 161407, 161411, 161453, 161459, 161461, 161471, 161503, 161507, 161521, 161527, 161531, 161543, 161561, 161563, 161569, 161573, 161591, 161599, 161611, 161627, 161639, 161641, 161659, 161683, 161717, 161729, 161731, 161741, 161743, 161753, 161761, 161771, 161773, 161779, 161783, 161807, 161831, 161839, 161869, 161873, 161879, 161881, 161911, 161921, 161923, 161947, 161957, 161969, 161971, 161977, 161983, 161999, 162007, 162011, 162017, 162053, 162059, 162079, 162091, 162109, 162119, 162143, 162209, 162221, 162229, 162251, 162257, 162263, 162269, 162277, 162287, 162289, 162293, 162343, 162359, 162389, 162391, 162413, 162419, 162439, 162451, 162457, 162473, 162493, 162499, 162517, 162523, 162527, 162529, 162553, 162557, 162563, 162577, 162593, 162601, 162611, 162623, 162629, 162641, 162649, 162671, 162677, 162683, 162691, 162703, 162709, 162713, 162727, 162731, 162739, 162749, 162751, 162779, 162787, 162791, 162821, 162823, 162829, 162839, 162847, 162853, 162859, 162881, 162889, 162901, 162907, 162917, 162937, 162947, 162971, 162973, 162989, 162997, 163003, 163019, 163021, 163027, 163061, 163063, 163109, 163117, 163127, 163129, 163147, 163151, 163169, 163171, 163181, 163193, 163199, 163211, 163223, 163243, 163249, 163259, 163307, 163309, 163321, 163327, 163337, 163351, 163363, 163367, 163393, 163403, 163409, 163411, 163417, 163433, 163469, 163477, 163481, 163483, 163487, 163517, 163543, 163561, 163567, 163573, 163601, 163613, 163621, 163627, 163633, 163637, 163643, 163661, 163673, 163679, 163697, 163729, 163733, 163741, 163753, 163771, 163781, 163789, 163811, 163819, 163841, 163847, 163853, 163859, 163861, 163871, 163883, 163901, 163909, 163927, 163973, 163979, 163981, 163987, 163991, 163993, 163997, 164011, 164023, 164039, 164051, 164057, 164071, 164089, 164093, 164113, 164117, 164147, 164149, 164173, 164183, 164191, 164201, 164209, 164231, 164233, 164239, 164249, 164251, 164267, 164279, 164291, 164299, 164309, 164321, 164341, 164357, 164363, 164371, 164377, 164387, 164413, 164419, 164429, 164431, 164443, 164447, 164449, 164471, 164477, 164503, 164513, 164531, 164569, 164581, 164587, 164599, 164617, 164621, 164623, 164627, 164653, 164663, 164677, 164683, 164701, 164707, 164729, 164743, 164767, 164771, 164789, 164809, 164821, 164831, 164837, 164839, 164881, 164893, 164911, 164953, 164963, 164987, 164999, 165001, 165037, 165041, 165047, 165049, 165059, 165079, 165083, 165089, 165103, 165133, 165161, 165173, 165181, 165203, 165211, 165229, 165233, 165247, 165287, 165293, 165311, 165313, 165317, 165331, 165343, 165349, 165367, 165379, 165383, 165391, 165397, 165437, 165443, 165449, 165457, 165463, 165469, 165479, 165511, 165523, 165527, 165533, 165541, 165551, 165553, 165559, 165569, 165587, 165589, 165601, 165611, 165617, 165653, 165667, 165673, 165701, 165703, 165707, 165709, 165713, 165719, 165721, 165749, 165779, 165799, 165811, 165817, 165829, 165833, 165857, 165877, 165883, 165887, 165901, 165931, 165941, 165947, 165961, 165983, 166013, 166021, 166027, 166031, 166043, 166063, 166081, 166099, 166147, 166151, 166157, 166169, 166183, 166189, 166207, 166219, 166237, 166247, 166259, 166273, 166289, 166297, 166301, 166303, 166319, 166349, 166351, 166357, 166363, 166393, 166399, 166403, 166409, 166417, 166429, 166457, 166471, 166487, 166541, 166561, 166567, 166571, 166597, 166601, 166603, 166609, 166613, 166619, 166627, 166631, 166643, 166657, 166667, 166669, 166679, 166693, 166703, 166723, 166739, 166741, 166781, 166783, 166799, 166807, 166823, 166841, 166843, 166847, 166849, 166853, 166861, 166867, 166871, 166909, 166919, 166931, 166949, 166967, 166973, 166979, 166987, 167009, 167017, 167021, 167023, 167033, 167039, 167047, 167051, 167071, 167077, 167081, 167087, 167099, 167107, 167113, 167117, 167119, 167149, 167159, 167173, 167177, 167191, 167197, 167213, 167221, 167249, 167261, 167267, 167269, 167309, 167311, 167317, 167329, 167339, 167341, 167381, 167393, 167407, 167413, 167423, 167429, 167437, 167441, 167443, 167449, 167471, 167483, 167491, 167521, 167537, 167543, 167593, 167597, 167611, 167621, 167623, 167627, 167633, 167641, 167663, 167677, 167683, 167711, 167729, 167747, 167759, 167771, 167777, 167779, 167801, 167809, 167861, 167863, 167873, 167879, 167887, 167891, 167899, 167911, 167917, 167953, 167971, 167987, 168013, 168023, 168029, 168037, 168043, 168067, 168071, 168083, 168089, 168109, 168127, 168143, 168151, 168193, 168197, 168211, 168227, 168247, 168253, 168263, 168269, 168277, 168281, 168293, 168323, 168331, 168347, 168353, 168391, 168409, 168433, 168449, 168451, 168457, 168463, 168481, 168491, 168499, 168523, 168527, 168533, 168541, 168559, 168599, 168601, 168617, 168629, 168631, 168643, 168673, 168677, 168697, 168713, 168719, 168731, 168737, 168743, 168761, 168769, 168781, 168803, 168851, 168863, 168869, 168887, 168893, 168899, 168901, 168913, 168937, 168943, 168977, 168991, 169003, 169007, 169009, 169019, 169049, 169063, 169067, 169069, 169079, 169093, 169097, 169111, 169129, 169151, 169159, 169177, 169181, 169199, 169217, 169219, 169241, 169243, 169249, 169259, 169283, 169307, 169313, 169319, 169321, 169327, 169339, 169343, 169361, 169369, 169373, 169399, 169409, 169427, 169457, 169471, 169483, 169489, 169493, 169501, 169523, 169531, 169553, 169567, 169583, 169591, 169607, 169627, 169633, 169639, 169649, 169657, 169661, 169667, 169681, 169691, 169693, 169709, 169733, 169751, 169753, 169769, 169777, 169783, 169789, 169817, 169823, 169831, 169837, 169843, 169859, 169889, 169891, 169909, 169913, 169919, 169933, 169937, 169943, 169951, 169957, 169987, 169991, 170003, 170021, 170029, 170047, 170057, 170063, 170081, 170099, 170101, 170111, 170123, 170141, 170167, 170179, 170189, 170197, 170207, 170213, 170227, 170231, 170239, 170243, 170249, 170263, 170267, 170279, 170293, 170299, 170327, 170341, 170347, 170351, 170353, 170363, 170369, 170371, 170383, 170389, 170393, 170413, 170441, 170447, 170473, 170483, 170497, 170503, 170509, 170537, 170539, 170551, 170557, 170579, 170603, 170609, 170627, 170633, 170641, 170647, 170669, 170689, 170701, 170707, 170711, 170741, 170749, 170759, 170761, 170767, 170773, 170777, 170801, 170809, 170813, 170827, 170837, 170843, 170851, 170857, 170873, 170881, 170887, 170899, 170921, 170927, 170953, 170957, 170971, 171007, 171023, 171029, 171043, 171047, 171049, 171053, 171077, 171079, 171091, 171103, 171131, 171161, 171163, 171167, 171169, 171179, 171203, 171233, 171251, 171253, 171263, 171271, 171293, 171299, 171317, 171329, 171341, 171383, 171401, 171403, 171427, 171439, 171449, 171467, 171469, 171473, 171481, 171491, 171517, 171529, 171539, 171541, 171553, 171559, 171571, 171583, 171617, 171629, 171637, 171641, 171653, 171659, 171671, 171673, 171679, 171697, 171707, 171713, 171719, 171733, 171757, 171761, 171763, 171793, 171799, 171803, 171811, 171823, 171827, 171851, 171863, 171869, 171877, 171881, 171889, 171917, 171923, 171929, 171937, 171947, 172001, 172009, 172021, 172027, 172031, 172049, 172069, 172079, 172093, 172097, 172127, 172147, 172153, 172157, 172169, 172171, 172181, 172199, 172213, 172217, 172219, 172223, 172243, 172259, 172279, 172283, 172297, 172307, 172313, 172321, 172331, 172343, 172351, 172357, 172373, 172399, 172411, 172421, 172423, 172427, 172433, 172439, 172441, 172489, 172507, 172517, 172519, 172541, 172553, 172561, 172573, 172583, 172589, 172597, 172603, 172607, 172619, 172633, 172643, 172649, 172657, 172663, 172673, 172681, 172687, 172709, 172717, 172721, 172741, 172751, 172759, 172787, 172801, 172807, 172829, 172849, 172853, 172859, 172867, 172871, 172877, 172883, 172933, 172969, 172973, 172981, 172987, 172993, 172999, 173021, 173023, 173039, 173053, 173059, 173081, 173087, 173099, 173137, 173141, 173149, 173177, 173183, 173189, 173191, 173207, 173209, 173219, 173249, 173263, 173267, 173273, 173291, 173293, 173297, 173309, 173347, 173357, 173359, 173429, 173431, 173473, 173483, 173491, 173497, 173501, 173531, 173539, 173543, 173549, 173561, 173573, 173599, 173617, 173629, 173647, 173651, 173659, 173669, 173671, 173683, 173687, 173699, 173707, 173713, 173729, 173741, 173743, 173773, 173777, 173779, 173783, 173807, 173819, 173827, 173839, 173851, 173861, 173867, 173891, 173897, 173909, 173917, 173923, 173933, 173969, 173977, 173981, 173993, 174007, 174017, 174019, 174047, 174049, 174061, 174067, 174071, 174077, 174079, 174091, 174101, 174121, 174137, 174143, 174149, 174157, 174169, 174197, 174221, 174241, 174257, 174259, 174263, 174281, 174289, 174299, 174311, 174329, 174331, 174337, 174347, 174367, 174389, 174407, 174413, 174431, 174443, 174457, 174467, 174469, 174481, 174487, 174491, 174527, 174533, 174569, 174571, 174583, 174599, 174613, 174617, 174631, 174637, 174649, 174653, 174659, 174673, 174679, 174703, 174721, 174737, 174749, 174761, 174763, 174767, 174773, 174799, 174821, 174829, 174851, 174859, 174877, 174893, 174901, 174907, 174917, 174929, 174931, 174943, 174959, 174989, 174991, 175003, 175013, 175039, 175061, 175067, 175069, 175079, 175081, 175103, 175129, 175141, 175211, 175229, 175261, 175267, 175277, 175291, 175303, 175309, 175327, 175333, 175349, 175361, 175391, 175393, 175403, 175411, 175433, 175447, 175453, 175463, 175481, 175493, 175499, 175519, 175523, 175543, 175573, 175601, 175621, 175631, 175633, 175649, 175663, 175673, 175687, 175691, 175699, 175709, 175723, 175727, 175753, 175757, 175759, 175781, 175783, 175811, 175829, 175837, 175843, 175853, 175859, 175873, 175891, 175897, 175909, 175919, 175937, 175939, 175949, 175961, 175963, 175979, 175991, 175993, 176017, 176021, 176023, 176041, 176047, 176051, 176053, 176063, 176081, 176087, 176089, 176123, 176129, 176153, 176159, 176161, 176179, 176191, 176201, 176207, 176213, 176221, 176227, 176237, 176243, 176261, 176299, 176303, 176317, 176321, 176327, 176329, 176333, 176347, 176353, 176357, 176369, 176383, 176389, 176401, 176413, 176417, 176419, 176431, 176459, 176461, 176467, 176489, 176497, 176503, 176507, 176509, 176521, 176531, 176537, 176549, 176551, 176557, 176573, 176591, 176597, 176599, 176609, 176611, 176629, 176641, 176651, 176677, 176699, 176711, 176713, 176741, 176747, 176753, 176777, 176779, 176789, 176791, 176797, 176807, 176809, 176819, 176849, 176857, 176887, 176899, 176903, 176921, 176923, 176927, 176933, 176951, 176977, 176983, 176989, 177007, 177011, 177013, 177019, 177043, 177091, 177101, 177109, 177113, 177127, 177131, 177167, 177173, 177209, 177211, 177217, 177223, 177239, 177257, 177269, 177283, 177301, 177319, 177323, 177337, 177347, 177379, 177383, 177409, 177421, 177427, 177431, 177433, 177467, 177473, 177481, 177487, 177493, 177511, 177533, 177539, 177553, 177589, 177601, 177623, 177647, 177677, 177679, 177691, 177739, 177743, 177761, 177763, 177787, 177791, 177797, 177811, 177823, 177839, 177841, 177883, 177887, 177889, 177893, 177907, 177913, 177917, 177929, 177943, 177949, 177953, 177967, 177979, 178001, 178021, 178037, 178039, 178067, 178069, 178091, 178093, 178103, 178117, 178127, 178141, 178151, 178169, 178183, 178187, 178207, 178223, 178231, 178247, 178249, 178259, 178261, 178289, 178301, 178307, 178327, 178333, 178349, 178351, 178361, 178393, 178397, 178403, 178417, 178439, 178441, 178447, 178469, 178481, 178487, 178489, 178501, 178513, 178531, 178537, 178559, 178561, 178567, 178571, 178597, 178601, 178603, 178609, 178613, 178621, 178627, 178639, 178643, 178681, 178691, 178693, 178697, 178753, 178757, 178781, 178793, 178799, 178807, 178813, 178817, 178819, 178831, 178853, 178859, 178873, 178877, 178889, 178897, 178903, 178907, 178909, 178921, 178931, 178933, 178939, 178951, 178973, 178987, 179021, 179029, 179033, 179041, 179051, 179057, 179083, 179089, 179099, 179107, 179111, 179119, 179143, 179161, 179167, 179173, 179203, 179209, 179213, 179233, 179243, 179261, 179269, 179281, 179287, 179317, 179321, 179327, 179351, 179357, 179369, 179381, 179383, 179393, 179407, 179411, 179429, 179437, 179441, 179453, 179461, 179471, 179479, 179483, 179497, 179519, 179527, 179533, 179549, 179563, 179573, 179579, 179581, 179591, 179593, 179603, 179623, 179633, 179651, 179657, 179659, 179671, 179687, 179689, 179693, 179717, 179719, 179737, 179743, 179749, 179779, 179801, 179807, 179813, 179819, 179821, 179827, 179833, 179849, 179897, 179899, 179903, 179909, 179917, 179923, 179939, 179947, 179951, 179953, 179957, 179969, 179981, 179989, 179999, 180001, 180007, 180023, 180043, 180053, 180071, 180073, 180077, 180097, 180137, 180161, 180179, 180181, 180211, 180221, 180233, 180239, 180241, 180247, 180259, 180263, 180281, 180287, 180289, 180307, 180311, 180317, 180331, 180337, 180347, 180361, 180371, 180379, 180391, 180413, 180419, 180437, 180463, 180473, 180491, 180497, 180503, 180511, 180533, 180539, 180541, 180547, 180563, 180569, 180617, 180623, 180629, 180647, 180667, 180679, 180701, 180731, 180749, 180751, 180773, 180779, 180793, 180797, 180799, 180811, 180847, 180871, 180883, 180907, 180949, 180959, 181001, 181003, 181019, 181031, 181039, 181061, 181063, 181081, 181087, 181123, 181141, 181157, 181183, 181193, 181199, 181201, 181211, 181213, 181219, 181243, 181253, 181273, 181277, 181283, 181297, 181301, 181303, 181361, 181387, 181397, 181399, 181409, 181421, 181439, 181457, 181459, 181499, 181501, 181513, 181523, 181537, 181549, 181553, 181603, 181607, 181609, 181619, 181639, 181667, 181669, 181693, 181711, 181717, 181721, 181729, 181739, 181751, 181757, 181759, 181763, 181777, 181787, 181789, 181813, 181837, 181871, 181873, 181889, 181891, 181903, 181913, 181919, 181927, 181931, 181943, 181957, 181967, 181981, 181997, 182009, 182011, 182027, 182029, 182041, 182047, 182057, 182059, 182089, 182099, 182101, 182107, 182111, 182123, 182129, 182131, 182141, 182159, 182167, 182177, 182179, 182201, 182209, 182233, 182239, 182243, 182261, 182279, 182297, 182309, 182333, 182339, 182341, 182353, 182387, 182389, 182417, 182423, 182431, 182443, 182453, 182467, 182471, 182473, 182489, 182503, 182509, 182519, 182537, 182549, 182561, 182579, 182587, 182593, 182599, 182603, 182617, 182627, 182639, 182641, 182653, 182657, 182659, 182681, 182687, 182701, 182711, 182713, 182747, 182773, 182779, 182789, 182803, 182813, 182821, 182839, 182851, 182857, 182867, 182887, 182893, 182899, 182921, 182927, 182929, 182933, 182953, 182957, 182969, 182981, 182999, 183023, 183037, 183041, 183047, 183059, 183067, 183089, 183091, 183119, 183151, 183167, 183191, 183203, 183247, 183259, 183263, 183283, 183289, 183299, 183301, 183307, 183317, 183319, 183329, 183343, 183349, 183361, 183373, 183377, 183383, 183389, 183397, 183437, 183439, 183451, 183461, 183473, 183479, 183487, 183497, 183499, 183503, 183509, 183511, 183523, 183527, 183569, 183571, 183577, 183581, 183587, 183593, 183611, 183637, 183661, 183683, 183691, 183697, 183707, 183709, 183713, 183761, 183763, 183797, 183809, 183823, 183829, 183871, 183877, 183881, 183907, 183917, 183919, 183943, 183949, 183959, 183971, 183973, 183979, 184003, 184007, 184013, 184031, 184039, 184043, 184057, 184073, 184081, 184087, 184111, 184117, 184133, 184153, 184157, 184181, 184187, 184189, 184199, 184211, 184231, 184241, 184259, 184271, 184273, 184279, 184291, 184309, 184321, 184333, 184337, 184351, 184369, 184409, 184417, 184441, 184447, 184463, 184477, 184487, 184489, 184511, 184517, 184523, 184553, 184559, 184567, 184571, 184577, 184607, 184609, 184627, 184631, 184633, 184649, 184651, 184669, 184687, 184693, 184703, 184711, 184721, 184727, 184733, 184753, 184777, 184823, 184829, 184831, 184837, 184843, 184859, 184879, 184901, 184903, 184913, 184949, 184957, 184967, 184969, 184993, 184997, 184999, 185021, 185027, 185051, 185057, 185063, 185069, 185071, 185077, 185089, 185099, 185123, 185131, 185137, 185149, 185153, 185161, 185167, 185177, 185183, 185189, 185221, 185233, 185243, 185267, 185291, 185299, 185303, 185309, 185323, 185327, 185359, 185363, 185369, 185371, 185401, 185429, 185441, 185467, 185477, 185483, 185491, 185519, 185527, 185531, 185533, 185539, 185543, 185551, 185557, 185567, 185569, 185593, 185599, 185621, 185641, 185651, 185677, 185681, 185683, 185693, 185699, 185707, 185711, 185723, 185737, 185747, 185749, 185753, 185767, 185789, 185797, 185813, 185819, 185821, 185831, 185833, 185849, 185869, 185873, 185893, 185897, 185903, 185917, 185923, 185947, 185951, 185957, 185959, 185971, 185987, 185993, 186007, 186013, 186019, 186023, 186037, 186041, 186049, 186071, 186097, 186103, 186107, 186113, 186119, 186149, 186157, 186161, 186163, 186187, 186191, 186211, 186227, 186229, 186239, 186247, 186253, 186259, 186271, 186283, 186299, 186301, 186311, 186317, 186343, 186377, 186379, 186391, 186397, 186419, 186437, 186451, 186469, 186479, 186481, 186551, 186569, 186581, 186583, 186587, 186601, 186619, 186629, 186647, 186649, 186653, 186671, 186679, 186689, 186701, 186707, 186709, 186727, 186733, 186743, 186757, 186761, 186763, 186773, 186793, 186799, 186841, 186859, 186869, 186871, 186877, 186883, 186889, 186917, 186947, 186959, 187003, 187009, 187027, 187043, 187049, 187067, 187069, 187073, 187081, 187091, 187111, 187123, 187127, 187129, 187133, 187139, 187141, 187163, 187171, 187177, 187181, 187189, 187193, 187211, 187217, 187219, 187223, 187237, 187273, 187277, 187303, 187337, 187339, 187349, 187361, 187367, 187373, 187379, 187387, 187393, 187409, 187417, 187423, 187433, 187441, 187463, 187469, 187471, 187477, 187507, 187513, 187531, 187547, 187559, 187573, 187597, 187631, 187633, 187637, 187639, 187651, 187661, 187669, 187687, 187699, 187711, 187721, 187751, 187763, 187787, 187793, 187823, 187843, 187861, 187871, 187877, 187883, 187897, 187907, 187909, 187921, 187927, 187931, 187951, 187963, 187973, 187987, 188011, 188017, 188021, 188029, 188107, 188137, 188143, 188147, 188159, 188171, 188179, 188189, 188197, 188249, 188261, 188273, 188281, 188291, 188299, 188303, 188311, 188317, 188323, 188333, 188351, 188359, 188369, 188389, 188401, 188407, 188417, 188431, 188437, 188443, 188459, 188473, 188483, 188491, 188519, 188527, 188533, 188563, 188579, 188603, 188609, 188621, 188633, 188653, 188677, 188681, 188687, 188693, 188701, 188707, 188711, 188719, 188729, 188753, 188767, 188779, 188791, 188801, 188827, 188831, 188833, 188843, 188857, 188861, 188863, 188869, 188891, 188911, 188927, 188933, 188939, 188941, 188953, 188957, 188983, 188999, 189011, 189017, 189019, 189041, 189043, 189061, 189067, 189127, 189139, 189149, 189151, 189169, 189187, 189199, 189223, 189229, 189239, 189251, 189253, 189257, 189271, 189307, 189311, 189337, 189347, 189349, 189353, 189361, 189377, 189389, 189391, 189401, 189407, 189421, 189433, 189437, 189439, 189463, 189467, 189473, 189479, 189491, 189493, 189509, 189517, 189523, 189529, 189547, 189559, 189583, 189593, 189599, 189613, 189617, 189619, 189643, 189653, 189661, 189671, 189691, 189697, 189701, 189713, 189733, 189743, 189757, 189767, 189797, 189799, 189817, 189823, 189851, 189853, 189859, 189877, 189881, 189887, 189901, 189913, 189929, 189947, 189949, 189961, 189967, 189977, 189983, 189989, 189997, 190027, 190031, 190051, 190063, 190093, 190097, 190121, 190129, 190147, 190159, 190181, 190207, 190243, 190249, 190261, 190271, 190283, 190297, 190301, 190313, 190321, 190331, 190339, 190357, 190367, 190369, 190387, 190391, 190403, 190409, 190471, 190507, 190523, 190529, 190537, 190543, 190573, 190577, 190579, 190583, 190591, 190607, 190613, 190633, 190639, 190649, 190657, 190667, 190669, 190699, 190709, 190711, 190717, 190753, 190759, 190763, 190769, 190783, 190787, 190793, 190807, 190811, 190823, 190829, 190837, 190843, 190871, 190889, 190891, 190901, 190909, 190913, 190921, 190979, 190997, 191021, 191027, 191033, 191039, 191047, 191057, 191071, 191089, 191099, 191119, 191123, 191137, 191141, 191143, 191161, 191173, 191189, 191227, 191231, 191237, 191249, 191251, 191281, 191297, 191299, 191339, 191341, 191353, 191413, 191441, 191447, 191449, 191453, 191459, 191461, 191467, 191473, 191491, 191497, 191507, 191509, 191519, 191531, 191533, 191537, 191551, 191561, 191563, 191579, 191599, 191621, 191627, 191657, 191669, 191671, 191677, 191689, 191693, 191699, 191707, 191717, 191747, 191749, 191773, 191783, 191791, 191801, 191803, 191827, 191831, 191833, 191837, 191861, 191899, 191903, 191911, 191929, 191953, 191969, 191977, 191999, 192007, 192013, 192029, 192037, 192043, 192047, 192053, 192091, 192097, 192103, 192113, 192121, 192133, 192149, 192161, 192173, 192187, 192191, 192193, 192229, 192233, 192239, 192251, 192259, 192263, 192271, 192307, 192317, 192319, 192323, 192341, 192343, 192347, 192373, 192377, 192383, 192391, 192407, 192431, 192461, 192463, 192497, 192499, 192529, 192539, 192547, 192553, 192557, 192571, 192581, 192583, 192587, 192601, 192611, 192613, 192617, 192629, 192631, 192637, 192667, 192677, 192697, 192737, 192743, 192749, 192757, 192767, 192781, 192791, 192799, 192811, 192817, 192833, 192847, 192853, 192859, 192877, 192883, 192887, 192889, 192917, 192923, 192931, 192949, 192961, 192971, 192977, 192979, 192991, 193003, 193009, 193013, 193031, 193043, 193051, 193057, 193073, 193093, 193133, 193139, 193147, 193153, 193163, 193181, 193183, 193189, 193201, 193243, 193247, 193261, 193283, 193301, 193327, 193337, 193357, 193367, 193373, 193379, 193381, 193387, 193393, 193423, 193433, 193441, 193447, 193451, 193463, 193469, 193493, 193507, 193513, 193541, 193549, 193559, 193573, 193577, 193597, 193601, 193603, 193607, 193619, 193649, 193663, 193679, 193703, 193723, 193727, 193741, 193751, 193757, 193763, 193771, 193789, 193793, 193799, 193811, 193813, 193841, 193847, 193859, 193861, 193871, 193873, 193877, 193883, 193891, 193937, 193939, 193943, 193951, 193957, 193979, 193993, 194003, 194017, 194027, 194057, 194069, 194071, 194083, 194087, 194093, 194101, 194113, 194119, 194141, 194149, 194167, 194179, 194197, 194203, 194239, 194263, 194267, 194269, 194309, 194323, 194353, 194371, 194377, 194413, 194431, 194443, 194471, 194479, 194483, 194507, 194521, 194527, 194543, 194569, 194581, 194591, 194609, 194647, 194653, 194659, 194671, 194681, 194683, 194687, 194707, 194713, 194717, 194723, 194729, 194749, 194767, 194771, 194809, 194813, 194819, 194827, 194839, 194861, 194863, 194867, 194869, 194891, 194899, 194911, 194917, 194933, 194963, 194977, 194981, 194989, 195023, 195029, 195043, 195047, 195049, 195053, 195071, 195077, 195089, 195103, 195121, 195127, 195131, 195137, 195157, 195161, 195163, 195193, 195197, 195203, 195229, 195241, 195253, 195259, 195271, 195277, 195281, 195311, 195319, 195329, 195341, 195343, 195353, 195359, 195389, 195401, 195407, 195413, 195427, 195443, 195457, 195469, 195479, 195493, 195497, 195511, 195527, 195539, 195541, 195581, 195593, 195599, 195659, 195677, 195691, 195697, 195709, 195731, 195733, 195737, 195739, 195743, 195751, 195761, 195781, 195787, 195791, 195809, 195817, 195863, 195869, 195883, 195887, 195893, 195907, 195913, 195919, 195929, 195931, 195967, 195971, 195973, 195977, 195991, 195997, 196003, 196033, 196039, 196043, 196051, 196073, 196081, 196087, 196111, 196117, 196139, 196159, 196169, 196171, 196177, 196181, 196187, 196193, 196201, 196247, 196271, 196277, 196279, 196291, 196303, 196307, 196331, 196337, 196379, 196387, 196429, 196439, 196453, 196459, 196477, 196499, 196501, 196519, 196523, 196541, 196543, 196549, 196561, 196579, 196583, 196597, 196613, 196643, 196657, 196661, 196663, 196681, 196687, 196699, 196709, 196717, 196727, 196739, 196751, 196769, 196771, 196799, 196817, 196831, 196837, 196853, 196871, 196873, 196879, 196901, 196907, 196919, 196927, 196961, 196991, 196993, 197003, 197009, 197023, 197033, 197059, 197063, 197077, 197083, 197089, 197101, 197117, 197123, 197137, 197147, 197159, 197161, 197203, 197207, 197221, 197233, 197243, 197257, 197261, 197269, 197273, 197279, 197293, 197297, 197299, 197311, 197339, 197341, 197347, 197359, 197369, 197371, 197381, 197383, 197389, 197419, 197423, 197441, 197453, 197479, 197507, 197521, 197539, 197551, 197567, 197569, 197573, 197597, 197599, 197609, 197621, 197641, 197647, 197651, 197677, 197683, 197689, 197699, 197711, 197713, 197741, 197753, 197759, 197767, 197773, 197779, 197803, 197807, 197831, 197837, 197887, 197891, 197893, 197909, 197921, 197927, 197933, 197947, 197957, 197959, 197963, 197969, 197971, 198013, 198017, 198031, 198043, 198047, 198073, 198083, 198091, 198097, 198109, 198127, 198139, 198173, 198179, 198193, 198197, 198221, 198223, 198241, 198251, 198257, 198259, 198277, 198281, 198301, 198313, 198323, 198337, 198347, 198349, 198377, 198391, 198397, 198409, 198413, 198427, 198437, 198439, 198461, 198463, 198469, 198479, 198491, 198503, 198529, 198533, 198553, 198571, 198589, 198593, 198599, 198613, 198623, 198637, 198641, 198647, 198659, 198673, 198689, 198701, 198719, 198733, 198761, 198769, 198811, 198817, 198823, 198827, 198829, 198833, 198839, 198841, 198851, 198859, 198899, 198901, 198929, 198937, 198941, 198943, 198953, 198959, 198967, 198971, 198977, 198997, 199021, 199033, 199037, 199039, 199049, 199081, 199103, 199109, 199151, 199153, 199181, 199193, 199207, 199211, 199247, 199261, 199267, 199289, 199313, 199321, 199337, 199343, 199357, 199373, 199379, 199399, 199403, 199411, 199417, 199429, 199447, 199453, 199457, 199483, 199487, 199489, 199499, 199501, 199523, 199559, 199567, 199583, 199601, 199603, 199621, 199637, 199657, 199669, 199673, 199679, 199687, 199697, 199721, 199729, 199739, 199741, 199751, 199753, 199777, 199783, 199799, 199807, 199811, 199813, 199819, 199831, 199853, 199873, 199877, 199889, 199909, 199921, 199931, 199933, 199961, 199967, 199999, 200003, 200009, 200017, 200023, 200029, 200033, 200041, 200063, 200087, 200117, 200131, 200153, 200159, 200171, 200177, 200183, 200191, 200201, 200227, 200231, 200237, 200257, 200273, 200293, 200297, 200323, 200329, 200341, 200351, 200357, 200363, 200371, 200381, 200383, 200401, 200407, 200437, 200443, 200461, 200467, 200483, 200513, 200569, 200573, 200579, 200587, 200591, 200597, 200609, 200639, 200657, 200671, 200689, 200699, 200713, 200723, 200731, 200771, 200779, 200789, 200797, 200807, 200843, 200861, 200867, 200869, 200881, 200891, 200899, 200903, 200909, 200927, 200929, 200971, 200983, 200987, 200989, 201007, 201011, 201031, 201037, 201049, 201073, 201101, 201107, 201119, 201121, 201139, 201151, 201163, 201167, 201193, 201203, 201209, 201211, 201233, 201247, 201251, 201281, 201287, 201307, 201329, 201337, 201359, 201389, 201401, 201403, 201413, 201437, 201449, 201451, 201473, 201491, 201493, 201497, 201499, 201511, 201517, 201547, 201557, 201577, 201581, 201589, 201599, 201611, 201623, 201629, 201653, 201661, 201667, 201673, 201683, 201701, 201709, 201731, 201743, 201757, 201767, 201769, 201781, 201787, 201791, 201797, 201809, 201821, 201823, 201827, 201829, 201833, 201847, 201881, 201889, 201893, 201907, 201911, 201919, 201923, 201937, 201947, 201953, 201961, 201973, 201979, 201997, 202001, 202021, 202031, 202049, 202061, 202063, 202067, 202087, 202099, 202109, 202121, 202127, 202129, 202183, 202187, 202201, 202219, 202231, 202243, 202277, 202289, 202291, 202309, 202327, 202339, 202343, 202357, 202361, 202381, 202387, 202393, 202403, 202409, 202441, 202471, 202481, 202493, 202519, 202529, 202549, 202567, 202577, 202591, 202613, 202621, 202627, 202637, 202639, 202661, 202667, 202679, 202693, 202717, 202729, 202733, 202747, 202751, 202753, 202757, 202777, 202799, 202817, 202823, 202841, 202859, 202877, 202879, 202889, 202907, 202921, 202931, 202933, 202949, 202967, 202973, 202981, 202987, 202999, 203011, 203017, 203023, 203039, 203051, 203057, 203117, 203141, 203173, 203183, 203207, 203209, 203213, 203221, 203227, 203233, 203249, 203279, 203293, 203309, 203311, 203317, 203321, 203323, 203339, 203341, 203351, 203353, 203363, 203381, 203383, 203387, 203393, 203417, 203419, 203429, 203431, 203449, 203459, 203461, 203531, 203549, 203563, 203569, 203579, 203591, 203617, 203627, 203641, 203653, 203657, 203659, 203663, 203669, 203713, 203761, 203767, 203771, 203773, 203789, 203807, 203809, 203821, 203843, 203857, 203869, 203873, 203897, 203909, 203911, 203921, 203947, 203953, 203969, 203971, 203977, 203989, 203999, 204007, 204013, 204019, 204023, 204047, 204059, 204067, 204101, 204107, 204133, 204137, 204143, 204151, 204161, 204163, 204173, 204233, 204251, 204299, 204301, 204311, 204319, 204329, 204331, 204353, 204359, 204361, 204367, 204371, 204377, 204397, 204427, 204431, 204437, 204439, 204443, 204461, 204481, 204487, 204509, 204511, 204517, 204521, 204557, 204563, 204583, 204587, 204599, 204601, 204613, 204623, 204641, 204667, 204679, 204707, 204719, 204733, 204749, 204751, 204781, 204791, 204793, 204797, 204803, 204821, 204857, 204859, 204871, 204887, 204913, 204917, 204923, 204931, 204947, 204973, 204979, 204983, 205019, 205031, 205033, 205043, 205063, 205069, 205081, 205097, 205103, 205111, 205129, 205133, 205141, 205151, 205157, 205171, 205187, 205201, 205211, 205213, 205223, 205237, 205253, 205267, 205297, 205307, 205319, 205327, 205339, 205357, 205391, 205397, 205399, 205417, 205421, 205423, 205427, 205433, 205441, 205453, 205463, 205477, 205483, 205487, 205493, 205507, 205519, 205529, 205537, 205549, 205553, 205559, 205589, 205603, 205607, 205619, 205627, 205633, 205651, 205657, 205661, 205663, 205703, 205721, 205759, 205763, 205783, 205817, 205823, 205837, 205847, 205879, 205883, 205913, 205937, 205949, 205951, 205957, 205963, 205967, 205981, 205991, 205993, 206009, 206021, 206027, 206033, 206039, 206047, 206051, 206069, 206077, 206081, 206083, 206123, 206153, 206177, 206179, 206183, 206191, 206197, 206203, 206209, 206221, 206233, 206237, 206249, 206251, 206263, 206273, 206279, 206281, 206291, 206299, 206303, 206341, 206347, 206351, 206369, 206383, 206399, 206407, 206411, 206413, 206419, 206447, 206461, 206467, 206477, 206483, 206489, 206501, 206519, 206527, 206543, 206551, 206593, 206597, 206603, 206623, 206627, 206639, 206641, 206651, 206699, 206749, 206779, 206783, 206803, 206807, 206813, 206819, 206821, 206827, 206879, 206887, 206897, 206909, 206911, 206917, 206923, 206933, 206939, 206951, 206953, 206993, 207013, 207017, 207029, 207037, 207041, 207061, 207073, 207079, 207113, 207121, 207127, 207139, 207169, 207187, 207191, 207197, 207199, 207227, 207239, 207241, 207257, 207269, 207287, 207293, 207301, 207307, 207329, 207331, 207341, 207343, 207367, 207371, 207377, 207401, 207409, 207433, 207443, 207457, 207463, 207469, 207479, 207481, 207491, 207497, 207509, 207511, 207517, 207521, 207523, 207541, 207547, 207551, 207563, 207569, 207589, 207593, 207619, 207629, 207643, 207653, 207661, 207671, 207673, 207679, 207709, 207719, 207721, 207743, 207763, 207769, 207797, 207799, 207811, 207821, 207833, 207847, 207869, 207877, 207923, 207931, 207941, 207947, 207953, 207967, 207971, 207973, 207997, 208001, 208003, 208009, 208037, 208049, 208057, 208067, 208073, 208099, 208111, 208121, 208129, 208139, 208141, 208147, 208189, 208207, 208213, 208217, 208223, 208231, 208253, 208261, 208277, 208279, 208283, 208291, 208309, 208319, 208333, 208337, 208367, 208379, 208387, 208391, 208393, 208409, 208433, 208441, 208457, 208459, 208463, 208469, 208489, 208493, 208499, 208501, 208511, 208513, 208519, 208529, 208553, 208577, 208589, 208591, 208609, 208627, 208631, 208657, 208667, 208673, 208687, 208697, 208699, 208721, 208729, 208739, 208759, 208787, 208799, 208807, 208837, 208843, 208877, 208889, 208891, 208907, 208927, 208931, 208933, 208961, 208963, 208991, 208993, 208997, 209021, 209029, 209039, 209063, 209071, 209089, 209123, 209147, 209159, 209173, 209179, 209189, 209201, 209203, 209213, 209221, 209227, 209233, 209249, 209257, 209263, 209267, 209269, 209299, 209311, 209317, 209327, 209333, 209347, 209353, 209357, 209359, 209371, 209381, 209393, 209401, 209431, 209441, 209449, 209459, 209471, 209477, 209497, 209519, 209533, 209543, 209549, 209563, 209567, 209569, 209579, 209581, 209597, 209621, 209623, 209639, 209647, 209659, 209669, 209687, 209701, 209707, 209717, 209719, 209743, 209767, 209771, 209789, 209801, 209809, 209813, 209819, 209821, 209837, 209851, 209857, 209861, 209887, 209917, 209927, 209929, 209939, 209953, 209959, 209971, 209977, 209983, 209987, 210011, 210019, 210031, 210037, 210053, 210071, 210097, 210101, 210109, 210113, 210127, 210131, 210139, 210143, 210157, 210169, 210173, 210187, 210191, 210193, 210209, 210229, 210233, 210241, 210247, 210257, 210263, 210277, 210283, 210299, 210317, 210319, 210323, 210347, 210359, 210361, 210391, 210401, 210403, 210407, 210421, 210437, 210461, 210467, 210481, 210487, 210491, 210499, 210523, 210527, 210533, 210557, 210599, 210601, 210619, 210631, 210643, 210659, 210671, 210709, 210713, 210719, 210731, 210739, 210761, 210773, 210803, 210809, 210811, 210823, 210827, 210839, 210853, 210857, 210869, 210901, 210907, 210911, 210913, 210923, 210929, 210943, 210961, 210967, 211007, 211039, 211049, 211051, 211061, 211063, 211067, 211073, 211093, 211097, 211129, 211151, 211153, 211177, 211187, 211193, 211199, 211213, 211217, 211219, 211229, 211231, 211241, 211247, 211271, 211283, 211291, 211297, 211313, 211319, 211333, 211339, 211349, 211369, 211373, 211403, 211427, 211433, 211441, 211457, 211469, 211493, 211499, 211501, 211507, 211543, 211559, 211571, 211573, 211583, 211597, 211619, 211639, 211643, 211657, 211661, 211663, 211681, 211691, 211693, 211711, 211723, 211727, 211741, 211747, 211777, 211781, 211789, 211801, 211811, 211817, 211859, 211867, 211873, 211877, 211879, 211889, 211891, 211927, 211931, 211933, 211943, 211949, 211969, 211979, 211997, 212029, 212039, 212057, 212081, 212099, 212117, 212123, 212131, 212141, 212161, 212167, 212183, 212203, 212207, 212209, 212227, 212239, 212243, 212281, 212293, 212297, 212353, 212369, 212383, 212411, 212419, 212423, 212437, 212447, 212453, 212461, 212467, 212479, 212501, 212507, 212557, 212561, 212573, 212579, 212587, 212593, 212627, 212633, 212651, 212669, 212671, 212677, 212683, 212701, 212777, 212791, 212801, 212827, 212837, 212843, 212851, 212867, 212869, 212873, 212881, 212897, 212903, 212909, 212917, 212923, 212969, 212981, 212987, 212999, 213019, 213023, 213029, 213043, 213067, 213079, 213091, 213097, 213119, 213131, 213133, 213139, 213149, 213173, 213181, 213193, 213203, 213209, 213217, 213223, 213229, 213247, 213253, 213263, 213281, 213287, 213289, 213307, 213319, 213329, 213337, 213349, 213359, 213361, 213383, 213391, 213397, 213407, 213449, 213461, 213467, 213481, 213491, 213523, 213533, 213539, 213553, 213557, 213589, 213599, 213611, 213613, 213623, 213637, 213641, 213649, 213659, 213713, 213721, 213727, 213737, 213751, 213791, 213799, 213821, 213827, 213833, 213847, 213859, 213881, 213887, 213901, 213919, 213929, 213943, 213947, 213949, 213953, 213973, 213977, 213989, 214003, 214007, 214009, 214021, 214031, 214033, 214043, 214051, 214063, 214069, 214087, 214091, 214129, 214133, 214141, 214147, 214163, 214177, 214189, 214211, 214213, 214219, 214237, 214243, 214259, 214283, 214297, 214309, 214351, 214363, 214373, 214381, 214391, 214399, 214433, 214439, 214451, 214457, 214463, 214469, 214481, 214483, 214499, 214507, 214517, 214519, 214531, 214541, 214559, 214561, 214589, 214603, 214607, 214631, 214639, 214651, 214657, 214663, 214667, 214673, 214691, 214723, 214729, 214733, 214741, 214759, 214763, 214771, 214783, 214787, 214789, 214807, 214811, 214817, 214831, 214849, 214853, 214867, 214883, 214891, 214913, 214939, 214943, 214967, 214987, 214993, 215051, 215063, 215077, 215087, 215123, 215141, 215143, 215153, 215161, 215179, 215183, 215191, 215197, 215239, 215249, 215261, 215273, 215279, 215297, 215309, 215317, 215329, 215351, 215353, 215359, 215381, 215389, 215393, 215399, 215417, 215443, 215447, 215459, 215461, 215471, 215483, 215497, 215503, 215507, 215521, 215531, 215563, 215573, 215587, 215617, 215653, 215659, 215681, 215687, 215689, 215693, 215723, 215737, 215753, 215767, 215771, 215797, 215801, 215827, 215833, 215843, 215851, 215857, 215863, 215893, 215899, 215909, 215921, 215927, 215939, 215953, 215959, 215981, 215983, 216023, 216037, 216061, 216071, 216091, 216103, 216107, 216113, 216119, 216127, 216133, 216149, 216157, 216173, 216179, 216211, 216217, 216233, 216259, 216263, 216289, 216317, 216319, 216329, 216347, 216371, 216373, 216379, 216397, 216401, 216421, 216431, 216451, 216481, 216493, 216509, 216523, 216551, 216553, 216569, 216571, 216577, 216607, 216617, 216641, 216647, 216649, 216653, 216661, 216679, 216703, 216719, 216731, 216743, 216751, 216757, 216761, 216779, 216781, 216787, 216791, 216803, 216829, 216841, 216851, 216859, 216877, 216899, 216901, 216911, 216917, 216919, 216947, 216967, 216973, 216991, 217001, 217003, 217027, 217033, 217057, 217069, 217081, 217111, 217117, 217121, 217157, 217163, 217169, 217199, 217201, 217207, 217219, 217223, 217229, 217241, 217253, 217271, 217307, 217309, 217313, 217319, 217333, 217337, 217339, 217351, 217361, 217363, 217367, 217369, 217387, 217397, 217409, 217411, 217421, 217429, 217439, 217457, 217463, 217489, 217499, 217517, 217519, 217559, 217561, 217573, 217577, 217579, 217619, 217643, 217661, 217667, 217681, 217687, 217691, 217697, 217717, 217727, 217733, 217739, 217747, 217771, 217781, 217793, 217823, 217829, 217849, 217859, 217901, 217907, 217909, 217933, 217937, 217969, 217979, 217981, 218003, 218021, 218047, 218069, 218077, 218081, 218083, 218087, 218107, 218111, 218117, 218131, 218137, 218143, 218149, 218171, 218191, 218213, 218227, 218233, 218249, 218279, 218287, 218357, 218363, 218371, 218381, 218389, 218401, 218417, 218419, 218423, 218437, 218447, 218453, 218459, 218461, 218479, 218509, 218513, 218521, 218527, 218531, 218549, 218551, 218579, 218591, 218599, 218611, 218623, 218627, 218629, 218641, 218651, 218657, 218677, 218681, 218711, 218717, 218719, 218723, 218737, 218749, 218761, 218783, 218797, 218809, 218819, 218833, 218839, 218843, 218849, 218857, 218873, 218887, 218923, 218941, 218947, 218963, 218969, 218971, 218987, 218989, 218993, 219001, 219017, 219019, 219031, 219041, 219053, 219059, 219071, 219083, 219091, 219097, 219103, 219119, 219133, 219143, 219169, 219187, 219217, 219223, 219251, 219277, 219281, 219293, 219301, 219311, 219313, 219353, 219361, 219371, 219377, 219389, 219407, 219409, 219433, 219437, 219451, 219463, 219467, 219491, 219503, 219517, 219523, 219529, 219533, 219547, 219577, 219587, 219599, 219607, 219613, 219619, 219629, 219647, 219649, 219677, 219679, 219683, 219689, 219707, 219721, 219727, 219731, 219749, 219757, 219761, 219763, 219767, 219787, 219797, 219799, 219809, 219823, 219829, 219839, 219847, 219851, 219871, 219881, 219889, 219911, 219917, 219931, 219937, 219941, 219943, 219953, 219959, 219971, 219977, 219979, 219983, 220009, 220013, 220019, 220021, 220057, 220063, 220123, 220141, 220147, 220151, 220163, 220169, 220177, 220189, 220217, 220243, 220279, 220291, 220301, 220307, 220327, 220333, 220351, 220357, 220361, 220369, 220373, 220391, 220399, 220403, 220411, 220421, 220447, 220469, 220471, 220511, 220513, 220529, 220537, 220543, 220553, 220559, 220573, 220579, 220589, 220613, 220663, 220667, 220673, 220681, 220687, 220699, 220709, 220721, 220747, 220757, 220771, 220783, 220789, 220793, 220807, 220811, 220841, 220859, 220861, 220873, 220877, 220879, 220889, 220897, 220901, 220903, 220907, 220919, 220931, 220933, 220939, 220973, 221021, 221047, 221059, 221069, 221071, 221077, 221083, 221087, 221093, 221101, 221159, 221171, 221173, 221197, 221201, 221203, 221209, 221219, 221227, 221233, 221239, 221251, 221261, 221281, 221303, 221311, 221317, 221327, 221393, 221399, 221401, 221411, 221413, 221447, 221453, 221461, 221471, 221477, 221489, 221497, 221509, 221537, 221539, 221549, 221567, 221581, 221587, 221603, 221621, 221623, 221653, 221657, 221659, 221671, 221677, 221707, 221713, 221717, 221719, 221723, 221729, 221737, 221747, 221773, 221797, 221807, 221813, 221827, 221831, 221849, 221873, 221891, 221909, 221941, 221951, 221953, 221957, 221987, 221989, 221999, 222007, 222011, 222023, 222029, 222041, 222043, 222059, 222067, 222073, 222107, 222109, 222113, 222127, 222137, 222149, 222151, 222161, 222163, 222193, 222197, 222199, 222247, 222269, 222289, 222293, 222311, 222317, 222323, 222329, 222337, 222347, 222349, 222361, 222367, 222379, 222389, 222403, 222419, 222437, 222461, 222493, 222499, 222511, 222527, 222533, 222553, 222557, 222587, 222601, 222613, 222619, 222643, 222647, 222659, 222679, 222707, 222713, 222731, 222773, 222779, 222787, 222791, 222793, 222799, 222823, 222839, 222841, 222857, 222863, 222877, 222883, 222913, 222919, 222931, 222941, 222947, 222953, 222967, 222977, 222979, 222991, 223007, 223009, 223019, 223037, 223049, 223051, 223061, 223063, 223087, 223099, 223103, 223129, 223133, 223151, 223207, 223211, 223217, 223219, 223229, 223241, 223243, 223247, 223253, 223259, 223273, 223277, 223283, 223291, 223303, 223313, 223319, 223331, 223337, 223339, 223361, 223367, 223381, 223403, 223423, 223429, 223439, 223441, 223463, 223469, 223481, 223493, 223507, 223529, 223543, 223547, 223549, 223577, 223589, 223621, 223633, 223637, 223667, 223679, 223681, 223697, 223711, 223747, 223753, 223757, 223759, 223781, 223823, 223829, 223831, 223837, 223841, 223843, 223849, 223903, 223919, 223921, 223939, 223963, 223969, 223999, 224011, 224027, 224033, 224041, 224047, 224057, 224069, 224071, 224101, 224113, 224129, 224131, 224149, 224153, 224171, 224177, 224197, 224201, 224209, 224221, 224233, 224239, 224251, 224261, 224267, 224291, 224299, 224303, 224309, 224317, 224327, 224351, 224359, 224363, 224401, 224423, 224429, 224443, 224449, 224461, 224467, 224473, 224491, 224501, 224513, 224527, 224563, 224569, 224579, 224591, 224603, 224611, 224617, 224629, 224633, 224669, 224677, 224683, 224699, 224711, 224717, 224729, 224737, 224743, 224759, 224771, 224797, 224813, 224831, 224863, 224869, 224881, 224891, 224897, 224909, 224911, 224921, 224929, 224947, 224951, 224969, 224977, 224993, 225023, 225037, 225061, 225067, 225077, 225079, 225089, 225109, 225119, 225133, 225143, 225149, 225157, 225161, 225163, 225167, 225217, 225221, 225223, 225227, 225241, 225257, 225263, 225287, 225289, 225299, 225307, 225341, 225343, 225347, 225349, 225353, 225371, 225373, 225383, 225427, 225431, 225457, 225461, 225479, 225493, 225499, 225503, 225509, 225523, 225527, 225529, 225569, 225581, 225583, 225601, 225611, 225613, 225619, 225629, 225637, 225671, 225683, 225689, 225697, 225721, 225733, 225749, 225751, 225767, 225769, 225779, 225781, 225809, 225821, 225829, 225839, 225859, 225871, 225889, 225919, 225931, 225941, 225943, 225949, 225961, 225977, 225983, 225989, 226001, 226007, 226013, 226027, 226063, 226087, 226099, 226103, 226123, 226129, 226133, 226141, 226169, 226183, 226189, 226199, 226201, 226217, 226231, 226241, 226267, 226283, 226307, 226313, 226337, 226357, 226367, 226379, 226381, 226397, 226409, 226427, 226433, 226451, 226453, 226463, 226483, 226487, 226511, 226531, 226547, 226549, 226553, 226571, 226601, 226609, 226621, 226631, 226637, 226643, 226649, 226657, 226663, 226669, 226691, 226697, 226741, 226753, 226769, 226777, 226783, 226789, 226799, 226813, 226817, 226819, 226823, 226843, 226871, 226901, 226903, 226907, 226913, 226937, 226943, 226991, 227011, 227027, 227053, 227081, 227089, 227093, 227111, 227113, 227131, 227147, 227153, 227159, 227167, 227177, 227189, 227191, 227207, 227219, 227231, 227233, 227251, 227257, 227267, 227281, 227299, 227303, 227363, 227371, 227377, 227387, 227393, 227399, 227407, 227419, 227431, 227453, 227459, 227467, 227471, 227473, 227489, 227497, 227501, 227519, 227531, 227533, 227537, 227561, 227567, 227569, 227581, 227593, 227597, 227603, 227609, 227611, 227627, 227629, 227651, 227653, 227663, 227671, 227693, 227699, 227707, 227719, 227729, 227743, 227789, 227797, 227827, 227849, 227869, 227873, 227893, 227947, 227951, 227977, 227989, 227993, 228013, 228023, 228049, 228061, 228077, 228097, 228103, 228113, 228127, 228131, 228139, 228181, 228197, 228199, 228203, 228211, 228223, 228233, 228251, 228257, 228281, 228299, 228301, 228307, 228311, 228331, 228337, 228341, 228353, 228359, 228383, 228409, 228419, 228421, 228427, 228443, 228451, 228457, 228461, 228469, 228479, 228509, 228511, 228517, 228521, 228523, 228539, 228559, 228577, 228581, 228587, 228593, 228601, 228611, 228617, 228619, 228637, 228647, 228677, 228707, 228713, 228731, 228733, 228737, 228751, 228757, 228773, 228793, 228797, 228799, 228829, 228841, 228847, 228853, 228859, 228869, 228881, 228883, 228887, 228901, 228911, 228913, 228923, 228929, 228953, 228959, 228961, 228983, 228989, 229003, 229027, 229037, 229081, 229093, 229123, 229127, 229133, 229139, 229153, 229157, 229171, 229181, 229189, 229199, 229213, 229217, 229223, 229237, 229247, 229249, 229253, 229261, 229267, 229283, 229309, 229321, 229343, 229351, 229373, 229393, 229399, 229403, 229409, 229423, 229433, 229459, 229469, 229487, 229499, 229507, 229519, 229529, 229547, 229549, 229553, 229561, 229583, 229589, 229591, 229601, 229613, 229627, 229631, 229637, 229639, 229681, 229693, 229699, 229703, 229711, 229717, 229727, 229739, 229751, 229753, 229759, 229763, 229769, 229771, 229777, 229781, 229799, 229813, 229819, 229837, 229841, 229847, 229849, 229897, 229903, 229937, 229939, 229949, 229961, 229963, 229979, 229981, 230003, 230017, 230047, 230059, 230063, 230077, 230081, 230089, 230101, 230107, 230117, 230123, 230137, 230143, 230149, 230189, 230203, 230213, 230221, 230227, 230233, 230239, 230257, 230273, 230281, 230291, 230303, 230309, 230311, 230327, 230339, 230341, 230353, 230357, 230369, 230383, 230387, 230389, 230393, 230431, 230449, 230453, 230467, 230471, 230479, 230501, 230507, 230539, 230551, 230561, 230563, 230567, 230597, 230611, 230647, 230653, 230663, 230683, 230693, 230719, 230729, 230743, 230761, 230767, 230771, 230773, 230779, 230807, 230819, 230827, 230833, 230849, 230861, 230863, 230873, 230891, 230929, 230933, 230939, 230941, 230959, 230969, 230977, 230999, 231001, 231017, 231019, 231031, 231041, 231053, 231067, 231079, 231107, 231109, 231131, 231169, 231197, 231223, 231241, 231269, 231271, 231277, 231289, 231293, 231299, 231317, 231323, 231331, 231347, 231349, 231359, 231367, 231379, 231409, 231419, 231431, 231433, 231443, 231461, 231463, 231479, 231481, 231493, 231503, 231529, 231533, 231547, 231551, 231559, 231563, 231571, 231589, 231599, 231607, 231611, 231613, 231631, 231643, 231661, 231677, 231701, 231709, 231719, 231779, 231799, 231809, 231821, 231823, 231827, 231839, 231841, 231859, 231871, 231877, 231893, 231901, 231919, 231923, 231943, 231947, 231961, 231967, 232003, 232007, 232013, 232049, 232051, 232073, 232079, 232081, 232091, 232103, 232109, 232117, 232129, 232153, 232171, 232187, 232189, 232207, 232217, 232259, 232303, 232307, 232333, 232357, 232363, 232367, 232381, 232391, 232409, 232411, 232417, 232433, 232439, 232451, 232457, 232459, 232487, 232499, 232513, 232523, 232549, 232567, 232571, 232591, 232597, 232607, 232621, 232633, 232643, 232663, 232669, 232681, 232699, 232709, 232711, 232741, 232751, 232753, 232777, 232801, 232811, 232819, 232823, 232847, 232853, 232861, 232871, 232877, 232891, 232901, 232907, 232919, 232937, 232961, 232963, 232987, 233021, 233069, 233071, 233083, 233113, 233117, 233141, 233143, 233159, 233161, 233173, 233183, 233201, 233221, 233231, 233239, 233251, 233267, 233279, 233293, 233297, 233323, 233327, 233329, 233341, 233347, 233353, 233357, 233371, 233407, 233417, 233419, 233423, 233437, 233477, 233489, 233509, 233549, 233551, 233557, 233591, 233599, 233609, 233617, 233621, 233641, 233663, 233669, 233683, 233687, 233689, 233693, 233713, 233743, 233747, 233759, 233777, 233837, 233851, 233861, 233879, 233881, 233911, 233917, 233921, 233923, 233939, 233941, 233969, 233983, 233993, 234007, 234029, 234043, 234067, 234083, 234089, 234103, 234121, 234131, 234139, 234149, 234161, 234167, 234181, 234187, 234191, 234193, 234197, 234203, 234211, 234217, 234239, 234259, 234271, 234281, 234287, 234293, 234317, 234319, 234323, 234331, 234341, 234343, 234361, 234383, 234431, 234457, 234461, 234463, 234467, 234473, 234499, 234511, 234527, 234529, 234539, 234541, 234547, 234571, 234587, 234589, 234599, 234613, 234629, 234653, 234659, 234673, 234683, 234713, 234721, 234727, 234733, 234743, 234749, 234769, 234781, 234791, 234799, 234803, 234809, 234811, 234833, 234847, 234851, 234863, 234869, 234893, 234907, 234917, 234931, 234947, 234959, 234961, 234967, 234977, 234979, 234989, 235003, 235007, 235009, 235013, 235043, 235051, 235057, 235069, 235091, 235099, 235111, 235117, 235159, 235171, 235177, 235181, 235199, 235211, 235231, 235241, 235243, 235273, 235289, 235307, 235309, 235337, 235349, 235369, 235397, 235439, 235441, 235447, 235483, 235489, 235493, 235513, 235519, 235523, 235537, 235541, 235553, 235559, 235577, 235591, 235601, 235607, 235621, 235661, 235663, 235673, 235679, 235699, 235723, 235747, 235751, 235783, 235787, 235789, 235793, 235811, 235813, 235849, 235871, 235877, 235889, 235891, 235901, 235919, 235927, 235951, 235967, 235979, 235997, 236017, 236021, 236053, 236063, 236069, 236077, 236087, 236107, 236111, 236129, 236143, 236153, 236167, 236207, 236209, 236219, 236231, 236261, 236287, 236293, 236297, 236323, 236329, 236333, 236339, 236377, 236381, 236387, 236399, 236407, 236429, 236449, 236461, 236471, 236477, 236479, 236503, 236507, 236519, 236527, 236549, 236563, 236573, 236609, 236627, 236641, 236653, 236659, 236681, 236699, 236701, 236707, 236713, 236723, 236729, 236737, 236749, 236771, 236773, 236779, 236783, 236807, 236813, 236867, 236869, 236879, 236881, 236891, 236893, 236897, 236909, 236917, 236947, 236981, 236983, 236993, 237011, 237019, 237043, 237053, 237067, 237071, 237073, 237089, 237091, 237137, 237143, 237151, 237157, 237161, 237163, 237173, 237179, 237203, 237217, 237233, 237257, 237271, 237277, 237283, 237287, 237301, 237313, 237319, 237331, 237343, 237361, 237373, 237379, 237401, 237409, 237467, 237487, 237509, 237547, 237563, 237571, 237581, 237607, 237619, 237631, 237673, 237683, 237689, 237691, 237701, 237707, 237733, 237737, 237749, 237763, 237767, 237781, 237791, 237821, 237851, 237857, 237859, 237877, 237883, 237901, 237911, 237929, 237959, 237967, 237971, 237973, 237977, 237997, 238001, 238009, 238019, 238031, 238037, 238039, 238079, 238081, 238093, 238099, 238103, 238109, 238141, 238151, 238157, 238159, 238163, 238171, 238181, 238201, 238207, 238213, 238223, 238229, 238237, 238247, 238261, 238267, 238291, 238307, 238313, 238321, 238331, 238339, 238361, 238363, 238369, 238373, 238397, 238417, 238423, 238439, 238451, 238463, 238471, 238477, 238481, 238499, 238519, 238529, 238531, 238547, 238573, 238591, 238627, 238639, 238649, 238657, 238673, 238681, 238691, 238703, 238709, 238723, 238727, 238729, 238747, 238759, 238781, 238789, 238801, 238829, 238837, 238841, 238853, 238859, 238877, 238879, 238883, 238897, 238919, 238921, 238939, 238943, 238949, 238967, 238991, 239017, 239023, 239027, 239053, 239069, 239081, 239087, 239119, 239137, 239147, 239167, 239171, 239179, 239201, 239231, 239233, 239237, 239243, 239251, 239263, 239273, 239287, 239297, 239329, 239333, 239347, 239357, 239383, 239387, 239389, 239417, 239423, 239429, 239431, 239441, 239461, 239489, 239509, 239521, 239527, 239531, 239539, 239543, 239557, 239567, 239579, 239587, 239597, 239611, 239623, 239633, 239641, 239671, 239689, 239699, 239711, 239713, 239731, 239737, 239753, 239779, 239783, 239803, 239807, 239831, 239843, 239849, 239851, 239857, 239873, 239879, 239893, 239929, 239933, 239947, 239957, 239963, 239977, 239999, 240007, 240011, 240017, 240041, 240043, 240047, 240049, 240059, 240073, 240089, 240101, 240109, 240113, 240131, 240139, 240151, 240169, 240173, 240197, 240203, 240209, 240257, 240259, 240263, 240271, 240283, 240287, 240319, 240341, 240347, 240349, 240353, 240371, 240379, 240421, 240433, 240437, 240473, 240479, 240491, 240503, 240509, 240517, 240551, 240571, 240587, 240589, 240599, 240607, 240623, 240631, 240641, 240659, 240677, 240701, 240707, 240719, 240727, 240733, 240739, 240743, 240763, 240769, 240797, 240811, 240829, 240841, 240853, 240859, 240869, 240881, 240883, 240893, 240899, 240913, 240943, 240953, 240959, 240967, 240997, 241013, 241027, 241037, 241049, 241051, 241061, 241067, 241069, 241079, 241093, 241117, 241127, 241141, 241169, 241177, 241183, 241207, 241229, 241249, 241253, 241259, 241261, 241271, 241291, 241303, 241313, 241321, 241327, 241333, 241337, 241343, 241361, 241363, 241391, 241393, 241421, 241429, 241441, 241453, 241463, 241469, 241489, 241511, 241513, 241517, 241537, 241543, 241559, 241561, 241567, 241589, 241597, 241601, 241603, 241639, 241643, 241651, 241663, 241667, 241679, 241687, 241691, 241711, 241727, 241739, 241771, 241781, 241783, 241793, 241807, 241811, 241817, 241823, 241847, 241861, 241867, 241873, 241877, 241883, 241903, 241907, 241919, 241921, 241931, 241939, 241951, 241963, 241973, 241979, 241981, 241993, 242009, 242057, 242059, 242069, 242083, 242093, 242101, 242119, 242129, 242147, 242161, 242171, 242173, 242197, 242201, 242227, 242243, 242257, 242261, 242273, 242279, 242309, 242329, 242357, 242371, 242377, 242393, 242399, 242413, 242419, 242441, 242447, 242449, 242453, 242467, 242479, 242483, 242491, 242509, 242519, 242521, 242533, 242551, 242591, 242603, 242617, 242621, 242629, 242633, 242639, 242647, 242659, 242677, 242681, 242689, 242713, 242729, 242731, 242747, 242773, 242779, 242789, 242797, 242807, 242813, 242819, 242863, 242867, 242873, 242887, 242911, 242923, 242927, 242971, 242989, 242999, 243011, 243031, 243073, 243077, 243091, 243101, 243109, 243119, 243121, 243137, 243149, 243157, 243161, 243167, 243197, 243203, 243209, 243227, 243233, 243239, 243259, 243263, 243301, 243311, 243343, 243367, 243391, 243401, 243403, 243421, 243431, 243433, 243437, 243461, 243469, 243473, 243479, 243487, 243517, 243521, 243527, 243533, 243539, 243553, 243577, 243583, 243587, 243589, 243613, 243623, 243631, 243643, 243647, 243671, 243673, 243701, 243703, 243707, 243709, 243769, 243781, 243787, 243799, 243809, 243829, 243839, 243851, 243857, 243863, 243871, 243889, 243911, 243917, 243931, 243953, 243973, 243989, 244003, 244009, 244021, 244033, 244043, 244087, 244091, 244109, 244121, 244129, 244141, 244147, 244157, 244159, 244177, 244199, 244217, 244219, 244243, 244247, 244253, 244261, 244291, 244297, 244301, 244303, 244313, 244333, 244339, 244351, 244357, 244367, 244379, 244381, 244393, 244399, 244403, 244411, 244423, 244429, 244451, 244457, 244463, 244471, 244481, 244493, 244507, 244529, 244547, 244553, 244561, 244567, 244583, 244589, 244597, 244603, 244619, 244633, 244637, 244639, 244667, 244669, 244687, 244691, 244703, 244711, 244721, 244733, 244747, 244753, 244759, 244781, 244787, 244813, 244837, 244841, 244843, 244859, 244861, 244873, 244877, 244889, 244897, 244901, 244939, 244943, 244957, 244997, 245023, 245029, 245033, 245039, 245071, 245083, 245087, 245107, 245129, 245131, 245149, 245171, 245173, 245177, 245183, 245209, 245251, 245257, 245261, 245269, 245279, 245291, 245299, 245317, 245321, 245339, 245383, 245389, 245407, 245411, 245417, 245419, 245437, 245471, 245473, 245477, 245501, 245513, 245519, 245521, 245527, 245533, 245561, 245563, 245587, 245591, 245593, 245621, 245627, 245629, 245639, 245653, 245671, 245681, 245683, 245711, 245719, 245723, 245741, 245747, 245753, 245759, 245771, 245783, 245789, 245821, 245849, 245851, 245863, 245881, 245897, 245899, 245909, 245911, 245941, 245963, 245977, 245981, 245983, 245989, 246011, 246017, 246049, 246073, 246097, 246119, 246121, 246131, 246133, 246151, 246167, 246173, 246187, 246193, 246203, 246209, 246217, 246223, 246241, 246247, 246251, 246271, 246277, 246289, 246317, 246319, 246329, 246343, 246349, 246361, 246371, 246391, 246403, 246439, 246469, 246473, 246497, 246509, 246511, 246523, 246527, 246539, 246557, 246569, 246577, 246599, 246607, 246611, 246613, 246637, 246641, 246643, 246661, 246683, 246689, 246707, 246709, 246713, 246731, 246739, 246769, 246773, 246781, 246787, 246793, 246803, 246809, 246811, 246817, 246833, 246839, 246889, 246899, 246907, 246913, 246919, 246923, 246929, 246931, 246937, 246941, 246947, 246971, 246979, 247001, 247007, 247031, 247067, 247069, 247073, 247087, 247099, 247141, 247183, 247193, 247201, 247223, 247229, 247241, 247249, 247259, 247279, 247301, 247309, 247337, 247339, 247343, 247363, 247369, 247381, 247391, 247393, 247409, 247421, 247433, 247439, 247451, 247463, 247501, 247519, 247529, 247531, 247547, 247553, 247579, 247591, 247601, 247603, 247607, 247609, 247613, 247633, 247649, 247651, 247691, 247693, 247697, 247711, 247717, 247729, 247739, 247759, 247769, 247771, 247781, 247799, 247811, 247813, 247829, 247847, 247853, 247873, 247879, 247889, 247901, 247913, 247939, 247943, 247957, 247991, 247993, 247997, 247999, 248021, 248033, 248041, 248051, 248057, 248063, 248071, 248077, 248089, 248099, 248117, 248119, 248137, 248141, 248161, 248167, 248177, 248179, 248189, 248201, 248203, 248231, 248243, 248257, 248267, 248291, 248293, 248299, 248309, 248317, 248323, 248351, 248357, 248371, 248389, 248401, 248407, 248431, 248441, 248447, 248461, 248473, 248477, 248483, 248509, 248533, 248537, 248543, 248569, 248579, 248587, 248593, 248597, 248609, 248621, 248627, 248639, 248641, 248657, 248683, 248701, 248707, 248719, 248723, 248737, 248749, 248753, 248779, 248783, 248789, 248797, 248813, 248821, 248827, 248839, 248851, 248861, 248867, 248869, 248879, 248887, 248891, 248893, 248903, 248909, 248971, 248981, 248987, 249017, 249037, 249059, 249079, 249089, 249097, 249103, 249107, 249127, 249131, 249133, 249143, 249181, 249187, 249199, 249211, 249217, 249229, 249233, 249253, 249257, 249287, 249311, 249317, 249329, 249341, 249367, 249377, 249383, 249397, 249419, 249421, 249427, 249433, 249437, 249439, 249449, 249463, 249497, 249499, 249503, 249517, 249521, 249533, 249539, 249541, 249563, 249583, 249589, 249593, 249607, 249647, 249659, 249671, 249677, 249703, 249721, 249727, 249737, 249749, 249763, 249779, 249797, 249811, 249827, 249833, 249853, 249857, 249859, 249863, 249871, 249881, 249911, 249923, 249943, 249947, 249967, 249971, 249973, 249989]\nfunction solve(a,b){\n  return primes.join``.slice(a,a+b)\n}\n"
  },
  {
    "path": "Simple string indices.js",
    "content": "/*\nDescription:\nIn this Kata, you will be given a string with brackets and an index of an opening bracket and your task will be to return the index of the matching closing bracket. Both the input and returned index are 0-based except in Fortran where it is 1-based. An opening brace will always have a closing brace. Return -1 if there is no answer (in Haskell, return Nothing; in Fortran, return 0; in Go, return an error)\n\nExamples\nsolve(\"((1)23(45))(aB)\", 0) = 10 // the opening brace at index 0 matches the closing brace at index 10\nsolve(\"((1)23(45))(aB)\", 1) = 3 \nsolve(\"((1)23(45))(aB)\", 2) = -1 // there is no opening bracket at index 2, so return -1\nsolve(\"((1)23(45))(aB)\", 6) = 9\nsolve(\"((1)23(45))(aB)\", 11) = 14\nsolve(\"((>)|?(*'))(yZ)\", 11) = 14\nInput will consist of letters, numbers and special characters, but no spaces. The only brackets will be ( and ).\n\nMore examples in the test cases.\n\nGood luck!\n*/\nfunction solve(str,idx){\n if (str[idx]!=='(') return -1\n let count=1;\n for (let i=idx+1;i<str.length;i++){\n if (str[i]==='('){\n count++\n }\n if (str[i]===')'){\n count--\n }\n if (count===0){\n return i\n }}\n}\n"
  },
  {
    "path": "Simple sum of pairs.js",
    "content": "/*\nDescription:\nGiven an integer n, find two integers a and b such that:\n\nA) a >= 0 and b >= 0\nB) a + b = n\nC) DigitSum(a) + Digitsum(b) is maximum of all possibilities.\nYou will return the digitSum(a) + digitsum(b).\n\nFor example:\nsolve(29) = 11. If we take 15 + 14 = 29 and digitSum = 1 + 5 + 1 + 4 = 11. There is no larger outcome.\nn will not exceed 10e10.\n\nMore examples in test cases.\n\nGood luck!\n*/\n\nfunction solve(n) {\n  let str = n + '',\n      a = '9'.repeat(str.length - 1)*1,\n      b = n - a\n  return ('' + a + b).split('').reduce((c, d) => +c + +d)\n}\n"
  },
  {
    "path": "Simple transposition.js",
    "content": "/*\nDescription:\nSimple transposition is a basic and simple cryptography technique. We make 2 rows and put first a letter in the Row 1, the second in the Row 2, third in Row 1 and so on until the end. Then we put the text from Row 2 next to the Row 1 text and thats it.\n\nComplete the function that recieves a string and encrypt it with this simple transposition.\n\nExample\nFor example if the text to encrypt is: \"Simple text\", the 2 rows will be:\n\nRow 1\tS\tm\tl\t\te\tt\nRow 2\ti\tp\te\tt\tx\t\n\nSo the result string will be: `\"Sml etipetx\"`\n*/\nfunction simpleTransposition(text) {\n  const row1=[];\n  const row2=[];\n  text.split(``).map((v,i)=>i%2===0?row1.push(v):row2.push(v))\n  return row1.join(``)+row2.join(``)\n}\n"
  },
  {
    "path": "Simpson's Rule - Approximate Integration.js",
    "content": "/*\nDescription:\nAn integral:\n\n\\int_{a}^{b}f(x)dx\n\ncan be approximated by the so-called Simpson’s rule:\n\n \\frac{b-a}{3n}(f(a)+f(b)+4\\sum_{i=1}^{n/2}f(a+(2i-1)h)+2\\sum_{i=1}^{n/2-1}f(a+2ih))\n\nHere h = (b-a)/n, n being an even integer and a <= b. We want to try Simpson's rule with the function f:\n\nf(x) = \\frac{3}{2}sin^3x\n\nThe task is to write a function called simpson with parameter n which returns the value of the integral of f on the interval  \\left [ \\right 0,\\pi\\left \\right ] .\n\nDon't round or truncate your results. See in \"RUN EXAMPLES\" the function assertFuzzyEquals or testing. n will always be even.\n\nNote: we know that the exact value of the integral of f on the given interval is 2.\n\nYou can see: http://www.codewars.com/kata/5562ab5d6dca8009f7000050/train/javascript about rectangle method and trapezoidal rule.\n*/\nfunction simpson(n) {\n    let a  = 0\n    let b = Math.PI\n    let f =(x)=>{\n        return 3 * Math.pow(Math.sin(x), 3) / 2\n    }\n    let res1= 0.0, res2 = 0.0;\n    var h = (b-a)/(n)\n    for (let i = 1; i <= n/2; i++) {\n        res1 += f(a + (2*i-1)*h)\n    }\n    for (let i= 1; i <= n/2-1; i++) {\n        res2 += f(a + 2*(i)*h)\n    }\n\n    return (b-a)*(f(a) + f(b) + 4*res1 + 2*res2)/3.0/(n)\n}\n"
  },
  {
    "path": "Single Word Pig Latin.js",
    "content": "/*\nPig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules.\n\nThe rules themselves are rather easy:\n\n1) The word starts with a vowel(a,e,i,o,u) -> return the original string plus \"way\".\n\n2) The word starts with a consonant -> move consonants from the beginning of the word to the end of the word until the first vowel, then return it plus \"ay\".\n\n3) The result must be lowercase, regardless of the case of the input. If the input string has any non-alpha characters, the function must return None, null, Nothing (depending on the language).\n\n4) The function must also handle simple random strings and not just English words.\n\n5) The input string has no vowels -> return the original string plus \"ay\".\n\nFor example, the word \"spaghetti\" becomes \"aghettispay\" because the first two letters (\"sp\") are consonants, so they are moved to the end of the string and \"ay\" is appended.\n\n\n*/\nfunction pigLatin(string){\n  string=string.toLowerCase()\n  if (/[0-9]/.test(string)) return null\n  if (/[auioe]/.test(string[0])) return string+'way'\n  for (let i=0;i<string.length;i++)\n  {\n  if (/[auioe]/.test(string[0])) return (string+'ay')\n  let temp = string[0];\n  string=string.substring(1)+temp\n  }\n  return (string+'ay')\n}\n"
  },
  {
    "path": "Single character palindromes.js",
    "content": "/*\nDescription:\nYou will be given a string and you task is to check if it is possible to convert that string into a palindrome by removing a single character. If the string is already a palindrome, return \"OK\". If it is not, and we can convert it to a palindrome by removing one character, then return \"remove one\", otherwise return \"not possible\". The order of the characters should not be changed.\n\nFor example:\n\nsolve(\"abba\") = \"OK\". -- This is a palindrome\nsolve(\"abbaa\") = \"remove one\". -- remove the 'a' at the extreme right. \nsolve(\"abbaab\") = \"not possible\". \nMore examples in the test cases.\n\nGood luck!\n*/\nfunction solve(s){\n  let check = s.slice()\n  let reverse=(s)=>s.split``.reverse().join``\n  if (check===reverse(s)) return 'OK'\n  if (s.split``.map(v=>s).some((v,i)=>{\n  v=v.split``;\n  v.splice(i,1).join``;\n  return v.join``===reverse(v.join``)})) return 'remove one'\n  return 'not possible'\n};\n"
  },
  {
    "path": "Sometimes.js",
    "content": "/*\nDescription:\nA function that works sometimes\nThis kata is heavily influenced by the Once kata. It just adds a few extra steps to test fundamentals.\n\nImplement a function sometimes that takes another funciton as an argument and returns a new version of that function that will behave as the following:\n\n// Example function that will be passed as an argument to sometimes\nfunction add (a, b) {\n    return a + b;\n}\n\nvar s = sometimes(add);\n\n// The first 3 tmes we call s it returns add's expected output\ns(4, 6) // returns 10\ns(3, 6) // returns 9\ns(2, 6) // returns 8\n\n// But the 4th time it returns a default message 'hmm, I don't know!'\ns(1, 6) // returns 'hmm, I don't know!'\n\n// Each consecutive odd call returns add's expected output\ns(1, 5) // returns 6\n\n// Each consecutive even call doesn't work and returns 'hmm, I don't know!'\ns(1, 4) // returns 'hmm, I don't know!'\n*/\nfunction sometimes(fn) {\n  let i=0\n  return (a,b)=>{\n  i++\n  if (i<3){\n  return fn(a,b);\n  }\n  if (i%2!==0) return fn(a,b)\n  if (i%2===0) return `hmm, I don't know!`\n  }\n}\n"
  },
  {
    "path": "Sort Arrays (Ignoring Case).js",
    "content": "/*\nDescription:\nSimple sort, but this time sort regardless of upper / lower case.\n\nSo the input of\n\n[ \"Hello\", \"there\", \"I'm\", \"fine\"]\nis translated to\n\n[\"fine\", \"Hello\", \"I'm\", \"there\" ]\n*/\n\n// input: names - unsorted strings\n// output: case-agnostic sort\nsortme = function( names ){\n return names.sort((a,b)=>a.toLowerCase()>b.toLowerCase());\n}\n"
  },
  {
    "path": "Sort My Animals.js",
    "content": "/*\nDescription:\nConsider the following class:\n\nvar Animal = { \n    name: \"Cat\", \n    numberOfLegs: 4 \n}\nWrite a method that accepts a list of objects of type Animal, and returns a new list. The new list should be a copy of the original list, sorted first by the animal's number of legs, and then by its name.\n\nIf null is passed, the method should return null. If an empty list is passed, it should return an empty list back.\n*/\nfunction sortAnimal(animal) {\n    return animal?animal.sort((a,b)=>a.numberOfLegs-b.numberOfLegs||a.name.localeCompare(b.name)):null;\n}\n"
  },
  {
    "path": "Sort odd and even numbers in different order.js",
    "content": "/*\nDescription:\nYou are given an array of integers. Your task is to sort odd numbers within the array in ascending order, and even numbers in descending order.\n\nNote that zero is an even number. If you have an empty array, you need to return it.\n\nFor example:\n\n[5, 3, 2, 8, 1, 4]  -->  [1, 3, 8, 4, 5, 2]\n\nodd numbers ascending:   [1, 3,       5   ]\neven numbers descending: [      8, 4,    2]\n*/\nfunction sortArray(array) {\n    const odd = array.filter(v=>v%2!==0).sort((a,b)=>a-b)\n    const even = array.filter(v=>v%2===0).sort((a,b)=>b-a)\n    const arr = [];\n    for (let i=0;i<array.length;i++){\n      if (array[i]%2===0) arr.push(even.shift())\n      else arr.push(odd.shift())\n    }\n    return arr\n}\n"
  },
  {
    "path": "Sort sentence pseudo-alphabetically.js",
    "content": "/*\nDescription:\nGiven a standard english sentence passed in as a string, write a method that will return a sentence comprised of the same words, but sorted by their first letter. However, the method of sorting has a twist to it:\n\nAll words that begin with a lower case letter should be at the beginning of the sorted sentence, and sorted in ascending order. All words that begin with an upper case letter should come after that, and should be sorted in descending order. If a word appears twice in the sentence, it should be returned twice in the sorted sentence. Any punctuation must be discarded.\n\nFor example, given the input string \"Land of the Old Thirteen! Massachusetts land! land of Vermont and Connecticut!\", your method should return \"and land land of of the Vermont Thirteen Old Massachusetts Land Connecticut\". Lower case letters are sorted a->l->l->o->o->t and upper case letters are sorted V->T->O->M->L->C.\n*/\nfunction sort(s){\n    s=s.replace(/[^a-zA-Z ]/g,'').split` `\n    return s.filter(v=>v[0]===v[0].toLowerCase()).sort((a,b)=>a.localeCompare(b))\n    .concat(s.filter(v=>v[0]!==v[0].toLowerCase()).sort((a,b)=>b.localeCompare(a))).join` ` \n}\n"
  },
  {
    "path": "Sort the odd",
    "content": "/*\nDescription:\nYou have an array of numbers.\nYour task is to sort ascending odd numbers but even numbers must be on their places.\n\nZero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it.\n\nExample\n\nsortArray([5, 3, 2, 8, 1, 4]) == [1, 3, 2, 8, 5, 4]\n*/\n\nfunction sortArray(array) {\n  const odd = array.filter((x) => x % 2).sort((a,b) => a - b);\n  return array.map((x) => x % 2 ? odd.shift() : x);\n}\n"
  },
  {
    "path": "Sorting by bits.js",
    "content": "/*\nDescription:\nIn this kata you're expected to sort an array of 32-bit integers in ascending order of the number of on bits they have.\n\nE.g Given the array [7, 6, 15, 8]\n\n7 has 3 on bits (000...0111)\n6 has 2 on bits (000...0011)\n15 has 4 on bits (000...1111)\n8 has 1 on bit (000...1000)\nSo the array in sorted order would be [8, 6, 7, 15].\n\nIn cases where two numbers have the same number of bits, compare their real values instead.\n\nE.g between 10 (...1010) and 12 (...1100), they both have the same number of on bits '2' but the integer 10 is less than 12 so it comes first in sorted order.\n\nYour task is to write the function sortBybit() that takes an array of integers and sort them as described above.\n\nNote: Your function should modify the input rather than creating a new array.\n\nsortByBit([3, 8, 3, 6, 5, 7, 9, 1]) // => [1, 8, 3, 3, 5, 6, 9, 7]\n*/\nfunction sortByBit(arr) {\n  const countBit=(bit)=>bit.toString(2).replace(/[0]/g,'').length\n  return arr.sort((a,b)=>countBit(a)===countBit(b)?a-b:countBit(a)-countBit(b))\n}\n"
  },
  {
    "path": "Special Multiples.js",
    "content": "/*\nDescription:\nSome numbers have the property to be divisible by 2 and 3. Other smaller subset of numbers have the property to be divisible by 2, 3 and 5. Another subset with less abundant numbers may be divisible by 2, 3, 5 and 7. These numbers have something in common: their prime factors are contiguous primes.\n\nCreate a function count_specMult() that finds the amount of numbers that have the first n primes as factors below a given value, maxVal\n\nLet's see some cases:\n\ncount_specMult(3, 200) -------> 6 \n\n/// the first 3 primes are 2, 3 and 5\n\nand the found numbers below 200 are 30 < 60 < 90 < 120 < 150 < 180 < 200 (6 numbers)\nHappy coding!!\n*/\nconst primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]\nfunction countSpecMult(n, mxval) {\n    const prime=primes.slice(0,n).reduce((a,b)=>a*b,1)\n    return ~~(mxval/prime)\n}\n"
  },
  {
    "path": "Spelling Bee.js",
    "content": "/*\nDescription:\nHow many bees are in the beehive?\nbees can be facing UP, DOWN, LEFT, or RIGHT\nbees can share parts of other bees\nExamples\nEx1\n\nbee.bee     \n.e..e..\n.b..eeb\nAnswer: 5\n\nEx2 ``` bee.bee e.e.e.e eeb.eeb ``` *Answer: 8*\nNotes\nThe hive may be empty or null/None/nil/...\nPython: the hive is passed as a list of lists (not a list of strings)\n*/\nhowManyBees = function(hive) {\n  if (hive===null) return 0\n  if (!hive.length) return 0\n  let count = 0\n  for (let i=0;i<hive.length;i++){\n    for (let j=0;j<hive[0].length-2;j++){\n      if (hive[i][j]==='b'&&hive[i][j+1]==='e'&&hive[i][j+2]==='e')count++\n      if (hive[i][j]==='e'&&hive[i][j+1]==='e'&&hive[i][j+2]==='b')count++ \n    }\n  }\n  for (let i=0;i<hive[0].length;i++){\n    for (let j=0;j<hive.length-2;j++){\n      if (hive[j][i]==='b'&&hive[j+1][i]==='e'&&hive[j+2][i]==='e')count++\n      if (hive[j][i]==='e'&&hive[j+1][i]==='e'&&hive[j+2][i]==='b')count++\n       \n    }\n  }\n  return count\n}\n"
  },
  {
    "path": "Split Strings",
    "content": "/*\nDescription:\nComplete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').\n\nExamples:\n\nsolution('abc') // should return ['ab', 'c_']\nsolution('abcdef') // should return ['ab', 'cd', 'ef']\n*/\n\nfunction solution(str){\n  let arr=[];\n  for(let i = 0; i < str.split('').length; i += 2){\n  arr.push(str.slice(i,i+2))}\n\nreturn arr.map(v=>v.length===1?v+'_':v)\n}\n"
  },
  {
    "path": "Sqrt approximation.js",
    "content": "/*\nWe want to approximate the sqrt function. Usually this function takes a floating point number and returns another floating point number, but in this kata we're going to work with integral numbers instead.\n\nYour task is to write a function that takes an integer n and returns either\n\nan integer k if n is a square number, such that k * k == n or\na range (k, k+1), such that k * k < n and n < (k+1) * (k+1).\nExamples\nTest.assertDeepEquals( sqrtApproximation(4), 2 );\nTest.assertDeepEquals( sqrtApproximation(5), [2,3] );\nNote : pow() and sqrt() functions are disabled.\n\nRemarks\nIn dynamic languages, return either a single value or an array/list. In Haskell, use Either.\n*/\nfunction sqrtApproximation(number){\n  for (let i=0;i<=number;i++){\n  if (i*i===number) return i\n  if (i*i>number) return [i-1,i];\n  }\n  return 0\n}\n"
  },
  {
    "path": "Squares in a Rectangle.js",
    "content": "/*\nDescription:\nA rectangle can be split up into a grid of 1x1 squares, the amount of which being equal to the product of the two dimensions of the rectangle. Depending on the size of the rectangle, that grid of 1x1 squares can also be split up into larger squares, for example a 3x2 rectangle has a total of 8 squares, as there are 6 distinct 1x1 squares, and two possible 2x2 squares. A 4x3 rectangle contains 20 squares.\n\nYour task is to write a function `findSquares` that returns the total number of squares for any given rectangle, the dimensions of which being given as two integers with the first always being equal to or greater than the second.\n*/\nfunction findSquares(x,y){\n  let cubes= 0\n  while(x&&y){\n    cubes+=x*y\n    x--\n    y--\n  }\n  return cubes \n}\n"
  },
  {
    "path": "Srot the inner ctonnet in dsnnieedcg oredr.js",
    "content": "/*\nDescription:\n#Srot the inner ctnnoet in dsnnieedcg oredr\n\nYou have to sort the inner content of every word of a string in descending order.\nThe inner content is the content of a word without first and the last char.\n\nSome examples:\n\n\"sort the inner content in descending order\" -> \"srot the inner ctonnet in dsnnieedcg oredr\"\n\"wait for me\" -> \"wiat for me\"\n\"this kata is easy\" -> \"tihs ktaa is esay\"\nThe string will never be null and will never be empty.\nIt will contain only lowercase-letters and whitespaces.\n\nIn C++ the string is always 0-terminated. \n\n\nHave fun coding it and please don't forget to vote and rank this kata! :-)\n\nI have also created other katas. Take a look if you enjoyed this kata!\n*/\nfunction sortTheInnerContent(words)\n{\n  return words.split(' ').map(v=>v.length>1?v=(v.slice(0,1)+v.slice(1,-1)\n  .split('').sort((a,b)=>b>a).join('')+v.slice(-1)):v).join(' ');\n}\n"
  },
  {
    "path": "Statistics for an Athletic Association.js",
    "content": "/*\nYou are the \"computer expert\" of a local Athletic Association (C.A.A.). Many teams of runners come to compete. Each time you get a string of all race results of every team who has run. For example here is a string showing the individual results of a team of 5 runners:\n\n\"01|15|59, 1|47|6, 01|17|20, 1|32|34, 2|3|17\"\n\nEach part of the string is of the form: h|m|s where h, m, s (h for hour, m for minutes, s for seconds) are positive or null integer (represented as strings) with one or two digits. There are no traps in this format.\n\nTo compare the results of the teams you are asked for giving three statistics; range, average and median.\n\nRange : difference between the lowest and highest values. In {4, 6, 9, 3, 7} the lowest value is 3, and the highest is 9, so the range is 9 − 3 = 6.\n\nMean or Average : To calculate mean, add together all of the numbers in a set and then divide the sum by the total count of numbers.\n\nMedian : In statistics, the median is the number separating the higher half of a data sample from the lower half. The median of a finite list of numbers can be found by arranging all the observations from lowest value to highest value and picking the middle one (e.g., the median of {3, 3, 5, 9, 11} is 5) when there is an odd number of observations. If there is an even number of observations, then there is no single middle value; the median is then defined to be the mean of the two middle values (the median of {3, 5, 6, 9} is (5 + 6) / 2 = 5.5).\n\nYour task is to return a string giving these 3 values. For the example given above, the string result will be\n\n\"Range: 00|47|18 Average: 01|35|15 Median: 01|32|34\"\n\nof the form:\n\n\"Range: hh|mm|ss Average: hh|mm|ss Median: hh|mm|ss\"\n\nwhere hh, mm, ss are integers (represented by strings) with each 2 digits.\n\nRemarks:\n\nif a result in seconds is ab.xy... it will be given truncated as ab.\n\nif the given string is \"\" you will return \"\"\n*/\nfunction stat(str) {\n  if(str === '') return '';\n  let newString = str.split(\", \");\n  let times = [];\n\n  for(let i = 0; i < newString.length; i++){\n    newString[i] = newString[i].split('|');\n    let total = 0;\n    for(let j = 0; j < newString[i].length; j++){\n      if(j === 0) total += +newString[i][j] * 3600;\n      if(j === 1) total += +newString[i][j] * 60;\n      if(j === 2) total += +newString[i][j];\n    }\n      times.push(total);\n  }\n  times.sort((a, b) => a - b);\n  let rangeSeconds = times[times.length - 1] - times[0];\n  let rangeTime = calculateTime(rangeSeconds);\n  let averageSeconds = times.reduce((pv, pc) => pv + pc) / times.length;\n  let averageTime = calculateTime(averageSeconds);\n  let medianSeconds = times.length % 2 !== 0 ? times[(times.length - 1) / 2] : ((times[times.length / 2] + times[(times.length / 2) - 1]) / 2);\n  let medianTime = calculateTime(medianSeconds);\n  \n  return `Range: ${rangeTime} Average: ${averageTime} Median: ${medianTime}`;\n}\n\nfunction calculateTime(totalSeconds){\n  let hours = Math.floor(totalSeconds / 3600);\n  let minutes = Math.floor(totalSeconds / 60 % 60);\n  let seconds = Math.floor(totalSeconds % 60);\n  return [hours.toString().length < 2 ? '0' + hours : hours, minutes.toString().length < 2 ? '0' + minutes : minutes, seconds.toString().length < 2 ? '0' + seconds : seconds].join('|');\n}\n"
  },
  {
    "path": "Steps in Primes.js",
    "content": "/*\nDescription:\nThe prime numbers are not regularly spaced. For example from 2 to 3 the step is 1. From 3 to 5 the step is 2. From 7 to 11 it is 4. Between 2 and 50 we have the following pairs of 2-steps primes:\n\n3, 5 - 5, 7, - 11, 13, - 17, 19, - 29, 31, - 41, 43\n\nWe will write a function step with parameters:\n\ng (integer >= 2) which indicates the step we are looking for,\n\nm (integer >= 2) which gives the start of the search (m inclusive),\n\nn (integer >= m) which gives the end of the search (n inclusive)\n\nIn the example above step(2, 2, 50) will return [3, 5] which is the first pair between 2 and 50 with a 2-steps.\n\nSo this function should return the first pair of the two prime numbers spaced with a step of g between the limits m, n if these g-steps prime numbers exist otherwise nil or null or None or Nothing or [] or \"0, 0\" or {0, 0} (depending on the language).\n\n#Examples:\n\nstep(2, 5, 7) --> [5, 7] or (5, 7) or {5, 7} or \"5 7\"\n\nstep(2, 5, 5) --> nil or ... or [] in Ocaml or {0, 0} in C++\n\nstep(4, 130, 200) --> [163, 167] or (163, 167) or {163, 167}\n\nSee more examples for your language in \"RUN\"\nRemarks:\n([193, 197] is also such a 2-steps primes between 130 and 200 but it's not the first pair).\n\nstep(6, 100, 110) --> [101, 107] though there is a prime between 101 and 107 which is 103; the pair 101-103 is a 2-step.\n\n#Notes: The idea of \"step\" is close to that of \"gap\" but it is not exactly the same. For those interested they can have a look at http://mathworld.wolfram.com/PrimeGaps.html.\n\nA \"gap\" is more restrictive: there must be no primes in between (101-107 is a \"step\" but not a \"gap\". Next kata will be about \"gaps\":-).\n\nFor Go: nil slice is expected when there are no step between m and n. Example: step(2,4900,4919) --> nil\n*/\nfunction step(g, m, n){\n    for(let i = m; i <= n; i++){\n        if(isPrime(i) && isPrime(i+g)){ return [i, i+g]}\n    }\n    return null;\n}\nfunction isPrime(n) {\n  let rt = Math.sqrt(n);\n  for(let i = 2; i <= rt; i++) {\n    if(n % i === 0) return false; \n  }\n  return n !== 1;\n}\n"
  },
  {
    "path": "Stop gninnipS My sdroW!",
    "content": "/*\nDescription:\nWrite a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.\n\n\nExamples:\n\nspinWords( \"Hey fellow warriors\" ) => returns \"Hey wollef sroirraw\" \nspinWords( \"This is a test\") => returns \"This is a test\" \nspinWords( \"This is another test\" )=> returns \"This is rehtona test\"\n*/\n\nfunction spinWords(str){\n  return str.split(' ').map(value=>{ if (value.length>4) return value.split('').reverse().join(''); \n  return value})\n                      .join(' ');\n}\n"
  },
  {
    "path": "Street Fighter 2 - Character Selection.js",
    "content": "/*\nDescription:\nShort Intro\n\nSome of you might remember spending afternoons playing Street Fighter 2 in some Arcade back in the 90s or emulating it nowadays with the numerous emulators for retro consoles.\n\nCan you solve this kata? Suuure-You-Can!\n\nUPDATE: a new kata's harder version is available here.\n\nThe Kata\n\nYou'll have to simulate the video game's character selection screen behaviour, more specifically the selection grid. Such screen looks like this:\n\nalt text\n\nSelection Grid Layout in text:\n\n| Ryu  | E.Honda | Blanka  | Guile   | Balrog | Vega    |\n| Ken  | Chun Li | Zangief | Dhalsim | Sagat  | M.Bison |\nInput\n\nthe list of game characters in a 2x6 grid;\nthe initial position of the selection cursor (top-left is (0,0));\na list of moves of the selection cursor (which are up, down, left, right);\nOutput\n\nthe list of characters who have been hovered by the selection cursor after all the moves (ordered and with repetition, all the ones after a move, wether successful or not, see tests);\nRules\n\nSelection cursor is circular horizontally but not vertically!\n\nAs you might remember from the game, the selection cursor rotates horizontally but not vertically; that means that if I'm in the leftmost and I try to go left again I'll get to the rightmost (examples: from Ryu to Vega, from Ken to M.Bison) and vice versa from rightmost to leftmost.\n\nInstead, if I try to go further up from the upmost or further down from the downmost, I'll just stay where I am located (examples: you can't go lower than lowest row: Ken, Chun Li, Zangief, Dhalsim, Sagat and M.Bison in the above image; you can't go upper than highest row: Ryu, E.Honda, Blanka, Guile, Balrog and Vega in the above image).\n\nTest\n\nFor this easy version the fighters grid layout and the initial position will always be the same in all tests, only the list of moves change.\n\nNotice : changing some of the input data might not help you.\n\nExamples\n\n1.\n\nfighters = [\n    [\"Ryu\", \"E.Honda\", \"Blanka\", \"Guile\", \"Balrog\", \"Vega\"],\n    [\"Ken\", \"Chun Li\", \"Zangief\", \"Dhalsim\", \"Sagat\", \"M.Bison\"]\n]\ninitial_position = (0,0)\nmoves = ['up', 'left', 'right', 'left', 'left']\nthen I should get:\n\n['Ryu', 'Vega', 'Ryu', 'Vega', 'Balrog']\nas the characters I've been hovering with the selection cursor during my moves. Notice: Ryu is the first just because it \"fails\" the first up See test cases for more examples.\n\n2.\n\nfighters = [\n    [\"Ryu\", \"E.Honda\", \"Blanka\", \"Guile\", \"Balrog\", \"Vega\"],\n    [\"Ken\", \"Chun Li\", \"Zangief\", \"Dhalsim\", \"Sagat\", \"M.Bison\"]\n]\ninitial_position = (0,0)\nmoves = ['right', 'down', 'left', 'left', 'left', 'left', 'right']\nResult:\n\n['E.Honda', 'Chun Li', 'Ken', 'M.Bison', 'Sagat', 'Dhalsim', 'Sagat']\n*/\n\nfunction streetFighterSelection(fighters, position, moves){\n  let arr=[];\n  let y=position[0];\n  let x=position[1]\n  for (let i=0;i<moves.length;i++){\n  if (moves[i]==='left'){x--;if(x<0){x=5}arr.push(fighters[y][x])}\n  if (moves[i]==='right'){x++;if(x>5){x=0}arr.push(fighters[y][x])}\n  if (moves[i]==='up'){y++;if(y>0){y=0}arr.push(fighters[y][x])}\n  if (moves[i]==='down'){y--;if(y<1){y=1}arr.push(fighters[y][x])}} \n  return arr;\n}\n"
  },
  {
    "path": "String Breakers.js",
    "content": "/*\nDescription:\nI will give you an integer (N) and a string. Break the string up into as many substrings of N as you can without spaces. If there are leftover characters, include those as well.\n\nExample: \n\nN = 5;\n\nString = \"This is an example string\";\n\nReturn value:\nThisi\nsanex\nample\nstrin\ng\n\nReturn value as a string: 'Thisi'+'\\n'+'sanex'+'\\n'+'ample'+'\\n'+'strin'+'\\n'+'g'\n*/\nfunction stringBreakers(n, string){\n  string=string.replace(/\\s/g,'')\n  let arr = []\n  for (let i=0;i<string.length;i+=n){\n    arr.push(string.slice(i,i+n))\n  }\n  return arr.join`\\n`\n}\n"
  },
  {
    "path": "String Integer Greater-than.js",
    "content": "/*\nDescription:\nYou are to write a function, stringIntGreaterThan that must accept arguments, each being the string representation of an positive or negative integer of any length (could contain a thousand digits, or more; also, integers will not have leading zeros).\n\nThe function should then return true if the first argument is greater than the second argument, false if not.\n*/\nconst BigNumber = require('bignumber.js');\nfunction stringIntGreaterThan(a, b) {\n  return new BigNumber(a).gt(new BigNumber(b)) \n} \n"
  },
  {
    "path": "String Shortener (shrink).js",
    "content": "/*\nDescription:\nExplanation\nWrite a function that shortens a string to a given length. Instead of cutting the string from the end, your function will shorten it from the middle like shrinking.\n\nFor example:\n\nsentence = \"The quick brown fox jumps over the lazy dog\"\nres = shorten(sentence, 27)\n\nres === \"The quick br...the lazy dog\"\nYour function should also accept an optional argument glue to get the parts together.\n\nsentence = \"The quick brown fox jumps over the lazy dog\"\nres = shorten(sentence, 27, '---')\n\nres === \"The quick br---the lazy dog\"\nRules are simple:\nResult must always be equal to the given length\nOnly exception to above rule is, when string is already shorter than given length. In that case string should be returned untouched.\nIf no glue is sent ... should be used by default\nIf glue cannot go exactly in the middle, second part should be longer\nIf glue cannot fit in the shortened string, string should be shortened without shrinking.\nmeaning; shorten('hello world', 5, '....') should return hello because 4 char glue cannot fit in the shortened string.\nglue must have at least 1 char on both ends. Example minimum h...d, results ....d or h.... are not excepted.\nYou can assume you'll always receive a string as the sentence and the glue. And integer number for the length.\nThink about other possible edge cases, there are some surprises.\n*/\nfunction shorten(string, length, glue='...') {\n  if (glue.length>=string.length) return string.slice(0,length)\n  if (string.length<=length) return string\n  let left = string.slice(0,~~((length-glue.length)/2))\n  if (left.length===0) return string.slice(0,length)\n  let right = string.slice(Math.ceil((length-glue.length)/2)*-1)\n  let str = left+glue+right\n  if (str.length>length) return ''\n  return str\n}\n"
  },
  {
    "path": "String Suffixes.js",
    "content": "/*\nDescription:\nLet's say take 2 strings, A and B, and define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings abc and abd is 2, while the similarity of strings aaa and aaab is 3.\n\nwrite a function that calculates the sum of similarities of a string S with each of it's suffixes.\n\nstringSuffix('ababaa') => returns 11\nstringSuffix('abc') => returns 3\nExplanation:\n\nIn the first case, the suffixes of the string are ababaa, babaa, abaa, baa, aa and a. The similarities of each of these strings with the string ababaa are 6,0,3,0,1,1 respectively. Thus the answer is 6 + 0 + 3 + 0 + 1 + 1 = 11.\n\nFor the second case, the answer is simply 3 + 0 + 0 = 3.\n\nNote : Each string will have at least one character - no need to check for empty strings :)\n*/\nfunction stringSuffix(s) {\n  let suffix=0\n  for (let i=0;i<s.length;i++){\n    for (let j=0;j<s.length;j++)\n    if (s.slice(i)[j]===s[j]){suffix++}\n    else {break}\n  }\n  return suffix\n}\n"
  },
  {
    "path": "String array revisal.js",
    "content": "/*\nDescription:\nIn this Kata, you will be given an array of strings and your task is to remove all consecutive duplicate letters from each string in the array.\n\nFor example:\n\ndup([\"abracadabra\",\"allottee\",\"assessee\"]) = [\"abracadabra\",\"alote\",\"asese\"].\n\ndup([\"kelless\",\"keenness\"]) = [\"keles\",\"kenes\"].\n\nStrings will be alphabet characters only. Don't worry about lower and upper case. See test cases for more examples.\n\nGood luck!\n*/\nfunction dup(s) {\n  return s.map(v=>v.split``.map((v,i,arr)=>arr[i]===arr[i+1]?'':v).join``)\n};\n"
  },
  {
    "path": "String average.js",
    "content": "/*\nDescription:\nYou are given a string of numbers between 0-9. Find the average of these numbers and return it as a floored whole number (ie: no decimal places) written out as a string. Eg:\n\n\"zero nine five two\" -> \"four\"\n\nIf the string is empty or includes a number greater than 9, return \"n/a\"\n*/\nfunction averageString(str) {\n  const num = {zero:0,one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9}\n  const word = {0:'zero',1:'one',2:'two',3:'three',4:'four',5:'five',\n  6:'six',7:'seven',8:'eight',9:'nine'}\n  if (!str.length) return 'n/a'\n  let n=0\n  const l=str.split(' ').length\n  const arr=str.split(' ').map(v=>num.hasOwnProperty(v)?v=num[v]:n=1).reduce((a,b)=>a+b,0)\n  return n===0?word[Math.floor(arr/l)]:'n/a'\n}\n"
  },
  {
    "path": "String character frequency.js",
    "content": "/*\nDescription:\nIn this Kata, we are going to determine if the count of each of the characters in a string can be equal if we remove a single character from that string.\n\nFor example:\n\nsolve('abba') = false -- if we remove any character, the count of each character will not be equal.\nsolve('abbba') = true -- if we remove one b, the count of each character becomes 2.\nsolve('aaaa') = true -- if we remove one character, the remaining characters have same count.\nsolve('wwwf') = true -- if we remove f, the remaining letters have same count.\nMore examples in the test cases. Empty string is not tested.\n\nGood luck!\n*/\nfunction solve(s){\n  let dict = Object.values(s.split``.reduce((a,b)=>(a[b]=a[b]+1||1,a),{}))\n  if (dict.length===1) return true\n  for (let i=0;i<dict.length;i++){\n  let temp = dict[i]\n  dict[i]=dict[i]-1\n  if (dict.every(v=>v==dict[i])) return true\n  dict[i]=temp\n  }\n  dict=dict.sort((a,b)=>a-b)\n  if (dict.slice(1).every((v,i)=>v===dict[1])&&dict[0]===1) return true\n  return false\n};\n"
  },
  {
    "path": "String reduction.js",
    "content": "/*\nDescription:\nIn this Kata, we are going to see how a Hash (or Map or dict) can be used to keep track of characters in a string.\n\nConsider two strings \"aabcdefg\" and \"fbd\". How many characters do we have to remove from the first string to get the second string? Although not the only way to solve this, we could create a Hash of counts for each string and see which character counts are different. That should get us close to the answer. I will leave the rest to you.\n\nFor this example, solve(\"aabcdefg\",\"fbd\") = 5. Also, solve(\"xyz\",\"yxxz\") = 0, because we cannot get second string from the first since the second string is longer.\n\nMore examples in the test cases.\n\nGood luck!\n*/\nfunction solve(a, b) {\n  const h=[...a].reduce((h,c)=>(h[c]=h[c]+1||1,h),{});\n  for(let c of b) {\n    if(!h[c]) return 0;\n    h[c]--;\n  }\n  return Object.values(h).reduce((s,n)=>s+n,0);\n};\n"
  },
  {
    "path": "String searching with wildcard.js",
    "content": "/*\nDescription:\nThe method below, is the most simple string search algorithm. It will find the first occurrence of a word in a text string.\n\nhaystack = the whole text\n\nneedle = searchword\n\nwildcard = _\n\nfind(\"strike\", \"i will strike down upon thee\"); // return 7\nThe find method is already made.\n\nThe problem is to implement wildcard(s) in the needle. If you have a _ in the needle it will match any character in the haystack.\n\nA normal string search algorithm will find the first occurrence of a word(needle) in a text(haystack), starting on index 0. Like this:\n\nfind(\"strike\", \"I will strike down upon thee\"); return 7\nA wildcard in the needle will match any character in the haystack. The method should work on any types of needle, and haystasks. You can assume the needle is shorter than(or equal to) the haystack.\n\nfind(\"g__d\", \"That's the good thing about being president\"); // return 11\nIf no match the method should return -1\n*/\nfunction find(needle, haystack){\n  return haystack.search(RegExp(`${needle.replace(/[^a-z0-9\\.,-]/gi,'.')}`))\n}\n"
  },
  {
    "path": "String tops.js",
    "content": "/*\nDescription:\nTask\nWrite a function that accepts msg string and returns local tops of string from the highest to the lowest.\nThe string's tops are from displaying the string in the below way:\n\n                                                      3 \n                              p                     2   4\n            g               o   q                 1\n  b       f   h           n       r             z \na   c   e       i       m          s          y\n      d           j   l             t       x\n                    k                 u   w \n                                        v\n\nThe next top is always 1 character higher than the previous one. For the above example, the solution for the abcdefghijklmnopqrstuvwxyz1234 input string is 3pgb.\n\nWhen the msg string is empty, return an empty string.\nThe input strings may be very long. Make sure your solution has good performance.\nCheck the test cases for more samples.\n\nNote for C++\nDo not post an issue in my solution without checking if your returned string doesn't have some invisible characters. You read most probably outside of msg string.\n*/\nfunction tops(msg) {\n    let str='';\n    for (let i=1,j=2;i<msg.length;i+=j*2+1,j+=2){\n    str+=msg[i]\n    }\n   return str.split``.reverse().join``;\n}\n"
  },
  {
    "path": "String transformer.js",
    "content": "/*\nDescription:\nGiven a string, return a new string that has transformed based on the input:\n\nChange case of every character, ie. lower case to upper case, upper case to lower case.\nReverse the order of words from the input.\nFor example:\nstringTransformer('Example Input')/string_transformer(\"Example Input\") (depending on the language you are completing the Kata in) should return 'iNPUT eXAMPLE'\n\nYou may assume the input only contain English alphabet and spaces.\n*/\nfunction stringTransformer(str) {\n return str.split` `.map(v=>v.replace(/./gi,v=>{\n if (v===v.toLowerCase()) return v.toUpperCase()\n if (v===v.toUpperCase()) return v.toLowerCase()\n })).reverse().join` `\n}\n"
  },
  {
    "path": "Stringing me along.js",
    "content": "/*\nDescription:\nCreate a function that will allow you to pass in a string, with the ability to add to this with more function calls. When it is finally passed an empty argument return the full concatinated string of all arguments pased previously.\n\nFor example: createMessage(\"Hello\")(\"World!\")(\"how\")(\"are\")(\"you?\")();\n\nThis will return the following: \"Hello World! how are you?\"\n*/\nfunction createMessage(str) {\n  return (str1)=>{\n  if (str1===undefined) return str;\n  return createMessage(str+' '+str1)\n  }\n}\n"
  },
  {
    "path": "Strip Url Params.js",
    "content": "/*\nDescription:\nComplete the method so that it does the following:\nRemoves any duplicate query string parameters from the url\nRemoves any query string parameters specified within the 2nd argument (optional array)\nExamples:\nstripUrlParams('www.codewars.com?a=1&b=2&a=2') // returns 'www.codewars.com?a=1&b=2'\nstripUrlParams('www.codewars.com?a=1&b=2&a=2', ['b']) // returns 'www.codewars.com?a=1'\nstripUrlParams('www.codewars.com', ['b']) // returns 'www.codewars.com'\n*/\nfunction stripUrlParams(url, paramsToStrip){\n  url=url.replace(/&?([^?=]+)=.+?/g, function (x, y, z) {\n        return url.indexOf(y + \"=\") < z || (paramsToStrip || []).indexOf(y) > -1 ? \"\" : x;\n    });\n  let index =url.indexOf(paramsToStrip)\n  if (!paramsToStrip||index===-1){\n    return url\n  }\n  return url.slice(0,index-1)\n}\n"
  },
  {
    "path": "Sum The Tree.js",
    "content": "/*\nDescription:\nGiven a node object representing a binary tree:\n\nNode:\n  value: <int>,\n  left: <Node> or null,\n  right: <Node> or null\nNode:\n  value: <int>,\n  left: <Node> or null,\n  right: <Node> or null\nstruct node\n{\n  int value;\n  node* left;\n  node* right;\n}\npublic class Node\n{  \n    public int Value;  \n    public Node Left;  \n    public Node Right;\n\n    public Node(int value, Node left = null, Node right = null)\n    {\n      Value = value;\n      Left = left;\n      Right = right;\n    }\n}  \nwrite a function that returns the sum of all values, including the root. Absence of a node will be indicated with a null value.\n\nExamples:\n\n10\n| \\\n1  2\n=> 13\n\n1\n| \\\n0  0\n    \\\n     2\n=> 3\n*/\nfunction sumTheTreeValues(root){\n  if(!root)\n    return 0;\n  return root.value + sumTheTreeValues(root.left) + sumTheTreeValues(root.right);\n}\n"
  },
  {
    "path": "Sum consecutives.js",
    "content": "/*\nDescription:\nYou are given a list/array which contains only integers (positive and negative). Your job is to sum only the numbers that are the same and consecutive. The result should be one list.\n\nExtra credit if you solve it in one line. You can asume there is never an empty list/array and there will always be an integer.\n\nSame meaning: 1 == 1\n\n1 != -1\n\n#Examples:\n\n[1,4,4,4,0,4,3,3,1] # should return [1,12,0,4,6,1]\n\n\"\"\"So as you can see sum of consecutives 1 is 1 \nsum of 3 consecutives 4 is 12 \nsum of 0... and sum of 2 \nconsecutives 3 is 6 ...\"\"\"\n\n[1,1,7,7,3] # should return [2,14,3]\n[-5,-5,7,7,12,0] # should return [-10,14,12,0]\n*/\nconst sumConsecutives = list => list.reduce((accumulator, curr, i, list) => {\n  if (curr !== list[i - 1]) accumulator.push(curr);\n  else accumulator[accumulator.length - 1] += curr;\n  return accumulator;\n}, []);\n"
  },
  {
    "path": "Sum of Digits Digital Root",
    "content": "/*\nIn this kata, you must create a digital root function.\n\nA digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has two digits, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.\n\nHere's how it works (Ruby example given):\n\ndigital_root(16)\n=> 1 + 6\n=> 7\n\ndigital_root(942)\n=> 9 + 4 + 2\n=> 15 ...\n=> 1 + 5\n=> 6\n\ndigital_root(132189)\n=> 1 + 3 + 2 + 1 + 8 + 9\n=> 24 ...\n=> 2 + 4\n=> 6\n\ndigital_root(493193)\n=> 4 + 9 + 3 + 1 + 9 + 3\n=> 29 ...\n=> 2 + 9\n=> 11 ...\n=> 1 + 1\n=> 2\n*/\n\nfunction digital_root(n) {\n  return (n - 1) % 9 + 1;\n}\n"
  },
  {
    "path": "Sum of Two Integers.js",
    "content": "/*\nTask\nGiven Two intgers a , b , find The sum of them , BUT You are not allowed to use the operators + and -\n\nNotes\nThe numbers (a,b) may be positive , negative values or zeros .\n\nReturning value will be integer .\n\nJavascript: the Array reduce methods are disabled, along with eval, require, and module .\n\nJava: the following methods are prohibited: addExact, average, collect, decrement, increment, nextAfter, nextDown, nextUp, reduce, subtractExact, sum, summing . The following classes are prohibited: BigDecimal and BigInteger .\n\nNASM: the following instructions are prohibited: add, adc, adcx, adox, dec, inc, lea, sbb, sub .\n\nInput >> Output Examples\n1- Add (5,19) ==> return (24) \n\n2- Add (-27,18) ==> return (-9)\n\n3- Add (-14,-16) ==> return (-30)\n*/\nfunction add(x, y)\n{\n  while (y != 0) {\n  let carry = x & y;\n  x = x ^ y;\n  y = carry << 1;\n        }\n        return x;\n}\n"
  },
  {
    "path": "Sum of a Sequence [Hard-Core Version].js",
    "content": "/*\nDescription:\nAs the title suggests, this is the hard-core version of another neat kata.\n\nThe task is simple to explain: simply sum all the numbers from the first parameter being the beginning to the second parameter being the upper limit (possibly included), going in steps expressed by the third parameter:\n\nsequenceSum(2,2,2) === 2\nsequenceSum(2,6,2) === 12 // 2 + 4 + 6\nsequenceSum(1,5,1) === 15 // 1 + 2 + 3 + 4 + 5\nsequenceSum(1,5,3) === 5 // 1 + 4\nIf it is an impossible sequence (with the beginning being larger the end and a positive step or the other way around), just return 0. See the provided test cases for further examples :)\n\nNote: differing from the other base kata, much larger ranges are going to be tested, so you should hope to get your algo optimized and to avoid brute-forcing your way through the solution.\n*/\nfunction sequenceSum(begin, end, step){\n  let result = 0;\n  for (let i = begin; step > 0 ? i <= end : i >= end; i+=step)\n    result +=i;\n  return result;\n}\n"
  },
  {
    "path": "Sum of many ints.js",
    "content": "/*\nDescription:\nWrite this function\n\n\nfor i from 1 to n, do i % m and return the sum\n\nf(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0)\nYou'll need to get a little clever with performance, since n can be a very large number\n*/\nfunction f(n, m) {\n  return Math.floor(n / m) * (m * (m - 1) / 2) + n % m * (n % m + 1) / 2 \n}\n"
  },
  {
    "path": "Sum of nested numbers.js",
    "content": "/*\nDescription:\nBuild a function sumNestedNumbers/sum_nested_numbers that finds the sum of all numbers in a series of nested arrays raised to the power of their respective nesting levels. Numbers in the outer most array should be raised to the power of 1.\n\nFor example,\n\nsumNestedNumbers([1, [2], 3, [4, [5]]])\nshould return 1 + 2*2 + 3 + 4*4 + 5*5*5 === 149\n*/\nfunction sumNestedNumbers(arr) {\n  let arr1 = [];\n  let flat=(arr,power=0)=>{\n  power+=1\n  return arr.map(v=>Array.isArray(v)?flat(v,power):arr1.push([v,power]))\n}\n  flat(arr)\n  return arr1.map(v=>Math.pow(v[0],v[1])).reduce((a,b)=>a+b,0)\n}\n"
  },
  {
    "path": "Summarize ranges.js",
    "content": "/*\nDescription:\nGiven a sorted array of numbers, return the summary of its ranges.\n\nExamples\nsummaryRanges([1, 2, 3, 4]) === [\"1->4\"]\nsummaryRanges([1, 1, 1, 1, 1]) === [\"1\"]\nsummaryRanges([0, 1, 2, 5, 6, 9]) === [\"0->2\", \"5->6\", \"9\"]\nsummaryRanges([0, 1, 2, 3, 3, 3, 4, 5, 6, 7]) === [\"0->7\"]\nsummaryRanges([0, 1, 2, 3, 3, 3, 4, 4, 5, 6, 7, 7, 9, 9, 10]) === [\"0->7\", \"9->10\"]\nsummaryRanges([-2,0, 1, 2, 3, 3, 3, 4, 4, 5, 6, 7, 7, 9, 9, 10, 12]) ===[\"-2\", \"0->7\", \"9->10\", \"12\"]\n*/\nfunction summaryRanges(nums) {\n  nums=[...new Set(nums)]\n  let arr = [];\n  let temp = []\n  for (let i=0;i<nums.length;i++){\n    temp.push(nums[i])\n    if (nums[i+1]-nums[i]!==1){\n      arr.push(temp)\n      temp=[]\n    }\n  }\n  return arr.map(v=>v.length===1?v+'':v[0]+'->'+v[v.length-1])\n}\n"
  },
  {
    "path": "Sums of Parts.js",
    "content": "/*\nDescription:\nLet us consider this example (array written in general format):\n\nls = [0, 1, 3, 6, 10]\n\nIts following parts:\n\nls = [0, 1, 3, 6, 10]\nls = [1, 3, 6, 10]\nls = [3, 6, 10]\nls = [6, 10]\nls = [10]\nls = []\nThe corresponding sums are (put together in a list): [20, 20, 19, 16, 10, 0]\n\nThe function parts_sums (or its variants in other languages) will take as parameter a list ls and return a list of the sums of its parts as defined above.\n\nOther Examples:\nls = [1, 2, 3, 4, 5, 6] \nparts_sums(ls) -> [21, 20, 18, 15, 11, 6, 0]\n\nls = [744125, 935, 407, 454, 430, 90, 144, 6710213, 889, 810, 2579358]\nparts_sums(ls) -> [10037855, 9293730, 9292795, 9292388, 9291934, 9291504, 9291414, 9291270, 2581057, 2580168, 2579358, 0]\nNotes\nSome lists can be long.\nPlease ask before translating: some translations are already written and published when/if the kata is approved.\n*/\nfunction partsSums(ls) {\n  let arr = [0];\n  ls.reverse().forEach(v => arr.push(arr[arr.length-1] + v));\n  return arr.reverse();\n}\n"
  },
  {
    "path": "Surrounding Primes for a value.js",
    "content": "/*\nDescription:\nWe need a function prime_bef_aft() that gives the largest prime below a certain given value n,\n\nbefPrime or bef_prime (depending on the language),\n\nand the smallest prime larger than this value,\n\naftPrime/aft_prime (depending on the language).\n\nThe result should be output in a list like the following:\n\nprimeBefAft == [befPrime, aftPrime]\nIf n is a prime number it will give two primes, n will not be included in the result.\n\nLet's see some cases:\n\nprimeBefAft(100) == [97, 101]\n\nprimeBefAft(97) == [89, 101]\n\nprimeBefAft(101) == [97, 103]\nRange for the random tests: 1000 <= n <= 200000\n\n(The extreme and special case n = 2 will not be considered for the tests. Thanks Blind4Basics)\n\nHappy coding!!\n*/\nfunction primeBefAft(num) {\n    let prime = [0,0]\n    for (let i=num+1;;i++){\n      if (isPrime(i)){\n        prime[1]=i\n        break\n      }\n    }\n    for (let j=num-1;;j--){\n      if (isPrime(j)){\n        prime[0]=j\n        return prime\n      }\n    }\n}\nfunction isPrime(n) {\n  let rt = Math.sqrt(n);\n  for(let i = 2; i <= rt; i++) {\n    if(n % i === 0) return false; \n  }\n  return n !== 1;\n}\n"
  },
  {
    "path": "T.T.T.17: Split odd and even.js",
    "content": "/*\nDescription:\nThey say that only the name is long enough to attract attention. They also said that only a simple Kata will have someone to solve it. This is a sadly story. series #17:\nSplit odd and even\n\nTask\nComplete function splitOddAndEven, accept a number n(n>0), return an array that contains the continuous parts of odd or even digits.\n\nPlease don't worry about digit 0, it won't appear ;-)\n\nExamples\n\nsplitOddAndEven(123)  ===  [1,2,3]\n\nsplitOddAndEven(223)  ===  [22,3]\n\nsplitOddAndEven(111)  ===  [111]\n\nsplitOddAndEven(13579)  ===  [13579]\n\nsplitOddAndEven(135246)  ===  [135,246]\n\nsplitOddAndEven(123456)  ===  [1,2,3,4,5,6]\n*/\nfunction splitOddAndEven(n) {\n  let arr = []\n  let str = n.toString()\n  for (let i=0;i<str.length;i++){\n    arr.push(str[i])\n    if ((str[i]%2==0&&str[i+1]%2!==0||str[i]%2!==0&&str[i+1]%2==0)&&i!==str.length-1){\n      arr.push(',')\n    }\n  }\n  return arr.join``.split`,`.map(v=>v*1)\n}\n"
  },
  {
    "path": "Take a Number And Sum Its Digits Raised To The Consecutive Powers And ....¡Eureka!!",
    "content": "/*\nDescription:\nThe number 89 is the first integer with more than one digit that fulfills the property partially introduced in the title of this kata. What's the use of saying \"Eureka\"? Because this sum gives the same number.\n\nIn effect: 89 = 8^1 + 9^2\n\nThe next number in having this property is 135.\n\nSee this property again: 135 = 1^1 + 3^2 + 5^3\n\nWe need a function to collect these numbers, that may receive two integers a, b that defines the range [a, b] (inclusive) and outputs a list of the sorted numbers in the range that fulfills the property described above.\n\nLet's see some cases:\n\nsumDigPow(1, 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nsumDigPow(1, 100) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 89]\nIf there are no numbers of this kind in the range [a, b] the function should output an empty list.\n\nsumDigPow(90, 100) == []\nEnjoy it!!\n*/\n\n\nfunction sumDigPow(a, b) {\n  var ans = [];\n  while(a <= b){\n    if(a.toString().split('').reduce((x,y,i)=>x + +y ** (i + 1),0) == a)\n      ans.push(a);\n    a++;\n  }\n  return ans;\n}\n"
  },
  {
    "path": "Take a Ten Minute Walk",
    "content": "/*\nDescription:\nYou live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones -- everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg. ['n', 's', 'w', 'e']). You always walk only a single block in a direction and you know it takes you one minute to traverse one city block, so create a function that will return true if the walk the app gives you will take you exactly ten minutes (you don't want to be early or late!) and will, of course, return you to your starting point. Return false otherwise.\n\nNote: you will always receive a valid array containing a random assortment of direction letters ('n', 's', 'e', or 'w' only). It will never give you an empty array (that's not a walk, that's standing still!).\n*/\n\nfunction isValidWalk(walk) {\n  let n=[],s=[],e=[],w=[];\n  walk.map(v=>{\n  if (v==='n')n.push(1);\n  if (v==='s')s.push(1);\n  if (v==='e')e.push(1);\n  if (v==='w')w.push(1);\n})\n  return (n.length===s.length)&&(w.length===e.length)&&(walk.length===10)\n}\n"
  },
  {
    "path": "Tank Truck.js",
    "content": "/*\nDescription:\nTo introduce the problem think to my neighbor who drives a tanker truck. The level indicator is down and he is worried because he does not know if he will be able to make deliveries. We put the truck on a horizontal ground and measured the height of the liquid in the tank.\n\nFortunately the tank is a perfect cylinder and the vertical walls on each end are flat. The height of the remaining liquid is h, the diameter of the cylinder is d, the total volume is vt (h, d, vt are positive or null integers). You can assume that h <= d.\n\nCould you calculate the remaining volume of the liquid? Your function tankvol(h, d, vt) returns an integer which is the truncated result (e.g floor) of your float calculation.\n\nExamples:\n\ntankvol(40,120,3500) should return 1021 (calculation gives about: 1021.26992027)\n\ntankvol(60,120,3500) should return 1750\n\ntankvol(80,120,3500) should return 2478 (calculation gives about: 2478.73007973)\nTank vertical section:\n\n\n*/\nfunction tankvol(h, d, vt) {\n    return Math.floor(((4 * vt)/(Math.pow(d, 2) * Math.PI)) *\n    (Math.pow(d / 2, 2) * Math.acos(1 - h / (d / 2)) - ((d / 2) - h) * Math.sqrt(h * (d - h))))\n}\n"
  },
  {
    "path": "Temperature converter.js",
    "content": "/*\nDescription:\nWrite a function convert_temp(temp, from_scale, to_scale) converting temperature from one scale to another. Return converted temp value.\n\nRound converted temp value to an integer(!).\n\nReading: http://en.wikipedia.org/wiki/Conversion_of_units_of_temperature\n\npossible scale inputs:\n    \"C\"  for Celsius\n    \"F\"  for Fahrenheit\n    \"K\"  for Kelvin\n    \"R\"  for Rankine\n    \"De\" for Delisle\n    \"N\"  for Newton\n    \"Re\" for Réaumur\n    \"Ro\" for Rømer\ntemp is a number, from_scale and to_scale are strings.\n\nconvert_temp(   100, \"C\",  \"F\") # => 212\nconvert_temp(    40, \"Re\", \"C\") # => 50\nconvert_temp(    60, \"De\", \"F\") # => 140\nconvert_temp(373.15, \"K\",  \"N\") # => 33\nconvert_temp(   666, \"K\",  \"K\") # => 666\n*/\nconst toCelcius = {\n  C: function(t) { return t },\n  F: function(t) { return (t - 32) * 5 / 9 },\n  K: function(t) { return t - 273.15 },\n  R: function(t) { return (t - 491.67) * 5 / 9 },\n  De: function(t) { return 100 - t * 2 / 3 },\n  N: function(t) { return t * 100 / 33 },\n  Re: function(t) { return t * 5 / 4 },\n  Ro: function(t) { return (t - 7.5) * 40 / 21 }\n}\n\nconst fromCelcius = {\n  C: function(t) { return t },\n  F: function(t) { return t * 9 / 5 + 32 },\n  K: function(t) { return t + 273.15 },\n  R: function(t) { return (t + 273.15) * 9 / 5 },\n  De: function(t) { return (100 - t) * 3 / 2 },\n  N: function(t) { return t * 33 / 100 },\n  Re: function(t) { return t * 4 / 5 },\n  Ro: function(t) { return t * 21 / 40 + 7.5 }\n}\nfunction convertTemp(temp, from, to) {\n  if (from === to) return temp\n  temp = toCelcius[from](temp)\n  temp = fromCelcius[to](temp)\n  return Math.round(temp)\n}\n"
  },
  {
    "path": "The Book of Mormon.js",
    "content": "/*\nDescription:\nThe Mormons are trying to find new followers and in order to do that they embark on missions.\n\nEach time they go on a mission, every Mormons converts a fixed number of people (reach) into followers. This continues and every freshly converted Mormon as well as every original Mormon go on another mission and convert the same fixed number of people each. The process continues until they reach a predefined target number of followers (input into the model).\n\nConverted Mormons are unique so that there's no duplication amongst them.\n\nCreate a function Mormons(startingNumber, reach, target) that calculates how many missions Mormons need to embark on, in order to reach their target. While each correct solution will pass, for more fun try to make a recursive function.\n\nAll model inputs are valid positive integers.\n*/\nfunction Mormons(startingNumber, reach, target){\n  let n = startingNumber\n  for (var i=0;;i++){\n    if (n>=target) return i\n    n+=n*reach\n  }\n}\n"
  },
  {
    "path": "The Deaf Rats of Hamelin.js",
    "content": "/*\nDescription:\nStory\nThe Pied Piper has been enlisted to play his magical tune and coax all the rats out of town.\n\nBut some of the rats are deaf and are going the wrong way!\n\nKata Task\nHow many deaf rats are there?\n\nLegend\nP = The Pied Piper\nO~ = Rat going left\n~O = Rat going right\nExample\nex1 ~O~O~O~O P has 0 deaf rats\nex2 P O~ O~ ~O O~ has 1 deaf rat\nex3 ~O~O~O~OP~O~OO~ has 2 deaf rats\n*/\n\nvar countDeafRats = function(town) {\n  // Your code here\n  if(town != null){\n    [left,right]=town.split('P');\n        var a=left+right.split('').reverse().join('');\n        var b=(a.match(/O~|~O/gi)||[]).filter(v=>v=='O~').length;\n         return b;\n  }\n  return 0;   \n}\n"
  },
  {
    "path": "The Desperate Rocket Scientist.js",
    "content": "/*\nJim, the rocket scientist has finished the code for the board computer of his new Mars rocket. Only one last function is missing, the function for creating the countdown. Because Jim is always nervous when starting a new rocket, he sometimes forgets a number when doing the final countdown from ten to zero, so in order to be sure everything will work perfectly on the great day, he wrote a JavaScript function that does the countdown for him.\n\nToday is rocket launch day, and Jim has a big problem. The unit test for the countdown suddenly fails! Jim could swear that the unit tests were all green yesterday, and that he didn't change anything in the countdown function. He suspects that his assistant Jeff has introduced a bug somewhere in the rocket board computer startup code, but he cannot understand how that could affect the output of his countdown method in such a strange way. Oh, if Jim and Jeff had only learned a bit more JavaScript working on Codewars katas!\n\nJim is desperate because the countdown function has already been burned into a ROM deep inside the board computer that cannot be easily replaced. He has to fix the problem by calling a method in the startup code that is still accessible. Can you help poor Jim?\n\nHere is Jim's countdown code that he is not able to change any more:\n\nfunction countdown() {\n  var ret = \"\";\n  var numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n  for (var number in numbers) {\n    if (ret) ret += \", \";\n    if (number < 10)\n      number = 10 - number;\n    else if (number == 10)\n      number = \"Zero\";\n    ret += number;\n  }\n  ret += \"!\";\n  return ret;\n}\nWrite a function fix_countdown() that contains a fix to make countdown() work again.\n*/\nfunction fix_countdown() {\n   delete Array.prototype.Dammit\n}\n"
  },
  {
    "path": "The Enigma Machine - Part 1: The Plugboard.js",
    "content": "/*\nDescription:\nIn this series of Kata, we will be implementing a software version of the Enigma Machine.\n\nThe Enigma Machine was a message enciphering/deciphering machine used during the Second World War for disguising the content of military communications. Alan Turing - the father of computing - formulated and developed concepts that are the basis of all computers in use today, he did this in response to the vital need to break those military communications. Turing and his colleagues at Bletchley Park are generally recognised as being responsible for shortening WWII by two years and saving an estimated 22 Million lives.\n\nThe Enigma Machine consisted of a number of parts: Keyboard for input, rotors and plugboard for enciphering, and lampboard for output.\n\nWe will simulate input and output with strings, and build the rotors, plugboard and mechanism that used them in software. As we progress the code will become more complex, so you are advised to attempt them in order.\n\nStep 1: The plugboard\n\nIn this Kata, you must implement the plugboard.\n\nPhysical Description\nThe plugboard crosswired the 26 letters of the latin alphabet togther, so that an input into one letter could generate output as another letter. If a wire was not present, then the input letter was unchanged. Each plugboard came with a maximum of 10 wires, so at least six letters were not cross-wired.\n\nFor example:\n\nIf a wire connects A to B, then an A input will generate a B output and a B input will generate an A output.\n\nIf no wire connects to C, then only a C input will generate a C output.\n\nNote\nIn the actual usage of the original Enigma Machine, punctuation was encoded as words transmitted in the stream, in our code, anything that is not in the range A-Z will be returned unchanged.\n\nKata\nThe Plugboard class you will implement, will:\n\nTake a list of wire pairs at construction in the form of a string, with a default behaviour of no wires configured. E.g. \"ABCD\" would wire A <-> B and C <-> D.\nValidate that the wire pairings are legitimate. Raise an exception if not.\nImplement the process method to translate a single character input into an output.\nExamples\nvar plugboard = Plugboard(\"ABCDEFGHIJKLMNOPQRST\")\nplugboard.process(\"A\") ==> \"B\"\nplugboard.process(\"B\") ==> \"A\"\nplugboard.process(\"X\") ==> \"X\"\nplugboard.process(\".\") ==> \".\"\n*/\nPlugboard = function(wires) {\n  wires = wires || '';\n\n  if (!wires.match(/^([A-Z][A-Z]){0,10}$/)) \n    throw Error();\n    \n  if (wires.match(/(.).*\\1/)) \n    throw Error();\n\n  this.process = function(wire) {\n    var i = wires.indexOf(wire);\n    return i == -1 ? wire : wires[i + 1 - 2 * (i % 2)];\n  }\n}\n"
  },
  {
    "path": "The Freeway Game.js",
    "content": "/*\nDescription:\n\nBack-Story\nEvery day I travel on the freeway.\n\nWhen I am more bored than usual I sometimes like to play the following counting game I made up:\n\nAs I join the freeway my count is 0\nAdd 1 for every car that I overtake\nSubtract 1 for every car that overtakes me\nStop counting when I reach my exit\nWhat an easy game! What fun!\n\nKata Task\nYou will be given\n\nThe distance to my exit (km)\nHow fast I am going (kph)\nInformation about a lot of other cars\nTheir time (relative to me) as I join the freeway. For example,\n-1.5 means they already passed my starting point 1.5 minutes ago\n2.2 means they will pass my starting point 2.2 minutes from now\nHow fast they are going (kph)\nFind what is my \"score\" as I exit the freeway!\n\nNotes\nAssume all cars travel at a constant speeds\n Safety Warning \n\nIf you plan to play this \"game\" remember that it is not really a game. You are in a real car.\n\nThere may be a temptation to try to beat your previous best score.\n\nPlease don't do that...\n*/\nvar freewayGame = function(distKmToExit, mySpeedKmPH, otherCars) {\n    let myTimeToExit = distKmToExit / mySpeedKmPH;\n    return otherCars.reduce((a, [lead, speed]) => a\n        + (lead < 0 && myTimeToExit * speed < distKmToExit + lead / 60 * speed)\n        - (lead > 0 && myTimeToExit * speed > distKmToExit + lead / 60 * speed), 0);\n}\n"
  },
  {
    "path": "The Modulo-3 Sequence.js",
    "content": "/*\nDescription:\n#Task: Consider a sequence where the first two numbers are 0 and 1 and the next number of the sequence is the sum of the previous 2 modulo 3. Write a function that finds the nth number of the sequence.\n\n#Constraints:\n\n1 ≤ N ≤ 10^19\n#Example:\n\nsequence(1);\n0\nsequence(2);\n1\nsequence(3);\n1\n*/\nfunction sequence(n){\n  return [1,0,1,1,2,0,2,2][n%8];\n}\n"
  },
  {
    "path": "The Most Sacred of Days.js",
    "content": "/*\nDescription:\nIn the United States, one of the most important days of the year is colloquially known as \"Black Friday\". On this day, millions of pilgrims sojourn to their local centers of capitalism to stand in long lines and trade currency for flat-screen TVs and two-dollar DVDs.\n\nBlack Friday—so-called because on this day some retailers' accounting books move from \"the red\" (having net losses) to \"the black\" (having net profits)—is traditionally celebrated on the day immediately following the American Thanksgiving holiday, which always falls on the fourth Thursday in November.\n\nYou have recently been hired by a large boat retailer, Beast Bouy, who wants to know exactly what date they can expect shoppers to crowd their store and purchase their stocks of moderately discounted jet-skis. Your first task at this job is create a blackFriday function which accepts an integer year, and returns the day of the month of November that Black Friday falls on in that year. Your function only needs to support years after 1752*.\n*/\nfunction blackFriday(year) {\n  let i=29\n  while (new Date(year,10,i).getDay()!==5){\n    i--\n  }\n  return  new Date(year,10,i).getDate()\n}\n"
  },
  {
    "path": "The Non-Discriminate Factorial.js",
    "content": "/*\nDescription:\nThe factorial function is widely found in pure mathematics, most commonly in combinatorics and discrete probability. Typically the factorial is a function defined over nonnegative integers in such a way: For n=0, factorial(n) = 1. For n>0,\n\nfactorial(n) = n*(n-1)*...*2*1.\n\nFor example, factorial(2) = 2, factorial(4) = 24. It might seem odd that factorial(0) = 1, but it is more of a convenience than anything else.\n\nThis problem requires you to define an extended version of the factorial function, one that accepts all integers! For nonnegative integers, your function should behave as above. For n<0,\n\nfactorial(n) = (n)*(n+1)*...*(-2)*(-1).\n\nFor example, factorial(-1) = -1, factorial(-2) = 2, factorial(-3) = -6.\n\nGet to it! Also, note that you will only get integers as input. No need for error messages:)\n*/\nfunction factorial(n) {\n  let stop=n\n  if (n>0){\n    for (let i=1;i<stop;i++){\n      n*=i\n    }\n    return n\n  }\n  if (n<0){\n    for (let i=n+1;i<0;i++){\n      n*=i\n    }\n    return n\n  }\n  return 1\n}\n"
  },
  {
    "path": "The Office V - Find a Chair.js",
    "content": "/*\nDescription:\nSo you've found a meeting room - phew! You arrive there ready to present, and find that someone has taken one or more of the chairs!! You need to find some quick.... check all the other meeting rooms to see if all of the chairs are in use.\n\nYour meeting room can take up to 8 chairs. need will tell you how many have been taken. You need to find that many.\n\nFind the spare chairs from the array of meeting rooms. Each meeting room array will have the number of occupants as a string. Each occupant is represented by 'X'. The room array will also have an integer telling you how many chairs there are in the room.\n\nYou should return an array of integers that shows how many chairs you take from each room in order, up until you have the required amount.\n\nexample: [['XXX', 3], ['XXXXX', 6], ['XXXXXX', 9], ['XXX',2]] when you need 4 chairs:\n\nresult -- > [0, 1, 3] (no chairs free in room 0, take 1 from room 1, take 3 from room 2. No need to consider room 4 as you have your 4 chairs already.\n\nIf you need no chairs, return 'Game On'. If there aren't enough spare chairs available, return 'Not enough!'\n\nMore in this series:\n\nThe Office I - Outed\nThe Office II - Boredeom Score\nThe Office III - Broken Photocopier\nThe Office IV - Find a Meeting Room\n*/\nfunction meeting(x, need){\n  let arr = [];\n  x.map(v=>arr.push(v[1]-v[0].length>=0?v[1]-v[0].length:0))\n  for (let i=0;i<=arr.length;i++){\n  if (arr.slice(0,i).reduce((a,b)=>a+b,0)>=need){arr=arr.slice(0,i);break}\n  }\n  while(arr.reduce((a,b)=>a+b,0)>need){\n    arr[arr.length-1]--\n  }\n  if (need===0) return 'Game On'\n  if (arr.reduce((a,b)=>a+b,0)<need) return 'Not enough!'\n  return arr\n}\n"
  },
  {
    "path": "The Shell Game.js",
    "content": "/*\nDescription:\n\"The Shell Game\" involves three shells/cups/etc upturned on a playing surface, with a ball placed underneath one of them. The shells are then rapidly swapped round, and the game involves trying to track the swaps and, once they are complete, identifying the shell containing the ball.\n\nThis is usually a con, but you can assume this particular game is fair...\n\nYour task is as follows. Given the shell that the ball starts under, and list of swaps, return the location of the ball at the end. All shells are indexed by the position they are in at the time.\n\nFor example, given the starting position 0 and the swap sequence [(0, 1), (1, 2), (1, 0)]:\n\nThe first swap moves the ball from 0 to 1\n\nThe second swap moves the ball from 1 to 2\n\nThe final swap doesn't affect the position of the ball.\n\nSo\n\nswaps = [[0,1], [1,2], [1, 0]]\nfind_the_ball(0, swaps) == 2\nThere aren't necessarily only three cups in this game, but there will be at least two. You can assume all swaps are valid, and involve two distinct indices.\n*/\nfind_the_ball=function(start,swaps){\n  swaps.forEach(function (val) {\n        if (val[0] === start) {\n            start = val[1];\n        } else if (val[1] === start) {\n            start = val[0];\n        }\n    });\n    return start;\n};\n"
  },
  {
    "path": "The Spider and the Fly (Jumping Spider).js",
    "content": "/*\nDescription:\nBackground\nA spider web is defined by\n\n\"rings\" numbered out from the centre as 0, 1, 2, 3, 4\n\"radials\" labelled clock-wise from the top as A, B, C, D, E, F, G, H\nHere is a picture to help explain:\n\nsource: imgur.com\nWeb Coordinates\nAs you can see, each point where the rings and the radials intersect can be described by a \"web coordinate\".\n\nSo in this example the spider is at H3 and the fly is at E2\n\nKata Task\nOur friendly jumping spider is resting and minding his own spidery business at web-coordinate spider.\n\nAn inattentive fly bumbles into the web at web-coordinate fly and gets itself stuck.\n\nYour task is to calculate and return the distance the spider must jump to get to the fly.\n\nExample\nThe solution to the scenario described by the picture is 4.63522\n\nNotes\nThe centre of the web will always be referred to as A0\nThe rings intersect the radials at evenly spaced distances of 1 unit\nGood Luck!\nDM\n*/\nvar spiderToFly = function(spider, fly) {\n  const a = spider.split``[1]*1\n  const b = fly.split``[1]*1\n  const angles = 'CBAHGFED'\n  const y = Math.abs(angles.indexOf(spider.split``[0])-angles.indexOf(fly.split``[0]))*45\n  const side = Math.sqrt((a*a)+(b*b)-2*a*b*Math.cos(Math.toRadians(y)))\n  return side;\n}\nMath.toRadians = function(degrees) {\n  return degrees/(180/Math.PI)\n}\n"
  },
  {
    "path": "The Supermarket Queue.js",
    "content": "/*\nDescription:\nThere is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!\n\nThe function has two input variables:\n\ncustomers: an array (list in python) of positive integers representing the queue. Each integer represents a customer, and its value is the amount of time they require to check out.\nn: a positive integer, the number of checkout tills.\nThe function should return an integer, the total time required.\n\nEDIT: A lot of people have been confused in the comments. To try to prevent any more confusion:\n\nThere is only ONE queue, and\nThe order of the queue NEVER changes, and\nAssume that the front person in the queue (i.e. the first element in the array/list) proceeds to a till as soon as it becomes free.\nThe diagram on the wiki page I linked to at the bottom of the description may be useful.\nSo, for example:\n\nqueueTime([5,3,4], 1)\n// should return 12\n// because when n=1, the total time is just the sum of the times\n\nqueueTime([10,2,3,3], 2)\n// should return 10\n// because here n=2 and the 2nd, 3rd, and 4th people in the \n// queue finish before the 1st person has finished.\n\nqueueTime([2,3,10], 2)\n// should return 12\nN.B. You should assume that all the test input will be valid, as specified above.\n\nP.S. The situation in this kata can be likened to the more-computer-science-related idea of a thread pool, with relation to running multiple processes at the same time: https://en.wikipedia.org/wiki/Thread_pool\n*/\n\nfunction queueTime(customers, n) {\n  let w = new Array(n).fill(0);\n  for (let t of customers) {\n    let idx = w.indexOf(Math.min(...w));\n    w[idx] += t;\n  }\n  return Math.max(...w);\n}\n"
  },
  {
    "path": "The Vowel Code.js",
    "content": "/*\nDescription:\nStep 1: Create a function called encode() to replace all the lowercase vowels in a given string with numbers according to the following pattern:\n\na -> 1\n\ne -> 2\n\ni -> 3\n\no -> 4\n\nu -> 5\n\nFor example, encode(\"hello\") would return \"h2ll4\" There is no need to worry about uppercase vowels in this kata.\n\nStep 2: Now create a function called decode() to turn the numbers back into vowels according to the same pattern shown above.\n\nFor example, decode(\"h3 th2r2\") would return \"hi there\"\n\nFor the sake of simplicity, you can assume that any numbers passed into the function will correspond to vowels.\n*/\nfunction encode(string){\n  return string.replace(/[aeiou]/g,v=>{\n  if (v==='a') return 1\n  if (v==='e') return 2\n  if (v==='i') return 3\n  if (v==='o') return 4\n  if (v==='u') return 5\n  })\n}\n\nfunction decode(string){\n    return string.replace(/[1-5]/g,v=>{\n  if (v==='1') return 'a'\n  if (v==='2') return 'e'\n  if (v==='3') return 'i'\n  if (v==='4') return 'o'\n  if (v==='5') return 'u'\n  })\n}\n"
  },
  {
    "path": "The elegance of the code.js",
    "content": "/*\nDescription:\nThis program runs well but we need to make it more elegant.\n\nTry to rewrite the code of the function factorial in way to use recursion.\n\nYou cannot use looping(for, while, forEach).\n\nNote: If you find another solution this kata isn't for you, you're in a higher level.\n\nReturn examples\n\nfactorial(3)=>3 x 2 x 1 = 6\n\nfactorial(2)=>2 x 1 = 2\n\nfactorial(0)=>1 = 1\n*/\nfunction factorial(num){\n  return num>1?num*factorial(num-1):1;\n}\n"
  },
  {
    "path": "The maximum and minimum difference -- Simple version",
    "content": "/*\nDescription:\nWhen no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said\n\nDescription:\nGiven two array of integers(arr1,arr2). Your task is going to find a pair of numbers(an element in arr1, and another element in arr2), their difference is as big as possible(absolute value); Again, you should to find a pair of numbers, their difference is as small as possible. Return the maximum and minimum difference values by an array: [ max difference, min difference ]\n\nFor example:\n\n Given arr1 = [3,10,5], arr2 = [20,7,15,8]\n should return [17,2] because 20 - 3 = 17, 10 - 8 = 2\nNote:\narr1 and arr2 contains only integers(positive, negative or 0);\narr1 and arr2 may have different lengths, they always has at least one element;\nAll inputs are valid.\nThis is a simple version, if you want some challenges, try the challenge version.\nSome Examples\n maxAndMin([3,10,5],[20,7,15,8]) === [17,2]\n maxAndMin([3],[20]) === [17,17]\n maxAndMin([3,10,5],[3,10,5]) === [7,0]\n maxAndMin([1,2,3,4,5],[6,7,8,9,10]) === [9,1]\n*/\n\nconst maxAndMin = (array1, array2) => [\n    Math.max(...array1.map(x => Math.max(...array2.map(y => Math.abs(x - y))))),\n    Math.min(...array1.map(x => Math.min(...array2.map(y => Math.abs(x - y)))))\n];\n"
  },
  {
    "path": "The maximum sum value of ranges -- Simple version.js",
    "content": "/*\nDescription:\nWhen no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said\n\nDescription:\nGiven an array arr that contains some integers(positive, negative or 0), and a range list such as [[start1,end1],[start2,end2],...], start and end are the index of arr and start always less than end. Your task is to calculate the sum value of each range (start index and end index are both inclusive), and return the maximum sum value.\n\nFor example:\n\n Given arr = [1,-2,3,4,-5,-4,3,2,1], \n       range = [[1,3],[0,4],[6,8]]\n should return 6\n\n calculation process:\n range[1,3] = arr[1]+arr[2]+arr[3] = 5\n range[0,4] = arr[0]+arr[1]+arr[2]+arr[3]+arr[4] = 1\n range[6,8] = arr[6]+arr[7]+arr[8] = 6\n So the maximum sum value is 6\nNote:\narr/$a always has at least 5 elements;\nrange/$range/ranges always has at least 1 element;\nAll inputs are valid;\nThis is a simple version, if you want some challenge, please try the challenge version.\nSome Examples\n maxSum([1,-2,3,4,-5,-4,3,2,1],[[1,3],[0,4],[6,8]]) === 6\n maxSum([1,-2,3,4,-5,-4,3,2,1],[[1,3]]) === 5\n maxSum([1,-2,3,4,-5,-4,3,2,1],[[1,4],[2,5]]) === 0\n*/\nfunction maxSum(arr,range){\n  let ans = []\n  for (let i=0;i<range.length;i++){\n    ans.push(arr.slice(range[i][0],range[i][1]+1).reduce((a,b)=>a+b,0))\n  }\n  return Math.max(...ans)\n}\n"
  },
  {
    "path": "The nth smallest integer.js",
    "content": "/*\nDescription:\nGiven a list of integers, return the nth smallest integer in the list. Only distinct elements should be considered when calculating the answer. n will always be positive (n > 0)\n\nIf the nth small integer doesn't exist, return -1 (C++) / None (Python) / nil (Ruby) / null (JavaScript).\n\nNotes:\n\n\"indexing\" starts from 1\nhuge lists (of 1 million elements) will be tested\nExamples\nnthSmallest([1, 3, 4, 5], 7)        ==> null  // n is more than the size of the list\nnthSmallest([4, 3, 4, 5], 4)        ==> null  // 4th smallest integer doesn't exist\nnthSmallest([45, -10, 4, 5, 4], 4)  ==> 45   // 4th smallest integer is 45\nIf you get a timeout, just try to resubmit your solution. However, if you always get a timeout, review your code.\n*/\nfunction nthSmallest(arr, n) {\n  const a = Array.from(new Set(arr)).sort((a,b) => a-b)[n-1];\n  return a===undefined?null:a\n}\n"
  },
  {
    "path": "The range() function.js",
    "content": "/*\nDescription:\nLet's implement the range function:\n\nrange([start], stop, [step])\n\nrange(1, 11);\n=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n\nrange(1, 4, 0); // /!\\ note that the step is 0\n=> [1, 1, 1]\n\nrange(0);\n=> []\n\nrange(10, 0); // /!\\ note that the end is before the start\n=> []\n\nrange(10);\n=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n\nrange(0, 30, 5);\n=> [0, 5, 10, 15, 20, 25]\nstart, if omitted, defaults to 0; step defaults to 1.\n\nReturns a list of integers from start to stop, incremented (or decremented) by step, exclusive.\n\nNote that ranges that stop before they start are considered to be zero-length instead of negative.\n*/\nfunction range(start = 0, end, step = 1) {\n  if(end === undefined){end = start, start = 0;}\n  let range = [];\n  let steps = (end - start) / (step || 1);\n  for(let i = 0; i < steps; i++) {\n    range.push(start)\n    start += step;\n  }\n  return range;\n}\n"
  },
  {
    "path": "The takeWhile Function.js",
    "content": "/*\nDescription:\nHere's another staple for the functional programmer. You have a sequence of values and some predicate for those values. You want to get the longest prefix of elements such that the predicate is true for each element. We'll call this the takeWhile function. It accepts two arguments. The first is the sequence of values, and the second is the predicate function. The function does not change the value of the original sequence.\n\nfunction isEven(num) {\n  return num % 2 === 0;\n}\nvar seq = [2,4,6,8,1,2,5,4,3,2];\n\ntakeWhile(seq, isEven) // -> [2,4,6,8]\nYour task is to implement the takeWhile function.\n\nIf you've got a span function lying around, this is a one-liner! Also, if you liked this problem, you'll surely love the dropWhile function.\n*/\nfunction takeWhile (arr, pred) {\n  return arr.map(v=>pred(v)).indexOf(false)===-1?arr:arr.slice(0,arr.map(v=>pred(v)).indexOf(false))\n}\n"
  },
  {
    "path": "Think how isArray function can be implemented.js",
    "content": "/*\nDescription:\nYou know Array.isArray was already implement in ECMAScript 5.1 (ECMA-262). So this will be the polyfill.\n\nUse Array.isArray to define method.\n\nFor example:\n\nArray.isArray( [1,2,3] );  // true\nArray.isArray( new Array() ); // true\n\nArray.isArray( undefined ); // false\nArray.isArray(17); // false\n*/\nArray.isArray = function(value) {\n  return Object.prototype.toString.call(value) === '[object Array]';\n};\n"
  },
  {
    "path": "Thinkful - Logic Drills: Red and bumpy.js",
    "content": "/*\nDescription:\nYou're playing a game with a friend involving a bag of marbles. In the bag are ten marbles:\n\n1 smooth red marble\n4 bumpy red marbles\n2 bumpy yellow marbles\n1 smooth yellow marble\n1 bumpy green marble\n1 smooth green marble\nYou can see that the probability of picking a smooth red marble from the bag is 1 / 10 or 0.10 and the probability of picking a bumpy yellow marble is 2 / 10 or 0.20.\n\nThe game works like this: your friend puts her hand in the bag, chooses a marble (without looking at it) and tells you whether it's bumpy or smooth. Then you have to guess which color it is before she pulls it out and reveals whether you're correct or not.\n\nYou know that the information about whether the marble is bumpy or smooth changes the probability of what color it is, and you want some help with your guesses.\n\nWrite a function color_probability() that takes two arguments: a color ('red', 'yellow', or 'green') and a texture ('bumpy' or 'smooth') and returns the probability as a decimal fraction accurate to two places.\n\nThe probability should be a string and should discard any digits after the 100ths place. For example, 2 / 3 or 0.6666666666666666 would become the string '0.66'. Note this is different from rounding.\n\nAs a complete example, color_probability('red', 'bumpy') should return the string '0.57'.\n*/\nfunction colorProbability(color, texture){\n  if (texture===\"smooth\") return '0.33'\n  if (color===\"red\"&&texture===\"bumpy\") return '0.57'\n  if (color===\"green\"&&texture===\"bumpy\") return '0.14'\n  if (color===\"yellow\"&&texture===\"bumpy\") return '0.28'\n}\n"
  },
  {
    "path": "Three added Characters.js",
    "content": "/*\nDescription:\nGiven two strings, the first being a random string and the second being the same as the first, but with three added characters somewhere in the string (three same characters),\n\nWrite a function that returns the added character\n\nE.g\nstring1 = \"hello\"\nstring2 = \"aaahello\"\n\n// => 'a'\nThe above is just an example; the characters could be anywhere in the string and string2 is actually shuffled.\n\nAnother example\nstring1 = \"abcde\"\nstring2 = \"2db2a2ec\"\n\n// => '2'\nNote that the added character could also exist in the original string\n\nstring1 = \"aabbcc\"\nstring2 = \"aacccbbcc\"\n\n// => 'c'\nYou can assume that string2 will aways be larger than string1, and there will always be three added characters in string2.\n\nWrite the function addedChar() that takes two strings and return the added character as described above.\n\nCan you do it in O(m+n) or O(n) time and O(1) Space ?\n\nWhen you're done you'll be shown the average runtime your code took to finish all test cases; feel free to include it at the top of your solution ;)\n\n** Collapse 'Test cases' or scroll down to the end of the test cases to see your code's Average runtime **\n*/\nfunction addedChar(s1, s2){\n  const obj1={};\n  const obj2={};\n  s1.split``.map(v=>obj1[v]=obj1[v]?obj1[v]+1:1)\n  s2.split``.map(v=>obj2[v]=obj2[v]?obj2[v]+1:1)\n  for (let i in obj2){ \n    if (obj2[i]>obj1[i]||obj1[i]===undefined) return i\n  }\n}\n"
  },
  {
    "path": "Throwing Darts.js",
    "content": "/*\nDescription:\nYou've just recently been hired to calculate scores for a Dart Board game!\n\nScoring specifications:\n\n0 points - radius above 10\n5 points - radius between 5 and 10 inclusive\n10 points - radius less than 5\nIf all radiuses are less than 5, award 100 BONUS POINTS!\n\nWrite a function that accepts an array of radiuses (can be integers and/or floats), and returns a total score using the above specification.\n\nAn empty array should return 0.\n\nExamples:\nscoreThrows( [1, 5, 11] )    =>  15\nscoreThrows( [15, 20, 30] )  =>  0\nscoreThrows( [1, 2, 3, 4] )  =>  140\n*/\nfunction scoreThrows(r){\n  if (r.length===0) return 0\n  let score=0;\n  for (let i=0;i<r.length;i++){\n  \n    if (r[i]>=5&&r[i]<=10)score+=5\n    if (r[i]<5)score+=10\n    \n  }\n  if (r.every(v=>v<5)) score+=100\n  return score\n}\n"
  },
  {
    "path": "Tick Toward.js",
    "content": "/*\nDescription:\nDefine a function that generates medial values between two coordinates and returns them in an array from start to target. For example, if the starting point is [1,1] and the target point is [3,2] then the shortest route from start to target would be [[1,1], [2,2], [3,2]]. The route should go only through integral coordinates.\n\nNote: you should move diagonally until the path from your current position to the target can be represented as a fully horizontal/vertical line.\n\nExamples:\ntickToward([5,5],[5,7])  // => [[5,5],[5,6],[5,7]]\ntickToward([3,2],[4,5])  // => [[3,2],[4,3],[4,4],[4,5]]\ntickToward([5,1],[5,-2]) // => [[5,1],[5,0],[5,-1],[5,-2]]\n*/\nfunction tickToward([s1,s2],[e1,e2]){\n  let arr1 = [];\n  let arr2 = [];\n  if (e1<s1){\n    for (let i=s1;i>=e1;i--){\n      arr1.push(i)\n    }\n  } \n  else {\n    for (let i=s1;i<=e1;i++){\n      arr1.push(i)\n    } \n  }\n    if (e2<s2){\n    for (let i=s2;i>=e2;i--){\n      arr2.push(i)\n    }\n  } else {\n    for (let i=s2;i<=e2;i++){\n      arr2.push(i)\n    } \n  }\n  let max = Math.max(arr1.length,arr2.length)\n  let arr3 = [];\n  for (let i=0;i<max;i++){\n    arr3.push([(arr1[i]?arr1[i]:arr1[i]===0?0:arr1[arr1.length-1]),(arr2[i]?arr2[i]:arr2[i]===0?0:arr2[arr2.length-1])])\n  }\n  return arr3\n}\n"
  },
  {
    "path": "Time-like string format.js",
    "content": "/*\nDescription:\nBuild up a method that takes an integer and formats it to a 'time - like' format.\n\nThe method must raise an exception if its hour length is less than 3 digits and greater than 4.\n\nExample:\nsolution(800); // should return '8:00'\nsolution(1000); // should return '10:00'\nsolution(1451); // should return '14:51'\nsolution(3351); // should return '33:51'\nsolution(10000); // should raise an exception\n*/\nfunction solution(hour) {\n  let str=hour.toString()\n  if (str.length>4||str.length<3) throw Error()\n  if (str.length===4) return str[0]+str[1]+':'+str[2]+str[3]\n  else return  str[0]+':'+str[1]+str[2]\n}\n"
  },
  {
    "path": "Title Case",
    "content": "/*\nDescription:\nA string is considered to be in title case if each word in the string is either (a) capitalised (that is, only the first letter of the word is in upper case) or (b) considered to be an exception and put entirely into lower case unless it is the first word, which is always capitalised.\n\nWrite a function that will convert a string into title case, given an optional list of exceptions (minor words). The list of minor words will be given as a string with each word separated by a space. Your function should ignore the case of the minor words string -- it should behave in the same way even if the case of the minor word string is changed.\n\n###Arguments (Haskell)\n\nFirst argument: space-delimited list of minor words that must always be lowercase except for the first word in the string.\nSecond argument: the original string to be converted.\n###Arguments (Other languages)\n\nFirst argument (required): the original string to be converted.\nSecond argument (optional): space-delimited list of minor words that must always be lowercase except for the first word in the string. The JavaScript/CoffeeScript tests will pass undefined when this argument is unused.\n###Example\n\ntitleCase('a clash of KINGS', 'a an the of') // should return: 'A Clash of Kings'\ntitleCase('THE WIND IN THE WILLOWS', 'The In') // should return: 'The Wind in the Willows'\ntitleCase('the quick brown fox') // should return: 'The Quick Brown Fox'\n*/\n\nfunction titleCase(title, minorWords) {\n  var minorWords = typeof minorWords !== \"undefined\" ? minorWords.toLowerCase().split(' ') : [];\n  return title.toLowerCase().split(' ').map(function(v, i) {\n    if(v != \"\" && ( (minorWords.indexOf(v) === -1) || i == 0)) {\n      v = v.split('');\n      v[0] = v[0].toUpperCase();\n      v = v.join('');\n    }\n    return v;\n  }).join(' ');\n}\n"
  },
  {
    "path": "Tortoise racing",
    "content": "/*\nDescription:\nTwo tortoises named A and B must run a race. A starts with an average speed of 720 feet per hour. Young B knows she runs faster than A, and furthermore has not finished her cabbage.\n\nWhen she starts, at last, she can see that A has a 70 feet lead but B's speed is 850 feet per hour. How long will it take B to catch A?\n\nMore generally: given two speeds v1 (A's speed, integer > 0) and v2 (B's speed, integer > 0) and a lead g (integer > 0) how long will it take B to catch A?\n\nThe result will be an array [hour, min, sec] which is the time needed in hours, minutes and seconds (round down to the nearest second) or a string in some languages.\n\nIf v1 >= v2 then return nil, nothing, null, None or {-1, -1, -1} for C++, C, Go, Nim, [] for Kotlin or \"-1 -1 -1\".\n\nExamples:\n(form of the result depends on the language)\n\nrace(720, 850, 70) => [0, 32, 18] or \"0 32 18\"\nrace(80, 91, 37)   => [3, 21, 49] or \"3 21 49\"\n**Note:\n\nSee other examples in \"Your test cases\".\n\nIn Fortran - as in any other language - the returned string is not permitted to contain any redundant trailing whitespace: you can use dynamically allocated character strings.\n*/\n\nfunction race(v1, v2, g) {\n  \n   if (v2 <= v1) \n    return null;\n  \n   var res = Math.floor(3600*g/(v2-v1));\n  return [Math.floor(res/3600), Math.floor(res/60)%60, res%60];\n }\n"
  },
  {
    "path": "Transform To Prime.js",
    "content": "/*\nDescription:\nTask :\nGiven a List [] of n integers , find minimum mumber to be inserted in a list, so that sum of all elements of list should equal the closest prime number .\n\nNotes\nList size is at least 2 .\n\nList's numbers will only positives (n > 0) .\n\nRepeatition of numbers in the list could occur .\n\nThe newer list's sum should equal the closest prime number .\n\nInput >> Output Examples\n1- minimumNumber ({3,1,2}) ==> return (1)\nExplanation:\nSince , the sum of the list's elements equal to (6) , the minimum number to be inserted to transform the sum to prime number is (1) , which will make *the sum of the List** equal the closest prime number (7)* .\n2-  minimumNumber ({2,12,8,4,6}) ==> return (5)\nExplanation:\nSince , the sum of the list's elements equal to (32) , the minimum number to be inserted to transform the sum to prime number is (5) , which will make *the sum of the List** equal the closest prime number (37)* .\n3- minimumNumber ({50,39,49,6,17,28}) ==> return (2)\nExplanation:\nSince , the sum of the list's elements equal to (189) , the minimum number to be inserted to transform the sum to prime number is (2) , which will make *the sum of the List** equal the closest prime number (191)* .\n*/\nfunction minimumNumber(numbers){\n  let sum= numbers.reduce((a,b)=>a+b,0)\n  for (let i=0;;i++){\n  if (isPrime(sum+i)){return i}\n  }\n}\nfunction isPrime(n) {\n  let rt = Math.sqrt(n);\n  for(let i = 2; i <= rt; i++) {\n    if(n % i === 0) return false; \n  }\n  return n !== 1;\n}\n"
  },
  {
    "path": "Tree Depth.js",
    "content": "/*\nDescription:\nWrite a method that takes a nested hash (object in javascript) as input and returns that hash with added \"depth\" keys. So, for example, the following input:\n\n{ a: 1, b: 2, c: { d: { e: 3 } } }\nwould yield the following return value:\n\n{ a: 1, b: 2, c: { d: { e: 3, depth: 2 }, depth: 1 }, depth: 0 }\nFor Ruby, if the input is not a hash, then the function should return nil. For JavaScript, if the input is not an object (including an array), the function should return null.\n*/\n\nfunction recordDepth(tree, d = 0) {\n  if (!tree || typeof tree !== 'object' || Array.isArray(tree)) return null\n  tree.depth = d\n  let keys = Object.keys(tree)\n  for (let k of keys) {\n    if (typeof tree[k] === 'object') {\n      recordDepth(tree[k], d + 1)\n    }\n  }\n  return tree\n}\n"
  },
  {
    "path": "Triangle number check.js",
    "content": "/*\nDescription:\nA triangle number is a number where n objects form an equilateral triangle (it's a bit hard to explain). For example, 6 is a triangle number because you can arrange 6 objects into an equilateral triangle:\n\n  1\n 2 3\n4 5 6\n8 is not a triangle number because 8 objects do not form an equilateral triangle:\n\n   1\n  2 3\n 4 5 6\n7 8\nIn other words, the nth triangle number is equal to the sum of the n natural numbers from 1 to n.\n\nYour task:\nCheck if a given input is a valid triangle number. Return true if it is, false if it is not (note that any non-integers, including non-number types, are not triangle numbers).\n\nYou are encouraged to develop an effective algorithm: test cases include really big numbers.\n\nAssumptions:\nYou may assume that the given input, if it is a number, is always positive.\n\nNotes:\n0 and 1 are triangle numbers.\n*/\n\nfunction isTriangleNumber(number) {\n return Math.sqrt(number*8+1)===Math.sqrt(number*8+1).toFixed(0)*1\n}\n"
  },
  {
    "path": "Triangle type",
    "content": "/*\nDescription:\nIn this kata, you should calculate type of triangle with three given sides a, b and c (given in any order).\n\nIf all angles are less than 90°, this triangle is acute and function should return 1.\n\nIf one angle is strictly 90°, this triangle is right and function should return 2.\n\nIf one angle more than 90°, this triangle is obtuse and function should return 3.\n\nIf three sides cannot form triangle, or one angle is 180° (which turns triangle into segment) - function should return 0.\n\nInput parameters are sides of given triangle. All input values are non-negative floating point or integer numbers (or both).\n\n\nAcute\n\nRight\n\nObtuse\nExamples:\ntriangleType(2, 4, 6); // return 0 (Not triangle)\ntriangleType(8, 5, 7); // return 1 (Acute, angles are approx. 82°, 38° and 60°)\ntriangleType(3, 4, 5); // return 2 (Right, angles are approx. 37°, 53° and exactly 90°)\ntriangleType(7, 12, 8); // return 3 (Obtuse, angles are approx. 34°, 106° and 40°)\nIf you stuck, this can help you: http://en.wikipedia.org/wiki/Law_of_cosines. But you can solve this kata even without angle calculation.\n\nThere is very small chance of random test to fail due to round-off error, in such case resubmit your solution.\n*/\n\n\nfunction triangleType(a, b, c){\n  const max = Math.max(a,b,c);\n  \n  if (a+b+c <= 2*max) return 0;\n  if (2*max*max == a*a+b*b+c*c) return 2;\n  if (2*max*max >  a*a+b*b+c*c) return 3;\n  return 1;\n}\n"
  },
  {
    "path": "Tribonacci Sequence",
    "content": "/*\nDescription:\nWell met with Fibonacci bigger brother, AKA Tribonacci.\n\nAs the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :(\n\nSo, if we are to start our Tribonacci sequence with [1, 1, 1] as a starting input (AKA signature), we have this sequence:\n\n[1, 1 ,1, 3, 5, 9, 17, 31, ...]\nBut what if we started with [0, 0, 1] as a signature? As starting with [0, 1] instead of [1, 1] basically shifts the common Fibonacci sequence by once place, you may be tempted to think that we would get the same sequence shifted by 2 places, but that is not the case and we would get:\n\n[0, 0, 1, 1, 2, 4, 7, 13, 24, ...]\nWell, you may have guessed it by now, but to be clear: you need to create a fibonacci function that given a signature array/list, returns the first n elements - signature included of the so seeded sequence.\n\nSignature will always contain 3 numbers; n will always be a non-negative number; if n == 0, then return an empty array and be ready for anything else which is not clearly specified ;)\n\nIf you enjoyed this kata more advanced and generalized version of it can be found in the Xbonacci kata\n\n[Personal thanks to Professor Jim Fowler on Coursera for his awesome classes that I really recommend to any math enthusiast and for showing me this mathematical curiosity too with his usual contagious passion :)]\n*/\n\nfunction tribonacci(signature,n){\n  let arr=[...signature];\n  for (let i=0;i<n;i++){\n  arr.push(arr.slice(i,i+3).reduce((acc,next)=>acc+next,0))\n  }\n  \n  return arr.slice(0,-3)\n}\n"
  },
  {
    "path": "Trim a String.js",
    "content": "/*\nDescription:\nDefine a function trim (JavaScript: method String.prototype.trim) which removes all forms of leading and trailing whitespace from a given string. Please refer to the Sample Tests for more examples.\n*/\nString.prototype.trim = function() {\n  return this.replace(/^\\s+/g,'').replace(/\\s+$/g,'');\n};\n"
  },
  {
    "path": "Triple trouble",
    "content": "/*\nDescription:\nWrite a function\n\ntripledouble(num1,num2)\nwhich takes in numbers num1 and num2 and returns 1 if there is a straight triple of a number at any place in num1 and also a straight double of the same number in num2.\nFor example:\ntripledouble(451999277, 41177722899) == 1 // num1 has straight triple 999s and \n                                          // num2 has straight double 99s\n\ntripledouble(1222345, 12345) == 0 // num1 has straight triple 2s but num2 has only a single 2\n\ntripledouble(12345, 12345) == 0\n\ntripledouble(666789, 12345667) == 1\nIf this isn't the case, return 0\n*/\n\n\nfunction tripledouble(num1, num2) {\n  for (let i = 0; i < 10; i++) {\n    if (new RegExp(`${i}{3}`).test(num1) && new RegExp(`${i}{2}`).test(num2)) {\n      return 1;\n    }\n  }\n  return 0;\n}\n"
  },
  {
    "path": "Tug-o'-War.js",
    "content": "/*\nDescription:\nIn this Kata we will play a classic game of Tug-o'-War!\n\nTwo teams of 5 members will face off, the strongest of which will prevail. Each team member will be assigned a strength rating (1-9), with the most powerful members having a rating of 9. Your goal is to determine, based on the cumulative strength of the members of each team, which team will win the war.\n\nThe teams will be represented by an array of arrays:\n\n[[5,0,3,2,1], [1,6,8,2,9]]  // 11 < 26 ; \"Team 2 wins!\"\nYour task is to return a string with which team won or if it was a tie.\n\nIf team one is stronger, return the string \"Team 1 wins!\"\nIf team two is stronger, return the string \"Team 2 wins!\"\nIf the two teams are of equal strength, the team with the strongest Anchor (the member furthest from the center of the rope) will win. In the above example, the member with strength 5 is team one's Anchor and strength 9 is team two's Anchor.\n\nIf the teams and the Anchors are both of equal strength, return the string \"It's a tie!\"\nThe Anchors are members in each end of the rope:\n\nanchors\n\nmore examples:\n\n[[1,2,3,4,5], [1,2,3,4,5]] // Team 2 has stronger Anchor ; \"Team 2 wins!\"\n[[1,2,3,4,5], [5,4,3,2,1]] // Teams & Anchors are tied; \"It's a tie!\"\nGood luck!\n*/\nfunction tug_o_war(teams) {\n  let team1=teams[0].reduce((a,b)=>a+b,0)\n  let team2=teams[1].reduce((a,b)=>a+b,0)\n  if (team1===team2&&teams[0][0]>teams[1][teams[1].length-1]) return \"Team 1 wins!\"\n  if (team1===team2&&teams[0][0]<teams[1][teams[1].length-1]) return \"Team 2 wins!\"\n  if (team1>team2) return \"Team 1 wins!\"\n  if (team1<team2) return \"Team 2 wins!\"\n  if (team1===team2) return \"It's a tie!\"\n}\n"
  },
  {
    "path": "Turkish National Identity Number.js",
    "content": "/*\nDescription:\nEvery Turkish citizen has an identity number whose validity can be checked by these set of rules:\n\nIt is an 11 digit number\nFirst digit can't be zero\nTake the sum of 1st, 3rd, 5th, 7th and 9th digit and multiply it by 7. Then subtract the sum of 2nd, 4th, 6th and 8th digits from this value. Modulus 10 of the result should be equal to 10th digit.\nSum of first ten digits' modulus 10 should be equal to eleventh digit.\nExample:\n\n10167994524\n//  1+1+7+9+5= 23   // \"Take the sum of 1st, 3rd, 5th, 7th and 9th digit...\"\n//    23 * 7= 161   //  \"...and multiply it by 7\"\n//   0+6+9+4 = 19   // \"Take the sum of 2nd, 4th, 6th and 8th digits...\"\n// 161 - 19 = 142   // \"...and subtract from first value\"\n// \"Modulus 10 of the result should be equal to 10th digit\"\n10167994524\n         ^ = 2 = 142 % 10\n// 1+0+1+6+7+9+9+4+5+2 = 44\n// \"Sum of first ten digits' modulus 10 should be equal to eleventh digit\"\n10167994524\n          ^ = 4 = 44 % 10\nYour task is to write a function to check the validity of a given number. Return true or false accordingly.\n\nNote: The input can be a string in some cases.\n*/\nfunction checkValidTrNumber(n) {\n  n=n.toString()\n  if (n[0]=='0'||n.length!==11) return false\n  let step1 = n.split``.slice(0,10).filter((v,i)=>i%2===0).reduce((a,b)=>a+b*1,0)*7\n  let step2 = n.split``.slice(0,9).filter((v,i)=>i%2!==0).reduce((a,b)=>a+b*1,0)\n  let step3 = (step1-step2)%10===n[9]*1\n  let step4 = n.slice(0,10).split``.reduce((a,b)=>a+b*1,0)%10===n[10]*1\n  return step3&&step4\n}\n"
  },
  {
    "path": "Two Joggers",
    "content": "/*\nDescription:\nTwo Joggers\nDescription\nBob and Charles are meeting for their weekly jogging tour. They both start at the same spot called \"Start\" and they each run a different lap, which may (or may not) vary in length. Since they know each other for a long time already, they both run at the exact same speed.\n\nIllustration\nExample where Charles (dashed line) runs a shorter lap than Bob:\n\nExample laps\n\nTask\nYour job is to complete the function nbrOfLaps(x, y) that, given the length of the laps for Bob and Charles, finds the number of laps that each jogger has to complete before they meet each other again, at the same time, at the start.\n\nThe function takes two arguments:\n\nThe length of Bob's lap (larger than 0)\nThe length of Charles' lap (larger than 0)\n\nThe function should return an array (Tuple<int, int> in C#) containing exactly two numbers:\n\nThe first number is the number of laps that Bob has to run\nThe second number is the number of laps that Charles has to run\n\nExamples:\n\nnbrOfLaps(5, 3); // returns [3, 5]\nnbrOfLaps(4, 6); // returns [3, 2]\n*/\n\nvar nbrOfLaps = function(x, y) {\n  var lcm = x;\n  while(lcm % y != 0) {lcm += x;}\n  return [lcm / x, lcm / y];\n}\n"
  },
  {
    "path": "Two Sum.js",
    "content": "/*\nDescription:\nWrite a function that takes an array of numbers (integers for the tests) and a target number. It should find two different items in the array that, when added together, give the target value. The indices of these items should then be returned in an array like so: [index1, index2].\n\nFor the purposes of this kata, some tests may have multiple answers; any valid solutions will be accepted.\n\nThe input will always be valid (numbers will be an array of length 2 or greater, and all of the items will be numbers; target will always be the sum of two different items from that array).\n\nBased on: http://oj.leetcode.com/problems/two-sum/\n*/\n\nfunction twoSum(numbers, target) {\n  for (let i = 0; i < numbers.length; i++) {\n    for (let j = i + 1; j < numbers.length; j++) {\n      if (numbers[i] + numbers[j] === target) return [i, j];\n    }\n  }\n}\n"
  },
  {
    "path": "Two cube sums.js",
    "content": "/*\nDescription:\nCreate a function\n\nhasTwoCubeSums(n) \nwhich checks if a given number n can be written as the sum of two cubes in two different ways: n = a³+b³ = c³+d³. All the numbers a, b, c and d should be different and greater than 0.\n\nE.g. 1729 = 9³+10³ = 1³+12³.\n\nhasTwoCubeSums(1729); // true\nhasTwoCubeSums(42);   // false\n*/\nfunction hasTwoCubeSums(n) {\n        let cnt = 0;\n        let limit = Math.cbrt(n);\n        let sum;\n        for (let i = 1; i <= limit; i++) {\n            for (let j = i; j <= limit; j++) {\n                sum = (Math.pow(i, 3) + Math.pow(j, 3));\n                if (sum == n) {\n                    cnt++;\n                }\n            }\n        }\n        return cnt >= 2;\n    }\n"
  },
  {
    "path": "Typer.js",
    "content": "/*\nDescription:\nType checking in JavaScript\nSometimes it could be a good thing to check if an object is of a type T. Lets see this example:\n\nfunction doStuff(thing) {\n  return thing.map(function(item) {\n    return item * 2;\n  });\n}\nIf we call this function with an array, we get the expected result\n\ndoStuff([1,2,3]) //Array [ 2, 4, 6 ]\nBut if someone calls doStuff (ruby do_stuff) with a different type of argument, it will throw an exception, because most likely the argument object won't have a method map defined on it.\n\ndoStuff(3) //TypeError: thing.map is not a function\nApart from this, having methods like isArray (ruby Typer.is_array? obj), or isString (ruby Typer.is_string? obj) can rise readability when validating input arguments, and clears things up for fellow co-workers.\n\nYour task will be to create a basic type-checker \"framework/api\" for JavaScript (or for Ruby). Let's call it typer.js (ruby Typer class). Your API must contain the following methods:\n\nisNumber (ruby is_number?)\nisString (ruby is_string?)\nisArray (ruby is_array?)\nisFunction (ruby do not implement this)\nisDate (ruby is_time?)\nisRegExp (ruby is_regexp?)\nisBoolean (ruby is_boolean?)\nisError (ruby is_exception?)\nisNull (ruby is_nil?)\nisUndefined (ruby is_nil?)\nCreate these utility methods for input validation. For example, if the argument is a number, then isNumber called with this argument should return true.\n\nExample\nassert.equal(typer.isNumber(5), true);\nassert.equal(typer.isString({}), false);\nNote\nIf you are stuck, feel free to check how known utility libraries do the exact same thing. Check them on GitHub ;)\n\nMotivation\nPossibly after this kata the warriors who just started to learn JavaScript will learn that sometimes the conventional ways of type checking in JavaScript in not sufficient enough, since, for example, not only \"simple\" numbers are considered as numbers, but numbers created by Number constructors, etc.\n\nThis kata has also been translated to Ruby\n*/\nvar typer = (function(TO_BE_DEFINED_BY_YOU) {\n  return {\n    isNumber:(TO_BE_DEFINED_BY_YOU)=>typeof TO_BE_DEFINED_BY_YOU.valueOf() === \"number\"&&!isNaN(TO_BE_DEFINED_BY_YOU),\n    isString:(TO_BE_DEFINED_BY_YOU)=>typeof TO_BE_DEFINED_BY_YOU ==='string'||TO_BE_DEFINED_BY_YOU instanceof String,\n    isArray: (TO_BE_DEFINED_BY_YOU)=>Array.isArray(TO_BE_DEFINED_BY_YOU),\n    isFunction: (TO_BE_DEFINED_BY_YOU)=>typeof TO_BE_DEFINED_BY_YOU ==='function',\n    isDate: (TO_BE_DEFINED_BY_YOU)=> TO_BE_DEFINED_BY_YOU instanceof Date,\n    isRegExp: (TO_BE_DEFINED_BY_YOU)=> TO_BE_DEFINED_BY_YOU instanceof RegExp,\n    isBoolean: (TO_BE_DEFINED_BY_YOU)=>typeof TO_BE_DEFINED_BY_YOU ==='boolean'||TO_BE_DEFINED_BY_YOU instanceof Boolean,\n    isError: (TO_BE_DEFINED_BY_YOU)=> TO_BE_DEFINED_BY_YOU instanceof Error,\n    isNull: (TO_BE_DEFINED_BY_YOU)=>TO_BE_DEFINED_BY_YOU ===null,\n    isUndefined: (TO_BE_DEFINED_BY_YOU)=>TO_BE_DEFINED_BY_YOU ===undefined\n  };\n}(null));\n"
  },
  {
    "path": "Unary function chainer.js",
    "content": "/*\nDescription:\nYour task is to write a higher order function for chaining together a list of unary functions. In other words, it should return a function that does a left fold on the given functions.\n\nchained([a,b,c,d])(input)\nShould yield the same result as\n\nd(c(b(a(input))))\n*/\n\nfunction chained(functions) {\n  return input => functions.reduce((res, func) => func(res), input);\n}\n"
  },
  {
    "path": "Unique In Order",
    "content": "/*\nDescription:\nImplement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements.\n\nFor example:\n\nuniqueInOrder('AAAABBBCCDAABBB') == ['A', 'B', 'C', 'D', 'A', 'B']\nuniqueInOrder('ABBCcAD')         == ['A', 'B', 'C', 'c', 'A', 'D']\nuniqueInOrder([1,2,2,3,3])       == [1,2,3]\n*/\n\nvar uniqueInOrder=function(iterable){\n if (typeof iterable === 'string') return iterable.split('').filter((v,i,arr)=>arr[i]!=arr[i+1]);\n return iterable.filter((v,i,arr)=>arr[i]!=arr[i+1]);\n}\n"
  },
  {
    "path": "Unwanted dollars.js",
    "content": "/*\nDescription:\nIf you're faced with an input box, like this:\n\n                                           +--------------+\n  Enter the price of the item, in dollars: |              |\n                                           +--------------+\ndo you put the $ sign in, or not? Inevitably, some people will type a $ sign and others will leave it out. The instructions could be made clearer - but that won't help those annoying people who never read instructions anyway.\n\nA better solution is to write code that can handle the input whether it includes a $ sign or not.\n\nSo, we need a simple function that converts a string representing a number (possibly with a $ sign in front of it) into the number itself.\n\nRemember to consider negative numbers (the - sign may come either before or after the $ sign, if there is one), and any extraneous space characters (leading, trailing, or around the $ sign) that the users might put in. You do not need to handle trailing characters other than spaces (e.g. \"1.2 3\"). If the given string does not represent a number, (either with or without a $ sign), return 0.0 .\n*/\nconst money_value = s => +s.replace(/\\s|\\$/g, '') || 0\n"
  },
  {
    "path": "Update inventory in your smartphone store.js",
    "content": "/*\nDescription:\nYou will be given an array which lists the current inventory of stock in your store and another array which lists the new inventory being delivered to your store today.\n\nYour task is to write a function that returns the updated list of your current inventory in alphabetical order.\n\nExample\ncurrentStock = [[25, 'HTC'], [1000, 'Nokia'], [50, 'Samsung'], [33, 'Sony'], [10, 'Apple']]\nnewStock = [[5, 'LG'], [10, 'Sony'], [4, 'Samsung'], [5, 'Apple']]\n\nupdateInventory(currentStock, newStock)  ==>\n[[15, 'Apple'], [25, 'HTC'], [5, 'LG'], [1000, 'Nokia'], [54, 'Samsung'], [43, 'Sony']]\nKata inspired by the FreeCodeCamp's 'Inventory Update' algorithm.\n*/\nfunction updateInventory(curStock, newStock) {\n  let dict = [...curStock,...newStock].reduce((a,b)=>(a[b[1]]=a[b[1]]+b[0]||b[0],a),{})\n  return Object.entries(dict).map(v=>[v[1],v[0]]).sort((a,b)=>a[1].localeCompare(b[1]))\n}\n"
  },
  {
    "path": "Upside down numbers.js",
    "content": "/*\nDescription:\nConsider the numbers 6969 and 9116. When you rotate them 180 degrees (upside down), these numbers remain the same. To clarify, if we write them down on a paper and turn the paper upside down, the numbers will be the same. Try it and see! Some numbers such as 2 or 5 don't yield numbers when rotated.\n\nGiven a range, return the count of upside down numbers within that range. For example, solve(0,10) = 3, because there are only 3 upside down numbers >= 0 and < 10. They are 0, 1, 8.\n\nMore examples in the test cases.\n\nGood luck!\n\nIf you like this Kata, please try\n\nSimple Prime Streaming\n\nLife without primes\n\nPlease also try the performance version of this kata at Upside down numbers - Challenge Edition\n*/\nfunction solve(x, y) {\n  const invalid = [\"2\",\"3\",\"4\",\"5\",\"7\"]\n  let arr = []\n  for(let i = x; i <y; i++) {\n    let valid = true\n    invalid.map(n => {\n      if(i.toString().includes(n)) valid = false\n    })\n    if (valid) arr.push(i+'')\n  }\n  return arr.filter(n => n === n.replace(/6|9/g,v=>v==='6'?'9':'6').split``.reverse().join``).length\n};\n"
  },
  {
    "path": "Upside-Down Pyramid Addition...REVERSED!.js",
    "content": "/*\nDescription:\nIf this challenge is too easy for you, check out: https://www.codewars.com/kata/5cc89c182777b00001b3e6a2\n\nUpside-Down Pyramid Addition is the process of taking a list of numbers and consecutively adding them together until you reach one number.\n\nWhen given the numbers 2, 1, 1 the following process occurs:\n\n 2   1   1\n   3   2 \n     5\nThis ends in the number 5.\n\nYOUR TASK\nGiven the right side of an Upside-Down Pyramid (Ascending), write a function that will return the original list.\n\nEXAMPLE\nreverse([5, 2, 1]) => [2, 1, 1]\nNOTE: The Upside-Down Pyramid will never be empty and will always consist of positive integers ONLY.\n\n\n*/\nfunction reverse(right) {\n  let arr = [[...right]]\n  let temp = []\n  for (let i=0;arr[i].length!==1;i++){\n    for (let j=1;j<arr[i].length;j++){\n      temp.push(arr[i][j-1]-arr[i][j])\n    }\n    arr.push(temp)\n    temp=[]\n  }\n  return arr.map(v=>v[v.length-1]).reverse()\n}\n"
  },
  {
    "path": "Urban Dictionary.js",
    "content": "/*\nDescription:\nDesign a data structure that supports the following two operations:\n\naddWord (or add_word) which adds a word,\nsearch which searches a literal word or a regular expression string containing lowercase letters \"a-z\" or \".\" where \".\" can represent any letter\nYou may assume that all given words contain only lowercase letters.\n\nExamples\naddWord(\"bad\")\naddWord(\"dad\")\naddWord(\"mad\")\n\nsearch(\"pad\") === false\nsearch(\"bad\") === true\nsearch(\".ad\") === true\nsearch(\"b..\") === true\nNote: the data structure will be initialized multiple times during the tests!\n*/\nvar WordDictionary = function () {\n  this.arr = []\n};\n\nWordDictionary.prototype.addWord = function (word) {\n   this.arr.push(word)\n};\n\nWordDictionary.prototype.search = function (word) {\n   let reg = new RegExp('^'+word+'$')\n   return this.arr.find(v=>reg.test(v))!==undefined\n};\n"
  },
  {
    "path": "Valid Braces",
    "content": "/*\nDescription:\nWrite a function that takes a string of braces, and determines if the order of the braces is valid. It should return true if the string is valid, and false if it's invalid.\n\nThis Kata is similar to the Valid Parentheses Kata, but introduces new characters: brackets [], and curly braces {}. Thanks to @arnedag for the idea!\n\nAll input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: ()[]{}.\n\nWhat is considered Valid?\nA string of braces is considered valid if all braces are matched with the correct brace.\n\nExamples\n\"(){}[]\"   =>  True\n\"([{}])\"   =>  True\n\"(}\"       =>  False\n\"[(])\"     =>  False\n\"[({})](]\" =>  False\n*/\n\nfunction validBraces(braces){\n while(/\\(\\)|\\[\\]|\\{\\}/g.test(braces)){braces = braces.replace(/\\(\\)|\\[\\]|\\{\\}/g,\"\")}\n return !braces.length;\n}\n"
  },
  {
    "path": "Valid Phone Number",
    "content": "/*\nDescription:\nWrite a function that accepts a string, and returns true if it is in the form of a phone number. \nAssume that any integer from 0-9 in any of the spots will produce a valid phone number.\n\nOnly worry about the following format:\n(123) 456-7890 (don't forget the space after the close parentheses) \n\nExamples:\n\nvalidPhoneNumber(\"(123) 456-7890\")  =>  returns true\nvalidPhoneNumber(\"(1111)555 2345\")  => returns false\nvalidPhoneNumber(\"(098) 123 4567\")  => returns false\n*/\n\nfunction validPhoneNumber(phoneNumber){\n  return (/^\\(\\d{3}\\)\\ \\d{3}\\-\\d{4}$/).test(phoneNumber)\n}\n"
  },
  {
    "path": "Valid string.js",
    "content": "/*\nDescription:\nYou are given an array of valid words and a string. Test if the string is made up by one or more words from the array. For example:\n\nstring[] dictionary = [\"code\", \"wars\"]; \n\nstring s = \"codewars\"; // true \n\nstring s1 = \"codewar\"; // false\n*/\nvar validWord = function(d, word) {\nd=d.sort((a,b)=>a.length-b.length)\nfor (let i=0;i<d.length;i++){\n   word=word.replace(new RegExp(d[i],'g'),'')\n }\n return !word.length\n};\n"
  },
  {
    "path": "Validate Credit Card Number.js",
    "content": "/*\nDescription:\nIn this Kata, you will implement the Luhn Algorithm, which is used to help validate credit card numbers.\n\nGiven a positive integer of up to 16 digits, return true if it is a valid credit card number, and false if it is not.\n\nHere is the algorithm:\n\nDouble every other digit, scanning from right to left, starting from the second digit (from the right).\n\nAnother way to think about it is: if there are an even number of digits, double every other digit starting with the first; if there are an odd number of digits, double every other digit starting with the second:\n\n1714 ==> [1*, 7, 1*, 4] ==> [2, 7, 2, 4]\n\n12345 ==> [1, 2*, 3, 4*, 5] ==> [1, 4, 3, 8, 5]\n\n891 ==> [8, 9*, 1] ==> [8, 18, 1]\nIf a resulting number is greater than 9, replace it with the sum of its own digits (which is the same as subtracting 9 from it):\n\n[8, 18*, 1] ==> [8, (1+8), 1] ==> [8, 9, 1]\n\nor:\n\n[8, 18*, 1] ==> [8, (18-9), 1] ==> [8, 9, 1]\nSum all of the final digits:\n\n[8, 9, 1] ==> 8 + 9 + 1 = 18\nFinally, take that sum and divide it by 10. If the remainder equals zero, the original credit card number is valid.\n\n  18 (modulus) 10 ==> 8 , which is not equal to 0, so this is not a valid credit card number\n\n*/\n\nfunction validate(n){\n  return [...String(n)]\n    .reverse()\n    .map((val, index) => index % 2 ? val * 2 : Number(val))\n    .map((val, index) => val > 9 ? val - 9 : val)\n    .reduce((prev, curr) => prev + curr) % 10 ? false : true;\n}\n"
  },
  {
    "path": "Vasya - Clerk.js",
    "content": "/*\nDescription:\nThe new \"Avengers\" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollars bill. An \"Avengers\" ticket costs 25 dollars.\n\nVasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.\n\nCan Vasya sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?\n\nReturn YES, if Vasya can sell a ticket to each person and give the change with the bills he has at hand at that moment. Otherwise return NO.\n\nExamples:\ntickets([25, 25, 50]) // => YES \ntickets([25, 100]) // => NO. Vasya will not have enough money to give change to 100 dollars\ntickets([25, 25, 50, 50, 100]) // => NO. Vasya will not have the right bills to give 75 dollars of change (you can't make two bills of 25 from one of 50)\n*/\n\nfunction tickets(peopleInLine){\n  let [c25,c50,c100] = [0,0,0];\n  for(let v of peopleInLine) {\n    if(v===25) c25++;\n    if(v===50) {c50++; c25--;}\n    if(v===100) {c25--; c50>0?c50--:c25-=2;}\n    if(c25<0||c50<0) return 'NO'\n  }\n  return 'YES'\n}\n"
  },
  {
    "path": "Vasya and Stairs.js",
    "content": "/*\nDescription:\nVasya wants to climb up a stair of certain amount of steps (Input parameter 1). There are 2 simple rules that he has to stick to.\n\nVasya can climb 1 or 2 steps at each move.\nVasya wants the number of moves to be a multiple of a certain integer. (Input parameter 2).\n###Task: What is the MINIMAL number of moves making him climb to the top of the stairs that satisfies his conditions?\n\n###Input\n\nNumber of stairs: 0 < N ≤ 10000 ;\nInteger to be multiplied : 1 < M ≤ 10;\n###Output\n\nReturn a single integer - the minimal number of moves being a multiple of M;\nIf there is no way he can climb satisfying condition return - 1 instead.\n###Examples\n\nnumberOfSteps(10, 2) => 6  // Sequence of steps : {2, 2, 2, 2, 1, 1}\n\nnumberOfSteps(3, 5) => -1 // !Possible sequences of steps : {2, 1}, {1, 2}, {1, 1, 1}\n*/\nfor (let i = Math.ceil(steps / 2); i <= steps; i++) {\n        if (i % m === 0) {\n            return i;\n        }\n    }\n    return -1;\n"
  },
  {
    "path": "Vasya and System of Equations.js",
    "content": "/*\nDescription:\nVasya isn't really good at math. However, he wants to get a good mark for the class. So he made a deal with his teacher. \"I wil study very hard and will be able to solve any given problem!\" - Vasya said.\n\nFinally, today is the time to show what Vasya achieved. He solved the given task immediately. Can you?\n\nTask:\nYou are given a system of equations:\n\n\n\nIn JS, C# and Java the parameters of the system: 1 ≤ n, m ≤ 1000\n\nYou should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system.\n\nExamples\nsolution(9,3) // => 1\nsolution(14,28) // => 1\nsolution(4,20) // => 0\n*/\nfunction solution(n, m){\n   let count = 0\n   for (let i=0;i<n;i++){\n     for (let j=0;j<m;j++){\n       if (i*i+j===n&&i+j*j===m) count++\n     }\n   }\n   return count\n}\n"
  },
  {
    "path": "Vowel Recognition.js",
    "content": "/*\nDescription:\n{a, e, i, o, u, A, E, I, O, U}\n\nNatural Language Understanding is the subdomain of Natural Language Processing where people used to design AI based applications have ability to understand the human languages. HashInclude Speech Processing team has a project named Virtual Assistant. For this project they appointed you as a data engineer (who has good knowledge of creating clean datasets by writing efficient code). As a data engineer your first task is to make vowel recognition dataset. In this task you have to find the presence of vowels in all possible substrings of the given string. For each given string you have to return the total number of vowels.\n\nExample\nGiven a string \"baceb\" you can split it into substrings: b, ba, bac, bace, baceb, a, ac, ace, aceb, c, ce, ceb, e, eb, b. The number of vowels in each of these substrings is 0, 1, 1, 2, 2, 1, 1, 2, 2, 0, 1, 1, 1, 1, 0; if you sum up these number, you get 16 - the expected output.\n\nNote: your solution should have linear time complexity.\n*/\nfunction vowelRecognition(input){\n  let count = 0, vowels = ['a', 'e', 'i', 'o', 'u'];\n  let formatInput = input.toLowerCase();\n  for (let letterPosition in formatInput){\n    if (vowels.includes(formatInput[letterPosition])){\n      count += ((formatInput.length - letterPosition) + (letterPosition * (formatInput.length - letterPosition)))\n    }\n  }\n  return count;\n}\n"
  },
  {
    "path": "Vowel Shifting.js",
    "content": "/*\nDescription:\nYou get a \"text\" and have to shift the vowels by \"n\" positions to the right.\n(Negative value for n should shift to the left.)\n\"Position\" means the vowel's position if taken as one item in a list of all vowels within the string.\nA shift by 1 would mean, that every vowel shifts to the place of the next vowel.\n\nShifting over the edges of the text should continue at the other edge.\n\nExample:\n\ntext = \"This is a test!\"\nn = 1\noutput = \"Thes is i tast!\"\n\ntext = \"This is a test!\"\nn = 3\noutput = \"This as e tist!\"\n\nIf text is null or empty return exactly this value.\nVowels are \"a,e,i,o,u\".\n\n\nHave fun coding it and please don't forget to vote and rank this kata! :-)\n\nI have created other katas. Have a look if you like coding and challenges.\n*/\nfunction vowelShift(text, n) {\n  if (typeof text !== 'string') return text\n  if (!/[aeiou]/gi.test(text)) return text\n  let arr = text.match(/[aeuoi]/gi).join``\n  let shift = (arr.slice(-n%arr.length)+arr.slice(0,-n%arr.length)).split``\n  let i = 0\n  return text.replace(/[aeuoi]/gi,v=>shift[i++])\n}\n"
  },
  {
    "path": "Walter's miraculous FizzBuzz factory.js",
    "content": "/*\nDescription:\nThe FizzBuzz factory\nWalter was a normal engineer. He built FizzBuzz functions every day. You might have heard of them. They return \"Fizz\", if your number is divisible by 3, \"Buzz\", if your number is divisible by 5, and \"FizzBuzz\" if your number is divisible by, well, both. For all other, boring numbers, the number itself was returned (but as a string, since Walter cared about types).\n\nHowever, those machines were so practical and beneficial to the whole society, that everyone copied Walter's machines. So he came up with a new idea: he would sell a personal FizzBuzz factory! That would bring his competitors out of business!\n\nTask\nIn this kata, you will get an array of unique numbers, paired with strings, like\n\n[(3, \"Fizz\"), (5, \"Buzz\"), (15, \"FizzBuzz\")]\nDepending on the language, that's either a list/array of tuples or an array of arrays. It's always sorted.\n\nYour job is to return another function, that—given a number n—returns the appropriate string. How do you know the correct string? Well, it's the one paired with the largest key that still divides the number n!\n\nExamples\nvar myFizz = fizzBuzzFactory([[3, \"Fizz\"], [5, \"Buzz\"], [15, \"FizzBuzz\"]])\nmyFizz(3)  === \"Fizz\"\nmyFizz(4)  === \"4\"\nmyFizz(5)  === \"Buzz\"\nmyFizz(15) === \"FizzBuzz\"\n\nvar myFooBar = fizzBuzzFactory([[2, \"Foo\"], [4, \"Bar\"], [6, \"FooBar\"]])\nmyFooBar(1)  === \"1\"\nmyFooBar(2)  === \"Foo\"\nmyFooBar(4)  === \"Bar\"\nmyFooBar(6)  === \"FooBar\"\nmyFooBar(8)  === \"Bar\"\nmyFooBar(10) === \"Foo\"\nmyFooBar(12) === \"FooBar\"\n*/\nfunction fizzBuzzFactory (arr){\n  let a = arr.slice().reverse()\n  return function(n){\n    return a.filter(v=>n%v[0]===0).length?a.filter(v=>n%v[0]===0)[0][1]:n.toString()\n  }\n}\n"
  },
  {
    "path": "WeIrD StRiNg CaSe",
    "content": "/*\nDescription:\nWrite a function toWeirdCase (weirdcase in Ruby) that accepts a string, and returns the same string with all even indexed characters in each word upper cased, and all odd indexed characters in each word lower cased. The indexing just explained is zero based, so the zero-ith index is even, therefore that character should be upper cased.\n\nThe passed in string will only consist of alphabetical characters and spaces(' '). Spaces will only be present if there are multiple words. Words will be separated by a single space(' ').\n\nExamples:\ntoWeirdCase( \"String\" );//=> returns \"StRiNg\"\n*/\n\nfunction toWeirdCase(string){\n  return string.split(' ').map((v,i)=>v.split('').map((v,i)=>i%2===0?v.toUpperCase():v.toLowerCase()).join('')).join(' ')\n}\n"
  },
  {
    "path": "What century is it?.js",
    "content": "/*\nDescription:\nReturn the inputted numerical year in century format. For example 2014, would return 21st.\n\nThe input will always be a 4 digit string. So there is no need for year string validation\n\nExamples:\nInput: 1999 Output: 20th\nInput: 2011 Output: 21st\nInput: 2154 Output: 22nd\nInput: 2259 Output: 23rd\nInput: 1124 Output: 12th\nInput: 2000 Output: 20th\n*/\nfunction whatCentury(year)\n{\n  let cent=year.toString().slice(0,2)*1\n  if (year%1000===0){\n   switch(cent){\n     case 10: return `10th`\n     case 20: return `20th`\n     case 30: return `30th`\n     }\n  }\n  cent=cent+1;\n  switch(cent){\n  case 11: return `${cent}th`\n  case 12: return `${cent}th`\n  case 13: return `${cent}th`\n  case 20: return `${cent}th`\n  case 21: return `${cent}st`\n  case 23: return `${cent}rd`\n  case 22: return `${cent}nd`\n  }\n}\n"
  },
  {
    "path": "What's in a name?.js",
    "content": "/*\nDescription:\nWhat's in a name?\n..Or rather, what's a name in? For us, a particular string is where we are looking for a name.\nTask\nTest whether or not the string contains all of the letters which spell a given name, in order.\n\nThe format\nA function passing two strings, searching for one (the name) within the other. ``function nameInStr(str, name){ return true || false }``\nExamples\nnameInStr(\"Across the rivers\", \"chris\") --> true\n            ^      ^  ^^   ^\n            c      h  ri   s\n\nContains all of the letters in \"chris\", in order.\nnameInStr(\"Next to a lake\", \"chris\") --> false\n\nContains none of the letters in \"chris\".\nnameInStr(\"Under a sea\", \"chris\") --> false\n               ^   ^\n               r   s\n\nContains only some of the letters in \"chris\".\nnameInStr(\"A crew that boards the ship\", \"chris\") --> false\n             cr    h              s i\n             cr                h  s i  \n             c     h      r       s i\n             ...\n\nContains all of the letters in \"chris\", but not in order.\nnameInStr(\"A live son\", \"Allison\") --> false\n           ^ ^^   ^^^\n           A li   son\n\nContains all of the correct letters in \"Allison\", in order, \nbut not enough of all of them (missing an 'l').\nNote: testing will not be case-sensative.\n*/\nfunction nameInStr(str, name){\n  str=str.toLowerCase()\n  name=name.toLowerCase()\n  let arr = str.split``.filter(v=>name.includes(v))\n  let pointer =0;\n  for (let i=0;i<arr.length;i++){\n    if (arr[i]===name[pointer]) pointer++\n  }\n  return pointer===name.length\n}\n"
  },
  {
    "path": "Wheel of Fortune.js",
    "content": "/*\nDescription:\nThree candidates take part in a TV show.\n\nIn order to decide who will take part in the final game and probably become rich, they have to roll the Wheel of Fortune!\n\nThe Wheel of Fortune is divided into 20 sections, each with a number from 5 to 100 (only mulitples of 5).\n\nEach candidate can roll the wheel once or twice and sum up the score of each roll. The winner one that is closest to 100 (while still being lower or equal to 100). In case of a tie, the candidate that rolled the wheel first wins.\n\nYou receive the information about each candidate as an array of objects: each object should have a name and a scores array with the candidate roll values.\n\nYour solution should return the name of the winner or false if there is no winner (all scored more than 100).\n\nExample:\n\nvar c1 = { name: \"Bob\", scores: [10, 65] };\nvar c2 = { name: \"Bill\", scores: [90, 5] };\nvar c3 = { name: \"Charlie\", scores: [40, 55] };\nwinner([c1, c2, c3]); // Returns \"Bill\"\nPlease note that inputs may be invalid: in this case, the function should return false.\n\nPotential errors derived from the specifications are:\n\nMore or less than three candidates take part in the game.\nA candidate did not roll the wheel or rolled it more than twice.\nScores are not valid.\nInvalid user entry (no name or no score).\n*/\nfunction winner(c) {\n  if (c.length!==3) return false\n  if (c.some(v=>!v.scores||!v.name)) return false\n  if (c.some(v=>!v.scores.every(v=>v%5==0))) return false\n  if (c.some(v=>v.scores.length>2||!v.scores.length)) return false\n  if (c.some(v=>v.scores.reduce((a,b)=>a+b,0)>100)) return false\n  return c.map(v=>[v.name,v.scores.reduce((a,b)=>a+b,0)]).sort((a,b)=>b[1]-a[1])[0][0]\n}\n"
  },
  {
    "path": "Where is my parent!?(cry).js",
    "content": "/*\nMothers arranged dance party for children in school.On that party there are only mothers and their children.All are having great fun on dancing floor when suddenly all lights went out.Its dark night and no one can see eachother.But you were flying nearby and you can see in the dark and have ability to teleport people anywhere you want.\n\nLegend:\n-Uppercase letters stands for mothers,lowercase stand for their children. I.E \"A\" mothers children are \"aaaa\".\n-Function input:String contain only letters,Uppercase letters are unique.\nTask:\nPlace all people in alphabetical order where Mothers are followed by their children.I.E \"aAbaBb\" => \"AaaBbb\".\n*/\nconst findChildren = dancingBrigade =>\n  dancingBrigade\n    .split('')\n    .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()) || b.localeCompare(a))\n    .join('')\n"
  },
  {
    "path": "Which are in?",
    "content": "/*\nDescription:\nGiven two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.\n\n#Example 1: a1 = [\"arp\", \"live\", \"strong\"]\n\na2 = [\"lively\", \"alive\", \"harp\", \"sharp\", \"armstrong\"]\n\nreturns [\"arp\", \"live\", \"strong\"]\n\n#Example 2: a1 = [\"tarp\", \"mice\", \"bull\"]\n\na2 = [\"lively\", \"alive\", \"harp\", \"sharp\", \"armstrong\"]\n\nreturns []\n\nNotes:\nArrays are written in \"general\" notation. See \"Your Test Cases\" for examples in your language.\n\nIn Shell bash a1 and a2 are strings. The return is a string where words are separated by commas.\n\nBeware: r must be without duplicates.\nDon't mutate the inputs.\n*/\n\nfunction inArray(array1,array2){\n  return array1.filter((x) => array2.some((y) => y.includes(x))).sort()\n}\n"
  },
  {
    "path": "Which filetypes are you using the most?.js",
    "content": "/*\nDescription:\nDescription\nYou've been working with a lot of different file types recently as your interests have broadened.\n\nBut what file types are you using the most? With this question in mind we look at the following problem.\n\nGiven a List/Array of Filenames (strings) files return a List/Array of string(s) contatining the most common extension(s). If there is a tie, return a sorted list of all extensions.\n\nImportant Info:\nDon't forget, you've been working with a lot of different file types, so expect some interesting extensions/file names/lengths in the random tests.\nFilenames and extensions will only contain letters (case sensitive), and numbers.\nIf a file has multiple extensions (ie: mysong.mp3.als) only count the the last extension (.als in this case)\nExamples\nfiles = ['Lakey - Better days.mp3', \n         'Wheathan - Superlove.wav', \n         'groovy jam.als', \n         '#4 final mixdown.als', \n         'album cover.ps', \n         'good nights.mp3']\nwould return: ['.als', '.mp3'], as both of the extensions appear two times in files.\n\nfiles = ['Lakey - Better days.mp3', \n         'Fisher - Stop it.mp3', \n         'Fisher - Losing it.mp3', \n         '#4 final mixdown.als', \n         'album cover.ps', \n         'good nights.mp3']\nwould return ['.mp3'], because it appears more times then any other extension, and no other extension has an equal amount of appearences.\n*/\nfunction solve(files) {\n  let dict = {}\n  let arr = [].concat(...files.map(v=>v.match(/\\.\\w+$/g))).map(v=>dict[v]=dict[v]?dict[v]+1:1)\n  let max = Math.max(...Object.values(dict)) \n  let answ = []\n  for (let i in dict){\n    if (dict[i]===max) answ.push(i)\n  }\n  let left = answ.filter(v=>v.split``.slice(1).some(v=>v===v.toUpperCase()&&!/[0-9]/.test(v))).sort((a,b)=>a.localeCompare(b))\n  let right = answ.filter(v=>!v.split``.slice(1).some(v=>v===v.toUpperCase()&&!/[0-9]/.test(v))).sort((a,b)=>a.localeCompare(b))\n  return [...left,...right]\n}\n"
  },
  {
    "path": "Who likes it?",
    "content": "/*\nDescription:\nYou probably know the \"like\" system from Facebook and other pages. People can \"like\" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item.\n\nImplement a function likes :: [String] -> String, which must take in input array, containing the names of people who like an item. It must return the display text as shown in the examples:\n\nlikes [] // must be \"no one likes this\"\nlikes [\"Peter\"] // must be \"Peter likes this\"\nlikes [\"Jacob\", \"Alex\"] // must be \"Jacob and Alex like this\"\nlikes [\"Max\", \"John\", \"Mark\"] // must be \"Max, John and Mark like this\"\nlikes [\"Alex\", \"Jacob\", \"Mark\", \"Max\"] // must be \"Alex, Jacob and 2 others like this\"\n*/\n\nfunction likes(names) {\n  if (names.length===0) return 'no one likes this';\n  if (names.length===1) return `${names[0]} likes this`;\n  if (names.length===2) return `${names[0]} and ${names[1]} like this`;\n  if (names.length===3) return `${names[0]}, ${names[1]} and ${names[2]} like this`;\n  return `${names[0]}, ${names[1]} and ${names.length-2} others like this`;\n}\n"
  },
  {
    "path": "Who won the election?.js",
    "content": "/*\nIn democracy we have a lot of elections. For example, we have to vote for a class representative in school, for a new parliament or a new government.\n\nUsually, we vote for a candidate, i.e. a set of eligible candidates is given. This is done by casting a ballot into a ballot-box. After that, it must be counted how many ballots (= votes) a candidate got.\n\nA candidate will win this election if he has the absolute majority.\n\nYour Task\nReturn the name of the winner. If there is no winner, return null (in Java and JavaScript), None (in Python) or nil (in Ruby).\nTask Description\nThere are no given candidates. An elector can vote for anyone. Each ballot contains only one name and represents one vote for this name. A name is an arbitrary string, e.g. \"A\", \"B\", or \"XJDHD\".\n\nThere are no spoiled ballots.\n\nThe ballot-box is represented by an unsorted list of names. Each entry in the list corresponds to one vote for this name. You do not know the names in advance (because there are no candidates).\n\nA name wins the election if it gets more than n/2 votes (n = number of all votes, i.e. n is equal to the size of the given list).\nExamples\n//3 votes for \"A\", 2 votes for \"B\" -> \"A\" wins the election\ngetWinner([\"A\", \"A\", \"A\", \"B\", \"B\"]) === \"A\" //true\n//2 votes for \"A\", 2 votes for \"B\" -> No winner\ngetWinner([\"A\", \"A\", \"B\", \"B\"]) === null //true\n//1 vote for each name -> No winner\ngetWinner([\"A\", \"B\", \"C\", \"D\"]) === null //true\n//3 votes for \"A\", 2 votes for \"B\", 1 vote for \"C\"  \n//-> No winner (\"A\" does not have more than n/2 = 3 votes)\ngetWinner([\"A\", \"A\", \"A\", \"B\", \"B\", \"C\"]) === null //true\nNote\nPlease keep in mind the list of votes can be large (n <= 1,200,000). The given list is immutable, i.e. you cannot modify the list (otherwise this could lead to vote rigging).\nGood luck and have fun.\n*/\nfunction getWinner(l) {\n  let win = l.length/2\n  let obj={};\n  l.map(v=>obj[v]=obj[v]?obj[v]+1:1)\n  for (let vote in obj){\n  if (obj[vote]>win) return vote\n  }\n  return null \n}\n"
  },
  {
    "path": "Wind component calculation.js",
    "content": "/*\nDescription:\nWhen landing an airplane manually, the pilot knows which runway he is using and usually has up to date wind information (speed and direction). This information alone does not help the pilot make a safe landing; what the pilot really needs to know is the speed of headwind, how much crosswind there is and from which side the crosswind is blowing relative to the plane.\n\nLet's imagine there is a system in the ATC tower with speech recognition that works so that when a pilot says \"wind info\" over the comms, the system will respond with a helpful message about the wind.\n\nYour task is to write a function that produces the response before it is fed into the text-to-speech engine.\n\nInput:\n\nrunway (string: \"NN[L/C/R]\"). NN is the runway's heading in tens of degrees. A suffix of L, C or R may be present and should be ignored. NN is between 01 and 36.\nwind_direction (int). Direction wind is blowing from in degrees. Between 0 and 359.\nwind_speed (int). Wind speed in knots\nOutput:\n\na string in the following format: \"(Head|Tail)wind N knots. Crosswind N knots from your (left|right).\"\nThe wind speeds must be correctly rounded integers. If the rounded headwind component is 0, \"Head\" should be used. Similarly, \"right\" in case crosswind component is 0.\n\nCalculating crosswind and headwind:\n\nA = Angle of the wind from the direction of travel (radians)\nWS = Wind speed\nCW = Crosswind\nHW = Headwind\n\nCW = sin(A) * WS\nHW = cos(A) * WS\nMore information about wind component calculation: http://en.wikipedia.org/wiki/Tailwind\n*/\nfunction windComponents(rwy, windDirection, windSpeed) {\n  let n = rwy.match(/\\d+/)[0]*10\n  let HW = Math.round(Math.cos((((windDirection-n)*Math.PI)/180))*windSpeed)\n  let CW = Math.round(Math.sin((((windDirection-n)*Math.PI)/180))*windSpeed)\n  let head=true;\n  let left=false\n  if (HW<0)head=false\n  if (CW<0)left=true\n  return `${head?'Head':'Tail'}wind ${Math.abs(HW)} knots. Crosswind ${Math.abs(CW)} knots from your ${left?'left':'right'}.`\n}\n"
  },
  {
    "path": "Word Mesh.js",
    "content": "/*\nDescription:\nYou will be given an array of strings. The words in the array should mesh together where the last few letters of one word will have the same letters (in the same order) as the next word in the array. But, there are times when all the words won't mesh.\n\nIf all the words in the given array mesh together, then your code should return the meshed letters in a string. You won't know how many letters the meshed words have in common, but it will be at least one.\n\nIf all the words don't mesh together, then your code should return \"failed to mesh\".\n\nInput: An array of strings. There will always be at least two words in the input array.\n\nOutput: Either a string of letters that mesh the words together or the string \"failed to mesh\".\n\nExamples\n#1:\n\n[\"allow\", \"lowering\", \"ringmaster\", \"terror\"] --> \"lowringter\"\nbecause:\n\nthe letters \"low\" in the first two words mesh together\nthe letters \"ring\" in the second and third word mesh together\nthe letters \"ter\" in the third and fourth words mesh together.\n#2:\n\n[\"kingdom\", \"dominator\", \"notorious\", \"usual\", \"allegory\"] --> \"failed to mesh\"\nAlthough the words \"dominator\" and \"notorious\" share letters in the same order, the last letters of the first word don't mesh with the first letters of the second word.\n*/\n\nfunction wordMesh(arr){\n  let r=\"\"\n  for(let i=0;i<arr.length-1;i++){\n    let t=(arr[i]+\" \"+arr[i+1]).match(/(.+) \\1/)\n    if(!t) return \"failed to mesh\"\n    r+=t[1]\n  }\n  return r\n}\n"
  },
  {
    "path": "Word Patterns.js",
    "content": "/*\nDescription:\nWrite\n\nfunction wordPattern(pattern, str)\nthat given a pattern and a string str, find if str follows the same sequence as pattern.\n\nFor example:\n\nwordPattern('abab', 'truck car truck car') === true\nwordPattern('aaaa', 'dog dog dog dog') === true\nwordPattern('abab', 'apple banana banana apple') === false\nwordPattern('aaaa', 'cat cat dog cat') === false\n*/\nfunction wordPattern(pattern, str) {\n  let arr = [...new Set(pattern.split``)]\n  let arr2 = [...new Set(str.split` `)]\n  let dict = {};\n  for (let i=0;i<arr.length;i++){\n    dict[arr[i]]=arr2[i]\n  }\n  return pattern.replace(/\\w/g,v=>dict[v])===str.split` `.join``\n}\n"
  },
  {
    "path": "Word Segmentation: MaxMatch.js",
    "content": "/*\nDescription:\nSome languages like Chinese, Japanese, and Thai do not have spaces between words. However, most natural languages processing tasks like part-of-speech tagging require texts that have segmented words. A simple and reasonably effective algorithm to segment a sentence into its component words is called \"MaxMatch\".\n\nMaxMatch\nMaxMatch starts at the first character of a sentence and tries to find the longest valid word starting from that character. If no word is found, the first character is deemed the longest \"word\", regardless of its validity. In order to find the rest of the words, MaxMatch is then recursively invoked on all of the remaining characters until no characters remain. A list of all of the words that were found is returned.\n\nSo for the string \"happyday\", \"happy\" is found because \"happyday\" is not a valid word, nor is \"happyda\", nor \"happyd\". Then, MaxMatch is called on \"day\", and \"day\" is found. The output is the list [\"happy\", \"day\"] in that order.\n\nThe Challenge\nWrite maxMatch, which takes an alphanumeric, spaceless, lowercased String as input and returns an Array of all the words found, in the order they were found. All valid words are in the Set VALID_WORDS, which only contains around 500 English words.\n\nNote: This algorithm is simple and operates better on Chinese text, so accept the fact that some words will be segmented wrongly.\n\nHappy coding :)\n*/\nfunction maxMatch(sentence){\n   const arr = []\n   for (let i=0;i<=sentence.length;i++){\n     for (let j=sentence.length;j>=0;j--){\n       if (VALID_WORDS.has(sentence.slice(i,j))){ arr.push(sentence.slice(i,j))\n         sentence=sentence.replace(sentence.slice(i,j),'*')\n         i=-1\n         break\n       }\n     }\n   }\n    let i=0\n    return sentence.split``.map(v=>v==='*'?arr[i++]:v)\n}\n"
  },
  {
    "path": "Word a10n (abbreviation)",
    "content": "/*\nDescription:\nThe word i18n is a common abbreviation of internationalization in the developer community, used instead of typing the whole word and trying to spell it correctly. Similarly, a11y is an abbreviation of accessibility.\n\nWrite a function that takes a string and turns any and all \"words\" (see below) within that string of length 4 or greater into an abbreviation, following these rules:\n\nA \"word\" is a sequence of alphabetical characters. By this definition, any other character like a space or hyphen (eg. \"elephant-ride\") will split up a series of letters into two words (eg. \"elephant\" and \"ride\").\nThe abbreviated version of the word should have the first letter, then the number of removed characters, then the last letter (eg. \"elephant ride\" => \"e6t r2e\").\nExample\nabbreviate(\"elephant-rides are really fun!\")\n//          ^^^^^^^^*^^^^^*^^^*^^^^^^*^^^*\n// words (^):   \"elephant\" \"rides\" \"are\" \"really\" \"fun\"\n//                123456     123     1     1234     1\n// ignore short words:               X              X\n\n// abbreviate:    \"e6t\"     \"r3s\"  \"are\"  \"r4y\"   \"fun\"\n// all non-word characters (*) remain in place\n//                     \"-\"      \" \"    \" \"     \" \"     \"!\"\n=== \"e6t-r3s are r4y fun!\"\n*/\n\nfunction abbreviate(string) {\n  return string.replace(/\\w{4,}/g, function(w) { return w[0] + (w.length - 2) + w[w.length - 1] });\n}\n"
  },
  {
    "path": "Wordify an integer.js",
    "content": "/*\nDescription:\nTurn a given number (an integer > 0, < 1000) into the equivalent English words. For the purposes of this kata, no hyphen is needed in numbers 21-99.\n\nExamples:\n\nwordify(1) == \"one\"\nwordify(12) == \"twelve\"\nwordify(17) == \"seventeen\"\nwordify(56) == \"fifty six\"\nwordify(90) == \"ninety\"\nwordify(326) == \"three hundred twenty six\"\nBased on \"Speech module\" mission from Checkio.\n*/\nconst words = {\n  \"zero\":0, \"one\":1, \"two\":2, \"three\":3, \"four\":4, \"five\":5, \"six\":6, \"seven\":7, \"eight\":8, \"nine\":9, \n  \"ten\":10, \"eleven\":11, \"twelve\":12, \"thirteen\":13, \"fourteen\":14, \"fifteen\":15, \"sixteen\":16, \n  \"seventeen\":17, \"eighteen\":18, \"nineteen\":19, \"twenty\":20, \"thirty\":30, \"forty\":40, \"fifty\":50, \n  \"sixty\":60, \"seventy\":70, \"eighty\":80, \"ninety\":90\n};\nfunction wordify(n){\n  const words1 = {}\n  const mult1 = {}\n  for (let i in words){\n    words1[words[i]]=i\n  }\n  if (words1[n]) return words1[n]\n  let arr = [];\n  let s = n.toString().split``.reverse()\n  for (let i=0;i<s.length;i++){\n    arr.push(s[i].padEnd(i+1,0))\n  }\n  if (words1[n.toString().slice(-2)]) return words1[s[s.length-1]]+' hundred '+words1[n.toString().slice(-2)]\n  return arr.filter(v=>parseInt(v)).map(v=>words1[v]?words1[v]:words1[v[0]]+' hundred').reverse().join` `\n}\n"
  },
  {
    "path": "World Bits War.js",
    "content": "/*\nDescription:\nVariation of this nice kata, the war has expanded and become dirtier and meaner; both even and odd numbers will fight with their pointy 1s. And negative integers are coming into play as well, with, ça va sans dire, a negative contribution (think of them as spies or saboteurs).\n\nAgain, three possible outcomes: odds win, evens win and tie.\n\nExamples:\n\nbitsWar([1,5,12]) => \"odds win\" //1+101 vs 1100, 3 vs 2\nbitsWar([7,-3,20]) => \"evens win\" //111-11 vs 10100, 3-2 vs 2\nbitsWar([7,-3,-2,6]) => \"tie\" //111-11 vs -1+110, 3-2 vs -1+2\n*/\nfunction bitsWar(numbers) {\n  let odd = numbers.filter(v=>v%2!==0)\n  let odd2 = odd.map(v=>Math.abs(v).toString(2).replace(/0/g,'').length).map((v,i)=>odd[i]<0?v*-1:v*1).reduce((a,b)=>a+b,0)\n  let even = numbers.filter(v=>v%2===0)\n  let even2 = even.map(v=>Math.abs(v).toString(2).replace(/0/g,'').length).map((v,i)=>even[i]<0?v*-1:v*1).reduce((a,b)=>a+b,0)\n  return odd2>even2?'odds win':odd2===even2?'tie':'evens win'\n}\n"
  },
  {
    "path": "Write JavaScript's 'call' function using apply..js",
    "content": "/*\nDescription:\nImagine JavaScript didn't natively include the call function. The apply function however still exists.\n\nUsing apply, write call.\n\nNote: console.log internally uses the 'call' function, which therefore means you can't debug using console.log as it will either call an empty function or cause an infinite loop.\n*/\nFunction.prototype.call = function(context, ...args) {\n  return this.apply(context, args);\n}\n"
  },
  {
    "path": "Write Number in Expanded Form",
    "content": "/*\nDescription:\nWrite Number in Expanded Form\nYou will be given a number and you will need to return it as a string in Expanded Form. For example:\n\nexpandedForm(12); // Should return '10 + 2'\nexpandedForm(42); // Should return '40 + 2'\nexpandedForm(70304); // Should return '70000 + 300 + 4'\nNOTE: All numbers will be whole numbers greater than 0.\n\nIf you liked this kata, check out part 2!!\n*/\n\nconst expandedForm = n => n.toString()\n                            .split(\"\")\n                            .reverse()\n                            .map( (a, i) => a * Math.pow(10, i))\n                            .filter(a => a > 0)\n                            .reverse()\n                            .join(\" + \");\n"
  },
  {
    "path": "Write Number in Expanded Form - Part 2.js",
    "content": "/*\nDescription:\nWrite Number in Expanded Form - Part 2\nThis is version 2 of my 'Write Number in Exanded Form' Kata.\n\nYou will be given a number and you will need to return it as a string in Expanded Form. For example:\n\nexpandedForm(1.24); // should return '1 + 2/10 + 4/100'\nexpandedForm(7.304); // should return '7 + 3/10 + 4/1000'\nexpandedForm(0.04); // should return '4/100'\n*/\nfunction expandedForm(num) {\n   let str = num.toString().split`.`\n   let f = str[0].split``.reverse().map((v,i)=>v*1===0?'':v+'0'.repeat(i)).filter(v=>v).reverse().join` + `\n   let s = str[1].split``.map((v,i)=>v*1===0?'':v+'/'+'1'+'0'.repeat(i+1)).filter(v=>v).join` + `\n   return ([f,s].join` + `).replace(/^[^0-9]+/g,'')\n}\n"
  },
  {
    "path": "X marks the spot!.js",
    "content": "/*\nDescription:\nWrite a function x(n) that takes in a number n and returns an nxn array with an X in the middle. The X will be represented by 1's and the rest will be 0's.\nE.g.\n\nx(5) === [[1, 0, 0, 0, 1],\n          [0, 1, 0, 1, 0],\n          [0, 0, 1, 0, 0],\n          [0, 1, 0, 1, 0],\n          [1, 0, 0, 0, 1]];\n\nx(6) === [[1, 0, 0, 0, 0, 1],\n          [0, 1, 0, 0, 1, 0],\n          [0, 0, 1, 1, 0, 0],\n          [0, 0, 1, 1, 0, 0],\n          [0, 1, 0, 0, 1, 0],\n          [1, 0, 0, 0, 0, 1]];\n*/\nfunction x(n) {\n   let arr = []\n   for (let i=0;i<n;i++){\n     arr.push(Array(n).fill(0))\n   }\n   for (let i=0;i<n;){\n     for (let j=0;j<n;){\n       arr[i][j]=1\n       i++\n       j++\n     }\n   }\n   for (let i=0;i<n;){\n     for (let j=n;j>0;){\n       arr[i][j-1]=1\n       i++\n       j--\n     }\n   }\n   return arr \n}\n"
  },
  {
    "path": "Your Ride Is Here.js",
    "content": "/*\nDescription:\nIt is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do, however, let the groups know ahead of time which will be picked up for each comet by a clever scheme: they pick a name for the comet which, along with the name of the group, can be used to determine if it is a particular group's turn to go (who do you think names the comets?). The details of the matching scheme are given below; your job is to write a program which takes the names of a group and a comet and then determines whether the group should go with the UFO behind that comet.\n\nBoth the name of the group and the name of the comet are converted into a number in the following manner: the final number is just the product of all the letters in the name, where \"A\" is 1 and \"Z\" is 26. For instance, the group \"USACO\" would be 21 * 19 * 1 * 3 * 15 = 17955. If the group's number mod 47 is the same as the comet's number mod 47, then you need to tell the group to get ready! (Remember that \"a mod b\" is the remainder left over after dividing a by b; 34 mod 10 is 4.)\n\nWrite a program which reads in the name of the comet and the name of the group and figures out whether according to the above scheme the names are a match, printing \"GO\" if they match and \"STAY\" if not. The names of the groups and the comets will be a string of capital letters with no spaces or punctuation, up to 6 characters long.\n\nExample:\n\ngroup = \"COMETQ\"\ncomet = \"HVNGAT\"\n\nride(group,comet) == \"GO\"\nConverting the letters to numbers:\n\nC  O   M   E  T   Q    \n3  15  13  5  20  17    \n\nH  V   N   G  A  T\n8  22  14  7  1  20    \nthen calculate the product mod 47:\n\n3 * 15 * 13 * 5 * 20 * 17 = 994500 mod 47 = 27\n8 * 22 * 14 * 7 *  1 * 20 = 344960 mod 47 = 27\nBecause both products evaluate to 27 (when modded by 47), the mission is 'GO'.\n*/\nfunction ride(group,comet){\n  let g= group.split``.reduce((a,b)=>a*(b.charCodeAt()-64),1)%47\n  let c= comet.split``.reduce((a,b)=>a*(b.charCodeAt()-64),1)%47\n  return g===c?'GO':'STAY'\n}\n"
  },
  {
    "path": "Your order, please",
    "content": "/*\nDescription:\nYour task is to sort a given string. Each word in the String will contain a single number. This number is the position the word should have in the result.\n\nNote: Numbers can be from 1 to 9. So 1 will be the first word (not 0).\n\nIf the input String is empty, return an empty String. The words in the input String will only contain valid consecutive numbers.\n\nFor an input: \"is2 Thi1s T4est 3a\" the function should return \"Thi1s is2 3a T4est\"\n\nyour_order(\"is2 Thi1s T4est 3a\")\n[1] \"Thi1s is2 3a T4est\"\n*/\n\nfunction order(words){\n  \n  return words.split(' ').sort(function(a, b){\n      return a.match(/\\d/) - b.match(/\\d/);\n   }).join(' ');\n}    \n"
  },
  {
    "path": "Zero fill... for the Queen!.js",
    "content": "/*\nDescription:\nQueen of the Forest needs a function that will add a specified quantity of leading zeros to any given number.\n\nFor example, if a 5-digit number is needed, and we pass in 11, the returned value would be 00011. There are many ways to achieve this. Additionally, if the size passed is less than the length of number, just return the number as a string. Let's have one that would be both useful and good performance-wise.\n\nNOTES:\n\n1) Numbers passed only - no strings, objects, functions, etc.\n\n2) Whole positives only - negatives converted, decimals dropped (provided in solution setup)\n*/\nfunction zeroFill(number, size) {\n  let num=Math.floor(Math.abs(number)).toFixed(0);\n  return '0'.repeat((size-num.length)>0?size-num.length:0)+num\n}\n"
  },
  {
    "path": "Ziiiiip!.js",
    "content": "/*\nDescription:\nLet's implement the zipObject function that enables such results\n\nzipObject(['fred', 'barney'], [30, 40])\n=> { 'fred': 30, 'barney': 40 }\n\nzipObject([['fred', 30], ['barney', 40]])\n=> { 'fred': 30, 'barney': 40 }\nThe zipObject creates an object composed from arrays of keys and values. It is provided with either a single two dimensional array, i.e. [[key1, value1], [key2, value2]] or with two arrays, one of keys and one of corresponding values.\n\nIf only keys are given, then set the values to undefined.\n\nzipObject(['fred', 'barney'])\n{ fred: undefined, barney: undefined }\nIf neither keys nor values are specified, then return {}\n\nzipObject()\n{}\n*/\nfunction zipObject(keys, values=[]) {\n  if (!keys) return {}\n  keys=flat(keys.concat(values))\n  let str = []\n  let num = []\n  for (let i=0;i<keys.length;i++){\n    if (typeof keys[i]==='string') str.push(keys[i])\n    else num.push(keys[i])\n  }\n  return str.reduce((a,b,i)=>(a[b]=(num[i]||undefined),a),{})\n}\nconst flat=(arr)=>{\n  return arr.reduce((a,b)=>a.concat(Array.isArray(b)?flat(b):b),[])\n}\n"
  },
  {
    "path": "bit \"Wise\" #1: XOR-cism.js",
    "content": "/*\nDescription:\nSeries: bit “Wise”\n\nJavascript’s bitwise operators are probably the least used and least widely understood part of the language: In the domain of the web, where Javascript enjoys unrivaled supremacy, operating on the bits-and-bytes level is often abstracted away (perhaps thankfully). Despite this, there remain practical uses for the language’s bitwise operators both on the web (for performance reasons) and especially in the burgeoning field of physical computing (Arduino, RaspberryPi, etc.), where Javascript is being embedded in and interacting with things like sensor packages, shift registers and other electronic components that “speak binary”. In this series of Kata, we’ll familiarize ourselves with some of the “basic moves” of the JS bitwise operators.\nExercise 1: XOR-cism\nIn this Kata, you will be writing a function named \"swapper\" that should \"swap\" two integer values (a and b) and return them in an array in \"swapped\" order. Do your best to complete the kata without declaring any variables or functions and using only bitwise operators in the body of the 'swapper' function. There are some pre-loaded hints you can access if you need help doing it with the bitwise operators. Good luck.\nE.G.\n\nvar x = swapper(0,1); //returns [1, 0]\nTest.expect(x[0] == 1);\nTest.expect(x[1] == 0);\n\nx = swapper(1,2);\nTest.expect(x[0] == 2);\nTest.expect(x[1] == 1);\n*/\nfunction swapper(a, b) {\n  return [b, a]\n}\n"
  },
  {
    "path": "bit \"Wise\" #2: SHIFT-iness.js",
    "content": "/*\nDescription:\nSeries: bit “Wise”\n\nJavascript’s bitwise operators are probably the least used and least widely understood part of the language: In the domain of the web, where Javascript enjoys unrivaled supremacy, operating on the bits-and-bytes level is often abstracted away (perhaps thankfully). Despite this, there remain practical uses for the language’s bitwise operators both on the web (for performance reasons) and especially in the burgeoning field of physical computing (Arduino, RaspberryPi, etc.), where Javascript is being embedded in and interacting with things like sensor packages, shift registers and other electronic components that “speak binary”. In this series of Kata, we’ll familiarize ourselves with some of the “basic moves” of the JS bitwise operators.\nExercise 2: SHIFT-iness\nOne of the tricky things about (x).toString(2) (where x is an integer, which reports the number back in binary) is that it doesn't really tell us the \"whole story\" about how JS is handling the bits for any given number. You learn this very quickly when you apply the \"~\" bitwise operator to an integer.\nFor Example:\n\nconsole.log((5).toString(2)); \nlogs \"101\" to the console...which is what you expect, right?\n\nSo \"flipping\" the bits on the number with the \"~\" operator should yield 010 - or 2, right? Let's see:\n\nconsole.log(~5); \n-6!? -6?! WTF?\n\nWell, there's a reason for that. The binary representation of numbers in JS is handled in the \"Two's Complement\" system...which is just a fancy way of saying that for any given set of bits, the first bit represents the sign (0 for positive, 1 for negative) of the number and the rest of the bits represent the \"absolute value\" of the number according to the following simple formula: A) For positive numbers and 0, the value tells how \"far\" from 0 the number is... i.e. 10 in binary (2 in decimal) means \"2 above 0\"...so for a 3-bit number in Two's Complement, the number 2 (decimal) would be represented as: \"010\". B) For negative numbers, how far above the smallest possible value that can be represented with the number of bits available...e.g. with three bits, the smallest possible number we can represent is -4...so \"101\" (binary) is like saying \"01 more than -4\"...or -3.\n\nSo in the example above, when we \"flipped\" the bits of the number 5, there was the extra \"sign bit\" on the front that got flipped as well.. so what we thought was \"101\" was actually \"0101\" and when we flipped the bits, we got \"1010\" - i.e. \"Two more than the smallest number possible in this many bits\" == \"Two more than -8\" == \"-6\".\n\nHere are all the possible 2's complement numbers in a 3-bit system: (binary == decimal)\n011 == 3\n010 == 2\n001 == 1\n000 == 0\n111 == -1\n110 == -2\n101 == -3\n100 == -4\n\nNow the problem; Extend the Number prototype with a function called \"twos\" that accepts one parameter (n), and when called, returns the two's-complement representation of the number in \"n\" bits in a string.\n\ne.g.\n\n(-2).twos(3) == \"110\";\n(8).twos(5) == \"01000\";\n(-8).twos(5) == \"11000\";\n(-16).twos(5) == \"10000\";\n*/\nNumber.prototype.twos = function(n) {\n  let ret = \"\";\n  while(n)\n  {\n    ret += ( (this >> --n) & (1) );\n  }\n  return ret;\n}\n"
  },
  {
    "path": "compute cube as sums.js",
    "content": "/*\nDescription:\nCan you compute a cube as a sum?\n\nIn this Kata, you will be given a number n (where n >= 1) and your task is to find n consecutive odd numbers whose sum is exactly the cube of n.\n\nMathematically:\ncube = n ** 3 \nsum = a1 + a2 + a3 + ..... + an\nsum == cube\na2 == a1 + 2, a3 == a2 + 2, .......\n\nFor example:\n\nfindSummands(3) = [7,9,11] // because 7 + 9 + 11 = 27, the cube of 3. Note that there are only n = 3 elements in the array.\nWrite function findSummands(n) which will return an array of n consecutive odd numbers with the sum equal to the cube of n (n*n*n).\n*/\nfunction findSummands(n){\n  let check=n*n*n\n  let c=n*n\n  while (c%2==0){\n    c--\n  }\n  let c1=c\n  let arr=[c];\n  for (let i=1;i<n;i+=2){\n    arr.push(c+=2)\n    arr.unshift(c1-=2)\n  }\n  return n%2==0?arr.slice(1):arr;\n}\n"
  },
  {
    "path": "extract file name.js",
    "content": "/*\nDescription:\nYou have to extract a portion of the file name as follows:\n\nAssume it will start with date represented as long number\nFollowed by an underscore\nYoull have then a filename with an extension\nit will always have an extra extension at the end\nInputs:\n1231231223123131_FILE_NAME.EXTENSION.OTHEREXTENSION\n\n1_This_is_an_otherExample.mpg.OTHEREXTENSIONadasdassdassds34\n\n1231231223123131_myFile.tar.gz2\nOutputs\nFILE_NAME.EXTENSION\n\nThis_is_an_otherExample.mpg\n\nmyFile.tar\nAcceptable characters for random tests:\n\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-0123456789\n\nThe recommend way to solve it is using RegEx and specifically groups.\n*/\nclass FileNameExtractor {\n    static extractFileName (dirtyFileName) {\n        return dirtyFileName.match(/\\d+_.+\\..+\\./).join``.replace(/^\\d+_/,'').replace(/\\.$/,'')\n    }\n}\n"
  },
  {
    "path": "first character that repeats.js",
    "content": "/*\nDescription:\nFind the first character that repeats in a String and return that character.\n\nfirstDup('tweet') => 't'\nfirstDup('like') => undefined\nThis is not the same as finding the character that repeats first. In that case, an input of 'tweet' would yield 'e'.\n*/\nfunction firstDup (s) {\n  for (let i=0;i<s.length;i++){\n    for (let j=i+1;j<s.length;j++){\n      if (s[i]===s[j]) return s[i]\n    }\n  }\n  return undefined\n}\n"
  },
  {
    "path": "longest_palindrome.js",
    "content": "/*\nDescription:\nLongest Palindrome\nFind the length of the longest substring in the given string s that is the same in reverse.\n\nAs an example, if the input was “I like racecars that go fast”, the substring (racecar) length would be 7.\n\nIf the length of the input string is 0, the return value must be 0.\n\nExample:\n\"a\" -> 1 \n\"aab\" -> 2  \n\"abcde\" -> 1\n\"zzbaabcd\" -> 4\n\"\" -> 0\n*/\n\nlongestPalindrome=function(s){\n    if (s.length===0) return 0\n    let n=[];\n    for (let i=0;i<s.length;i++){\n        for (let j=i;j<s.length+1;j++){\n        if (isPalindrome(s.slice(i,j))){n.push(s.slice(i,j).length)}\n        }}\n      return Math.max(...n)\n}\n\nfunction isPalindrome(line) {\n  let q=line.split('').reverse().join('');\n  return q==line;\n}\n"
  },
  {
    "path": "mkdir -p.js",
    "content": "/*\nWrite a synchronous function that makes a directory and recursively makes all of its parent directories as necessary.\n\nA directory is specified via a sequence of arguments which specify the path. For example:\n\nmkdirp('/','tmp','made','some','dir')\n...will make the directory /tmp/made/some/dir.\n\nLike the shell command mkdir -p, the function you program should be idempotent if the directory already exists.\n\nHINT:\n\nIn javascript/coffescript, you will want to require('fs') and use functions in that library.\n\nDocumentation on fs.\nIn python, you will want to use the os module and os.path\n\nDocumentation on os module\nDocumentation on os.path module\n*/\nconst fs = require('fs')\n\nfunction mkdirp(root, ...path) {\n  for (let i of path) {\n    try {\n      fs.mkdirSync(root += '/' + i)\n    }\n    catch (e) { }\n  }\n}\n"
  },
  {
    "path": "new with apply.js",
    "content": "/*\nDescription:\nIn JavaScript we can create objects using the new operator.\n\nFor example, if you have this constructor function:\n\nfunction Greeting(name) {\n  this.name = name;\n}\n\nGreeting.prototype.sayHello = function() {\n  return \"Hello \" + this.name;\n};\n\n\nGreeting.prototype.sayBye = function() {\n  return \"Bye \" + this.name;\n};\nYou can create a Greeting object in this way:\n\n  var greeting = new Greeting('John');\nnew operator is evil because it produces a highly coupled code, difficult to maintain and test.\n\nSome patterns to reduce coupling are object factories or dependency injection.\n\nThese patterns can benefit of the construct() function.\n\nThis function receives a constructor function and possibly some arguments and it returns a new object constructed with the function and the passed arguments.\n\nThis is another way to create the greeting object:\n\nvar greeting = construct(Greeting, 'John');\nAnd a factory could use like this:\n\n  function factory() {\n    return {\n      createGreeting() {\n        return construct(Greeting, arguments);\n      }\n      ...\n    }\n  }\nYour work is to implement the construct() function.\n*/\nfunction construct(Class,...args) {\n  return new Class(...args)\n}\n"
  },
  {
    "path": "replaceAll(input, find, replace).js",
    "content": "/*\nDescription:\nIsn't it annoying how \"string\".replace(\"find\", \"replace\"); only replaces the first match of the find string? Write a function, replaceAll(input, find, replace); that will replace all matches of the given find string with the given replace string.\n\nThe function will always be called with three strings, so don't worry about validating the arguments.\n\nAs with the original \"string\".replace(find, replace), if find is an empty string, it should match in-between each character, effectively inserting replace in-between each character, including the start and end of the string. I've given you some tests for this to make it a little clearer.\n*/\nfunction replaceAll(input, find, replace) {\n  if (find == '')\n    return input == '' ? replace : replace + input.split('').join(replace) + replace;\n  return input.split(find).join(replace);\n}\n"
  },
  {
    "path": "search in multidimensional array.js",
    "content": "/*\nDescription:\nWrite a function named \"locate\" that gets an array and value and returns true if specified value exist in a multidimentional array.\n\nExample:\n\nlocate(['a','b',['c','d',['e']]],'e'); // should return true\nlocate(['a','b',['c','d',['e']]],'a'); // should return true\nlocate(['a','b',['c','d',['e']]],'f'); // should return false\n*/\nvar locate = function(arr,value){\n  let arr2=[]\n  function flatten(arr){\n    return arr.map((a)=>Array.isArray(a)?flatten(a):arr2.push(a.toString()))\n  }\n  flatten(arr)\n  return arr2.some(v=>v===value.toString())\n}\n"
  },
  {
    "path": "uniq (UNIX style).js",
    "content": "/*\nDescription:\nImplement the uniq() function which behaves like the uniq command in UNIX. It takes as input an array and returns an array in which all duplicate elements following each other have been reduced to one instance.\n\nExample:\n\nvar input = ['a','a','b','b','c','a','b','c'];\nuniq(input); // -> returns ['a','b','c','a','b','c']\n*/\nfunction uniq(a) {\n  for (let i=0;i<a.length-1;i++){\n    if (a[i]===a[i+1]){\n      a.splice(i,1)\n      i--\n    }\n  }\n  return a\n}\n"
  },
  {
    "path": "up AND down.js",
    "content": "/*\nDescription:\nDon't be afraid, the description is rather long but - hopefully - it is in order that the process be well understood.\n\nYou are given a string s made up of substring s(1), s(2), ..., s(n) separated by whitespaces. Example: \"after be arrived two My so\"\n\n#Task Return a string t having the following property:\n\nlength t(O) <= length t(1) >= length t(2) <= length t(3) >= length t(4) .... (P)\n\nwhere the t(i) are the substring of s; you must respect the following rule:\n\nat each step from left to right, you can only move either already consecutive strings or strings that became consecutive after a previous move. The number of moves should be minimum.\n\n#Let us go with our example:\n\nThe length of \"after\" is greater than the length of \"be\". Let us move them ->\"be after arrived two My so\"\n\nThe length of \"after\" is smaller than the length of \"arrived\". Let us move them -> \"be arrived after two My so\"\n\nThe length of \"after\" is greater than the length of \"two\" ->\"be arrived two after My so\"\n\nThe length of \"after\" is greater than the length of \"My\". Good! Finally the length of \"My\" and \"so\" are the same, nothing to do. At the end of the process, the substrings s(i) verify:\n\nlength s(0) <= length s(1) >= length s(2) <= length s(3) >= length (s4) <= length (s5)\n\nHence given a string s of substrings s(i) the function arrange with the previous process should return a unique string t having the property (P).\n\nIt is kind of roller coaster or up and down. When you have property (P), to make the result more \"up and down\" visible t(0), t(2), ... will be lower cases and the others upper cases.\n\narrange(\"after be arrived two My so\") should return \"be ARRIVED two AFTER my SO\"\nNotes:\nThe string \"My after be arrived so two\" has the property (P) but can't be obtained by the described process so it won't be accepted as a result. The property (P) doesn't give unicity by itself.\nProcess: go from left to right, move only consecutive strings when needed.\nFor the first fixed tests the needed number of moves to get property (P) is given as a comment so that you can know if your process follows the rule.\n*/\nfunction arrange(strng) {\n    let arr = strng.split(\" \");\n    let arrLen = arr.length;\n    let comparer = [(a, b) => a.length > b.length,\n                    (a, b) => a.length < b.length];\n    for (let i = 0; i < arrLen - 1; i++) {\n      if (comparer[i % 2](arr[i], arr[i + 1])) {\n        let tmp = arr[i];\n        arr[i] = arr[i + 1];\n        arr[i + 1] = tmp;\n      }\n    }\n\n    return arr.map((e, i) => (i % 2) ? e.toUpperCase() : e.toLowerCase()).join(\" \");\n}\n"
  },
  {
    "path": "zipWith.js",
    "content": "/*\nDescription:\nImplement zipWith\nzipWith takes a function and two arrays and zips the arrays together, applying the function to every pair of values.\nThe function value is one new array.\n\nIf the arrays are of unequal length, the output will only be as long as the shorter one.\n(Values of the longer array are simply not used.)\n\nInputs should not be modified.\n\nExamples\nzipWith( Math.pow, [10,10,10,10], [0,1,2,3] )      =>  [1,10,100,1000]\nzipWith( Math.max, [1,4,7,1,4,7], [4,7,1,4,7,1] )  =>  [4,7,7,4,7,7]\n\nzipWith( function(a,b) { return a+b; }, [0,1,2,3], [0,1,2,3] )  =>  [0,2,4,6]  Both forms are valid.\nzipWith( (a,b) => a+b,                  [0,1,2,3], [0,1,2,3] )  =>  [0,2,4,6]  Both are functions.\nInput validation\nAssume all input is valid.\n*/\nfunction zipWith(fn,a0,a1) {\n  let arr = [];\n  const short = Math.min(a0.length, a1.length); \n  for (let i=0;i<short;i++){\n    arr.push(fn(a0[i],a1[i]))\n  }\n  return arr\n}\n"
  }
]