Solutions ()

"use strict";

function countWords(text, words) {
    var texts = text.split(" ");
    var found = [];
    for(var b = 0; b < words.length; b++){
        var foundString = false;
        for(var a = 0; a < texts.length; a++){
            if(texts[a].toLowerCase().indexOf(words[b].toLowerCase()) !== -1){
                foundString = true;
            }
        }
        if(foundString){
            found.push(1);
        }
    }
    return found.length;
}

var assert = require('assert');

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(countWords("How aresjfhdskfhskd you?", ["how", "are", "you", "hello"]),
        3, "Example");
    assert.equal(countWords("Bananas, give me bananas!!!", ["banana", "bananas"]), 2, "BANANAS!");
    assert.equal(countWords("Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
        ["sum", "hamlet", "infinity", "anything"]), 1, "Weird text");
    console.log("Code's finished? Earn rewards by clicking 'Check' to review your tests!");
}
"use strict";

function angles(a, b, c){
    // First check lengths: http://www.mathwarehouse.com/geometry/triangles/triangle-inequality-theorem-rule-explained.php
    if((a + b > c) && (a + c > b) && (b + c > a)){
        var angles = []; // Array to hold our angles
        var cosA = (Math.pow(b, 2) + Math.pow(c, 2) - Math.pow(a, 2)) / (2 * b * c);
        var A = Math.acos(cosA); // Gives us radians
        var aDegrees = Math.round(A * (180 / Math.PI));
        angles.push(aDegrees);
        var cosB = (Math.pow(c, 2) + Math.pow(a, 2) - Math.pow(b, 2)) / (2 * c * a);
        var B = Math.acos(cosB); // Gives us radians
        var bDegrees = Math.round(B * (180 / Math.PI));
        angles.push(bDegrees);
        var cDegrees = 180 -(aDegrees + bDegrees);
        angles.push(cDegrees);
        angles.sort(sortNumber);
        return angles;
    }else{
        return [0, 0, 0];
    }
}

function sortNumber(a,b) {
    return a - b;
}

var assert = require('assert');

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.deepEqual(angles(4, 4, 4), [60, 60, 60], "All sides are equal");
    assert.deepEqual(angles(3, 4, 5), [37, 53, 90], "Egyptian triangle");
    assert.deepEqual(angles(2, 2, 5), [0, 0, 0], "It's can not be a triangle");
    console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
function convert(strNumber, radix) {
    var table = '0123456789abcdefghijklmnopqrstuvwxyz';
    str = strNumber.toLowerCase();
    for (i=0; i<str.length; i++) {
        if (table.indexOf(str[i]) >= radix) {
            return -1;
        }
    }
    if(radix < 37 && radix > 1){
        if(isNaN(parseInt(strNumber, radix))){
            return -1;
        }else{
            return parseInt(strNumber, radix);
        }
    }else{
        return -1;
    }
}
transpose=m=>m[0].map((_,c)=>m.map(r=>r[c]));
"use strict";

function simpleAreas() {
    if(arguments.length === 1){
        return parseFloat(((arguments[0]/2) * (arguments[0]/2) * Math.PI).toFixed(2));
    }
    if(arguments.length === 2){
        return parseFloat((arguments[0] * arguments[1]).toFixed(2));
    }
    if(arguments.length === 3){
        var perimeter = (arguments[0] + arguments[1] + arguments[2])/2;
        return parseFloat((Math.sqrt(perimeter*((perimeter-arguments[0])*(perimeter-arguments[1])*(perimeter-arguments[2])))).toFixed(2));
    }
}

var assert = require('assert');

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    var almostEqual = function(actual, expected, significantDigits){
        significantDigits = significantDigits || 2;
        var precision =  Math.pow(0.1, significantDigits);
        return Math.abs(expected - actual) < precision;
    };

    assert(almostEqual(simpleAreas(3), 7.07), "Circle");
    assert(almostEqual(simpleAreas(2, 2), 4), "Square");
    assert(almostEqual(simpleAreas(2, 3), 6), "Rectangle");
    assert(almostEqual(simpleAreas(3, 5, 4), 6), "Triangle");
    assert(almostEqual(simpleAreas(1.5, 2.5, 2), 1.5), "Small triangle");
    console.log("All done? Earn rewards by using the 'Check' button!");
}
checkLine=(l)=>!l.some((c,i,a)=>~~i&&c===a[i-1]);
"use strict";

function checkGrid(grid) {
    var returnBool = true;
    for(var a = 0; a < grid.length; a++){
        for(var b = 0; b < grid[a].length; b++){
            if(grid[a][b+1] && grid[a][b] == grid[a][b+1]){
                returnBool = false
            }
            if(grid[a+1] && grid[a][b] == grid[a+1][b]){
                returnBool = false
            }
        }
    }
    return returnBool;

}

var assert = require('assert');

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(checkGrid([["X", "Z"], ["Z", "X"]]), true, "2x2 Good");
    assert.equal(checkGrid([
        ["X", "Z", "X"],
        ["Z", "X", "Z"],
        ["X", "Z", "X"]]), true, "3x3 Good");
    assert.equal(checkGrid([
        ["X", "Z", "X", "Z"],
        ["Z", "X", "Z", "X"]]), true, "2x4 Good");
    assert.equal(checkGrid([
        ["X", "X"],
        ["X", "X"]]), false, "2x2 Bad");
    assert.equal(checkGrid([
        ["X", "Z", "X"],
        ["Z", "Z", "Z"],
        ["X", "Z", "X"]]), false, "3x3 Bad");
    assert.equal(checkGrid([
        ["X", "Z", "X", "Z"],
        ["X", "Z", "X", "Z"]]), false, "2x4 Bad");
    console.log("Use 'Check' to earn sweet rewards!");
}
"use strict";

function fizzBuzz(number) {
    var returnString = "";
    if(number % 5 === 0 && number % 3 === 0){
        return "Fizz Buzz"
    }else{
        if(number % 5 === 0){
            return "Buzz"
        }else if(number % 3 === 0){
            return "Fizz"
        }else{
           return "" + number
        }
    }
}

var assert = require('assert');

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(fizzBuzz(15), "Fizz Buzz", "15 is divisible by 3 and 5");
    assert.equal(fizzBuzz(6), "Fizz", "6 is divisible by 3");
    assert.equal(fizzBuzz(5), "Buzz", "5 is divisible by 5");
    assert.equal(fizzBuzz(7), "7", "7 is not divisible by 3 or 5");
    console.log("Earn cool rewards by using the 'Check' button!");
}
golf=n=>+(""+n).replace(/0/g,'').split("").reduce((a,b)=>a*b)
"use strict";

function mostDifference() {
    if(arguments.length === 0){
        return 0;
    }else{
        var lowest = null;
        var highest = null;
        var difference = null
        for(var i = 0; i < arguments.length; i++){
            if(!lowest || arguments[i] < lowest){
                lowest = arguments[i]
            }
            if(!highest || arguments[i] > highest){
                highest = arguments[i]
            }
            if(!difference || (highest - lowest) > difference){
                difference = highest - lowest;
            }
        }
    }
    return difference;
}

var assert = require('assert');

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    var almostEqual = function(actual, expected, significantDigits){
        significantDigits = significantDigits || 3;
        var precision =  Math.pow(0.1, significantDigits);
        return Math.abs(expected - actual) < precision;
    };

    assert(almostEqual(mostDifference(1, 2, 3), 2), "3-1=2");
    assert(almostEqual(mostDifference(5, 5), 0), "5-5=0");
    assert(almostEqual(mostDifference(10.2, 2.2, 0.00001, 1.1, 0.5), 10.199), "10.2-(0.00001)=10.19999");
    assert(almostEqual(mostDifference(), 0), "Empty");
    console.log("Use 'Check' to earn sweet rewards!");
}
"use strict";

function nonUnique(data) {
    var returnArray = [];
    for(var i = 0; i < data.length; i++){
      if(data.filter(function(value){
        if(isNaN(data[i])){
          return (isNaN(value)) ? value.toUpperCase() === data[i].toUpperCase() : false;
        }else{
          return value === data[i];
        }
      }).length > 1){
        returnArray.push(data[i])
      }

    }
    return returnArray;
}

var assert = require('assert');

if (!global.is_checking) {
    assert.deepEqual(nonUnique([1, 2, 3, 1, 3]), [1, 3, 1, 3], "1st example");
    assert.deepEqual(nonUnique([1, 2, 3, 4, 5]), [], "2nd example");
    assert.deepEqual(nonUnique([5, 5, 5, 5, 5]), [5, 5, 5, 5, 5], "3rd example");
    assert.deepEqual(nonUnique([10, 9, 10, 10, 9, 8]), [10, 9, 10, 10, 9], "4th example");
    assert.deepEqual(nonUnique(['P', 7, 'j', 'A', 'P', 'N', 'Z', 'i',
        'A', 'X', 'j', 'L', 'y', 's', 'K', 'g',
        'p', 'r', 7, 'b']), ['P', 7, 'j', 'A', 'P', 'A', 'j', 'p', 7], "Letters");
    console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
"use strict";

function swapSort(arr){
    var returnArray = [];
    for(var a = 0; a < arr.length; a++){
        for(var b = 0; b < arr.length; b++){
            if(arr[b+1] && arr[b] > arr[b+1]){
                var temp = arr[b];
                arr[b] = arr[b+1]
                arr[b+1] = temp
                returnArray.push(b+""+(b+1))
            }
        }
    }
    return returnArray.join(",");
}

var assert = require("assert");

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    var checkSolution = function (f, indata) {
        var result = f(indata.slice());
        var sortData = indata.slice();
        sortData.sort();
        var array = indata.slice();
        var la = array.length;
        if (typeof(result) !== "string") {
            console.log("The result should be a string");
            return false;
        }

        var actions = result.length ? result.split(",") : [];
        for (var a = 0; a < actions.length; a++) {
            var act = actions[a];
            if (act.length != 2 || isNaN(act)) {
                console.log("The wrong action: act");
                return false;
            }
            var i = Number(act[0]),
                j = Number(act[1]);
            if (i >= la || j >= la) {
                console.log("Index error: " + act);
                return false;
            }
            if (Math.abs(i - j) != 1) {
                console.log("The wrong action: {}".format(act));
                return false;
            }
            var temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }
        if (actions.length > ~~(la * (la - 1) / 2)) {
            console.log("Too many actions. BOOM!");
            return false;
        }
        for (var k = 0; k < array.length; k++) {
            if (array[k] !== sortData[k]) {
                console.log("The array is not sorted. BOOM!");
                return false;
            }
        }
        return true;
    };

    assert(checkSolution(swapSort, [6, 4, 2]), "Reverse simple");
    assert(checkSolution(swapSort, [1, 2, 3, 4, 5]), "All right!");
    assert(checkSolution(swapSort, [1, 2, 3, 5, 3]), "One move");
    console.log("All set? Click 'Check' to review your code and earn rewards!");
}
function countIngots(report) {
    var runningTotal = 0;
    var bits = report.split(",");
    for(var i = 0; i < bits.length; i++){
        runningTotal += ((bits[i].charCodeAt(0) - 65) * 9) + parseInt(bits[i].charAt(1), 10)
    }
    return runningTotal;
}
function countReports(fullReport, fromDate, toDate) {
    var returnTotal = 0;
    var days = fullReport.split("\n");
    var fromDate = new Date(fromDate).getTime();
    var toDate = new Date(toDate).getTime();
    for(var i = 0; i < days.length; i++){
        var dayBits = days[i].split(" ");
        var day = new Date(dayBits[0]).getTime();
        if(day >= fromDate && day <= toDate){
            returnTotal += countIngots(dayBits[1])
        }
    }
    return returnTotal;
}

function countIngots(report) {
    var runningTotal = 0;
    var bits = report.split(",");
    for(var i = 0; i < bits.length; i++){
        runningTotal += ((bits[i].charCodeAt(0) - 65) * 9) + parseInt(bits[i].charAt(1), 10)
    }
    return runningTotal;
}
indexPower=(array,n)=>Math.pow(array[n],n)||-1;
golf=p=>/^((?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,})$/.test(p);
verifyAnagrams=(f,s)=>f.replace(/ /g,'').toLowerCase().split('').sort().join('')==s.replace(/ /g,'').toLowerCase().split('').sort().join('');
countUnits=number=>(number>>>0).toString(2).match(/1/g).length;
function checkPangram(text){
    var letters = [];
    for(var i = 0; i < text.length; i++){
        var char_code = text.charAt(i).toUpperCase().charCodeAt(0)
        if(char_code >= 65 && char_code <= 90){
            if(letters.indexOf(char_code) === -1){
                letters.push(char_code);
            }
        }
    }
    return (letters.length === 26) ? true : false;
}
"use strict";
function golf(matrix) {
    var i, rowSum;
    var returnObject = {
        "left": null,
        "top": null
    };
    var returnArray = [];
    for(i = 0; i < matrix.length; i++){
        rowSum = matrix[i].reduceRight(function(a,b){return a+b;});
        if(!returnObject.left){
            returnObject.left = rowSum
            returnArray[0] = i;
        }else{
            if(returnObject.left > rowSum){
                returnObject.left = rowSum
                returnArray[0] = i;
            }
        }
    }
    var newArray = matrix[0].map(function (_, c) { return matrix.map(function (r) { return r[c]; }); });
    for(i = 0; i < newArray.length; i++){
        rowSum = newArray[i].reduceRight(function(a,b){return a+b;});
        if(!returnObject.top){
            returnObject.top = rowSum
            returnArray[1] = i;
        }else{
            if(returnObject.top > rowSum){
                returnObject.top = rowSum
                returnArray[1] = i;
            }
        }
    }
    return returnArray;
}

var assert = require("assert");
if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.deepEqual(golf([
        [7, 2, 7, 2, 8],
        [2, 9, 4, 1, 7],
        [3, 8, 6, 2, 4],
        [2, 5, 2, 9, 1],
        [6, 6, 5, 4, 5]]), [3, 3], 'First');
    assert.deepEqual(golf([
        [7, 2, 4, 2, 8],
        [2, 8, 1, 1, 7],
        [3, 8, 6, 2, 4],
        [2, 5, 2, 9, 1],
        [6, 6, 5, 4, 5]]), [1, 2], "Second");
    console.log("All set? Click 'Check' to review your code and earn rewards!");
}
"use strict";

function clockAngle(time){
  var hours = parseInt(time.split(":")[0], 10);
  if(hours > 12){
    hours = hours - 12;
  }
  var minutes = parseInt(time.split(":")[1], 10);
  var hourAngle = 360 * (hours % 12) / 12 + 360 * (minutes / 60) * (1 / 12);
  var minuteAngle = 360 * minutes / 60;
  var difference = (hourAngle - minuteAngle) % 360;
  var difference = (difference < 0) ? difference * -1 : difference;
  return (difference > 180) ? 360 - difference : difference;
}

var assert = require('assert');

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(clockAngle("02:30"), 105, "02:30");
    assert.equal(clockAngle("13:42"), 159, "13:42");
    assert.equal(clockAngle("01:42"), 159, "01:42");
    assert.equal(clockAngle("01:43"), 153.5, "01:43");
    assert.equal(clockAngle("00:00"), 0, "Zero");
    assert.equal(clockAngle("12:01"), 5.5, "Little later");
    assert.equal(clockAngle("18:00"), 180, "Opposite");
    console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
var o = {
    conjunction:(x,y)=>x&&y,
    disjunction:(x,y)=>x||y,
    implication:(x,y)=>!x||y,
    exclusive:(x,y)=>(x&&!y)||(!x&&y),
    equivalence:(x,y)=>x===y
};
boolean=(x,y,operation)=>o[operation](x,y);
"use strict";

function countInversion(arr){
  var newArray = arr.slice();
  var numberOfInversions = 0;
  var currentNumber = null;
  for(var i = 0; i < newArray.length; i++){
    currentNumber = newArray[i]
    arr.splice(0, 1);
    for(var x = 0; x < arr.length; x++){
      if(currentNumber >= arr[x]){
        numberOfInversions++;
      }
    }
  }
  return numberOfInversions;
}

var assert = require("assert");

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(countInversion([1, 2, 5, 3, 4, 7, 6]), 3, "Example");
    assert.equal(countInversion([0, 1, 2, 3]), 0, "Sorted");
    assert.equal(countInversion([99, -99]), 1, "Two numbers");
    assert.equal(countInversion([5, 3, 2, 1, 0]), 10, "Reversed");
    console.log("All set? Click 'Check' to review your code and earn rewards!");
}
"use strict";

function evenLast(array){
    if(array.length === 0){
        return 0;
    }else{
        var runningTotal = 0;
        for(var i = 0; i < array.length; i++){
            if(i % 2 === 0){
                runningTotal += array[i];
            }
        }
        return runningTotal * array[array.length -1];
    }
}

var assert = require("assert");

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(evenLast([0, 1, 2, 3, 4, 5]), 30, "(0+2+4)*5=30");
    assert.equal(evenLast([1, 3, 5]), 30, "(1+5)*5=30");
    assert.equal(evenLast([6]), 36, "(6)*6=36");
    assert.equal(evenLast([]), 0, "An empty array = 0");
    console.log("Use 'Check' to earn sweet rewards!");
}
"use strict";

function median(data) {
    data.sort(function(a, b){
        return a - b;
    });
    console.log(data.length)
    if(data.length % 2){ // ODD
        console.log(data.length / 2);
        return data[Math.floor(data.length / 2)]
    }else{ // EVEN
        console.log(data.length / 2);
        return (data[data.length / 2] + data[(data.length / 2) - 1]) / 2
    }
}

var assert = require('assert');

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(median([1, 2, 3, 4, 5]), 3, "Sorted list");
    assert.equal(median([3, 1, 2, 5, 3]), 3, "Not sorted list");
    assert.equal(median([1, 300, 2, 200, 1]), 2, "It's not an average");
    assert.equal(median([3, 6, 20, 99, 10, 15]), 12.5, "Even length");
    assert.equal(median(list(range(1000000))), 499999.5, "Long.");
    console.log("All set? Click 'Check' to review your code and earn rewards!");
}
"use strict";

function findMessage(text){
    var returnString = "";
    for(var i = 0; i < text.length; i++){
        if(text.charCodeAt(i) >= 65 && text.charCodeAt(i) <= 90){
            returnString += text.charAt(i)
        }
    }
    return returnString
}

var assert = require("assert");

if (!global.is_checking){
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(findMessage("How are you? Eh, ok. Low or Lower? Ohhh."), "HELLO", "hello");
    assert.equal(findMessage("hello world!"), "", "Nothing");
    assert.equal(findMessage("HELLO WORLD!!!"), "HELLOWORLD", "Capitals");
    console.log("Code's finished? Earn rewards by clicking 'Check' to review your tests!");
}
"use strict";

function threeWords(words) {
    var regexObj = /([a-zA-Z]+)\s+([a-zA-Z]+)\s+([a-zA-Z]+)/g;
    return regexObj.test(words)
}

var assert = require("assert");

if (!global.is_checking) {
    // These "asserts" using only for self-checking and not necessary for auto-testing
    assert.equal(threeWords("Hello World hello"), true, "Hello");
    assert.equal(threeWords("He is 123 man"), false, "123 man");
    assert.equal(threeWords("1 2 3 4"), false, "Digits");
    assert.equal(threeWords("bla bla bla bla"), true, "Bla Bla");
    assert.equal(threeWords("Hi"), false, "Hi");
    console.log("Now that you're finished, hit the 'Check' button to review your code and earn sweet rewards!");
}
"use strict";

flatList=a=>JSON.stringify(a).replace(/\[/g,'').replace(/\]/g,'').split(",").map(n=>parseInt(n, 10)).filter(i=>!isNaN(i));
"use strict";

function recallPassword(cipherGrille, cipheredPassword) {
    var cG = cipherGrille.map(function(currentValue){
        return currentValue.split("");
    });
    var cP = cipheredPassword.map(function(currentValue){
        return currentValue.split("");
    });
    var returnString = "";
    for(var x = 0; x < 4; x++){
        var ninety = true;
        for(var a = 0; a < cG.length; a++){
            for(var b = 0; b < cG[a].length; b++){
                if(cG[a][b] === "X"){
                    returnString += cP[a][b];
                    if(cP[a][b] === cP[a][b].toUpperCase()){
                          ninety = false;
                    }
                }
            }
        }
        if(ninety){
            rotate90(cG)
        }else{
            for(var y = 0; y < 3; y++){
                rotate90(cG)
            }
        }
    }
    return returnString;
}

function rotate90(matrix){
    var length = matrix.length;
    for(var row = 0; row < (length / 2); row++){
        for(var col = row; col < ( length - 1 - row); col++){
            var tmpVal = matrix[row][col];
            for(var i = 0; i < 4; i++){
                var rowSwap = col;
                var colSwap = (length - 1) - row;
                var poppedVal = matrix[rowSwap][colSwap];
                matrix[rowSwap][colSwap] = tmpVal;
                tmpVal = poppedVal;
                col = colSwap;
                row = rowSwap;
            }
        }
    }
}
golf=c=>c.match(/([A-Z][1-9])/g).reduce((a,b)=>a+(b.charCodeAt(0)-65)*9+b[1]*1,0)
translate=phrase=>phrase.replace(/([b-df-hj-np-tv-xz]{1}[aeiouy]{1})/g,v=>v.charAt(0)).replace(/([aeiouy]{3})/g,v=>v.charAt(0));
function safePawns(p) {
    var safe = 0;
    p.forEach(a=>safe+=([String.fromCharCode(a[0].charCodeAt()-1)+((a[1]*1)-1),String.fromCharCode(a[0].charCodeAt()+1)+((a[1]*1)-1)].filter(n=>p.indexOf(n) != -1).length)?1:0)
    return safe;
}
var ones = Array("", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen");
var tens = Array("", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety");

function tellNumber(num){
    var res = (num < 0) ? ["minus"] : [];
    num = Math.abs(num);
    Math.floor(num/Math.pow(10, 30)) > 0 && res.push(tellNumber(Math.floor(num/Math.pow(10, 30)))+" quintillion");
    num -= Math.floor(num/Math.pow(10, 30)) * Math.pow(10, 30);
    Math.floor(num/Math.pow(10, 24)) > 0 && res.push(tellNumber(Math.floor(num/Math.pow(10, 24)))+" quadrillion");
    num -= Math.floor(num/Math.pow(10, 24)) * Math.pow(10, 24);
    Math.floor(num/Math.pow(10, 18)) > 0 && res.push(tellNumber(Math.floor(num/Math.pow(10, 18)))+" trillion");
    num -= Math.floor(num/Math.pow(10, 18)) * Math.pow(10, 18);
    Math.floor(num/Math.pow(10, 12)) > 0 && res.push(tellNumber(Math.floor(num/Math.pow(10, 12)))+" billion");
    num -= Math.floor(num/Math.pow(10, 12)) * Math.pow(10, 12);
    Math.floor(num/Math.pow(10, 6)) > 0 && res.push(tellNumber(Math.floor(num/Math.pow(10, 6)))+" million");
    num -= Math.floor(num/Math.pow(10, 6)) * Math.pow(10, 6);
    Math.floor(num/1000) > 0 && res.push(tellNumber(Math.floor(num/1000))+" thousand");
    num -= Math.floor(num/1000) * 1000;
    Math.floor(num/100) > 0 && res.push(tellNumber(Math.floor(num/100))+" hundred");
    num -= Math.floor(num/100) * 100;
    var tn = Math.floor(num / 10);
    var one = Math.floor(num % 10);
    if (tn > 0 || one > 0) {
        if (tn < 2) {
            res.push(ones[tn * 10 + one]);
        } else {
            res.push(tens[tn]);
            if (one > 0) {
                res.push(ones[one]);
            }
        }
    }
    if (res.length === 0) {
        res.push("zero");
    }
    return res.join(" ");
}
var push = /(PUSH)/;
var pop = /(POP)/;

function golf(c){
    var A = [], I = 0;
    c.forEach(function(a){
        if(push.test(a)){
            A.push(parseInt(a.split(" ")[1], 10));
        }else{
            if(A.length){
                I += A[A.length - 1]
                if(pop.test(a)){
                    A.pop()
                }
            }
        }
    });
    return I;
}
"use strict";

function countNeighbours(g, r, c) {
    var cs = [],
        I = 0;
    for (var i = 0; i < 3; i++) {
        for (var j = 0; j < 3; j++) {
            var A = [];
            i == 0 && A.push(c - 1);
            i == 1 && A.push(c);
            i == 2 && A.push(c + 1);
            j == 0 && A.push(r - 1);
            j == 1 && A.push(r);
            j == 2 && A.push(r + 1);
            ((A[0] >= 0 && A[0] <= g[0].length - 1) && (A[1] >= 0 && A[1] <= g.length - 1) && (!(A[0] == c && A[1] == r))) && cs.push(A);
        }
    }
    console.log(cs);
    for (var i in cs) {
        (g[cs[i][1]][cs[i][0]]) && I++;
    }
    return I;
}
"use strict";

var R = 6371.00;

function distance(f, s) {
    f = gLL(f), s = gLL(s);
    var dLat = deg2rad(s.lat - f.lat); // deg2rad below
    var dLon = deg2rad(s.lng - f.lng);
    var a =
        Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.cos(deg2rad(f.lat)) * Math.cos(deg2rad(s.lat)) *
        Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c; // Distance in km
    return d;
}

function deg2rad(deg) {
    return deg * (Math.PI / 180)
}

function gLL(S) {
    var reg = /^(\d+)°(\d+)'(\d+)?([A-Z])[,]*[ ]*(\d+)°(\d+)'(\d+)?([A-Z])$/;
    var d = reg.exec(S);
    return {
        "lat": (d[4] === "S") ? -Math.abs(d[1] * 1 + d[2] / 60 + d[3] / 3600) : d[1] * 1 + d[2] / 60 + d[3] / 3600,
        "lng": (d[8] === "W") ? -Math.abs(d[5] * 1 + d[6] / 60 + d[7] / 3600) : d[5] * 1 + d[6] / 60 + d[7] / 3600
    };
}
"use strict";

function mostLetter(text, allLetters){
    allLetters = allLetters || false;
    if(!allLetters){
        var m = {};
        var l = text.match(/[A-Za-z]/g,'').map(l=>l.toLowerCase()).sort();
        for(i in l){
            (!(l[i] in m)) ? m[l[i]] = 1 : m[l[i]]++;
        }
        return Object.keys(m).reduce(function(a, b){ return m[a] > m[b] ? a : b });
    }else{
        return 0;
    }
}
var commandNames = ["PUSH", "POP"];

function letterQueue(commands) {
    var word = '';
    for (var i=0; i<commands.length; i++) {
        switch (commandNames.indexOf(commands[i].split(' ')[0])){
            case 0:
                word += commands[i].split(' ')[1];
                break;
            case 1:
                word = word.substr(1,word.length);
                break;
        }
    }
    return word;
}
"use strict";

function goodRadix(strNumber){
    for(var i = 2; i < 37; i++){
        if(strNumber === parseInt(strNumber, i).toString(i).toUpperCase()){
            if(parseInt(strNumber, i) % (i - 1) === 0){
                return i;
            }
        }
    }
    return 0;
}
"use strict";

function roman(num) {
    if (!+num)
        return false;
    var digits = String(+num).split(""),
        key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
               "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
               "","I","II","III","IV","V","VI","VII","VIII","IX"],
        roman = "",
        i = 3;
    while (i--)
        roman = (key[+digits.pop() + (i * 10)] || "") + roman;
    return Array(+digits.join("") + 1).join("M") + roman;
}
"use strict";

var c = ["....", "...-", "..-.", "..--", ".-..", ".-.-", ".--.", ".---", "-...", "-..-"];

function morseTime(timeString) {
    var r = [];
    timeString.match(/([0-9])+/g).map(x => (x.length === 1) ? "0" + x : x).forEach((x, i) => r.push(((i === 0)) ? c[~~x.charAt(0)].slice(2) + " " + c[~~x.charAt(1)] : c[~~x.charAt(0)].slice(1) + " " + c[~~x.charAt(1)]));
    return r.join(" : ");
}
"use strict";

function commonWords(first, second){
    var f = first.split(",");
    var s = second.split(",");
    var n = [];
    for(var i = 0; i < f.length; i++) {
        for(var j = 0; j < s.length; j++) {
            if (f[i] == s[j]) {
                n.push(s[j]);
                break;
            }
        }
    }
    return n.sort().join(",");
}
golf=(c,a)=>{
var a=a/2,A=a*a,c=c/2,C=c*c,pi=Math.PI,x=Math.sqrt(A-C),y=Math.sqrt(C-A);
return [r(4/3*pi*A*c),a==c?r(4*pi*Math.pow(a,2)):a>c?r(2*pi*a*(a+C/x*h(x/c))):r(2*pi*a*(a+C/y*Math.asin(y/c)))]
}
r=n=>Math.round(n*100)/100
h=x=>Math.log(x+Math.sqrt(x*x+1))
"use strict";

hamming=(n, m)=>p(n,20).split("").reduceRight((a,b,i)=>a+(p(n,20).split("")[i] !== p(m,20).split("")[i]),0);
p=(n, w)=>Array.apply(null, Array(w-n.toString(2).length+1)).map(Number.prototype.valueOf,0).join("") + n.toString(2);
circleEquation=(n)=>{
    var p=n.match(/\((\d+),(\d+)\),\((\d+),(\d+)\),\((\d+),(\d+)\)/),a=[],b=[],c=[];a[0]=~~p[1],a[1]=~~p[2],b[0]=~~p[3],b[1]=~~p[4],c[0]=~~p[5],c[1]=~~p[6],e=k(a,b,c);
    return "(x-"+r(e[0])+")^2+(y-"+r(e[1])+")^2="+r(d(a, e))+"^2"
}
k=(b,c,d)=>{
    var temp=s(c[0])+s(c[1]),bc=(s(b[0])+s(b[1])-temp)/2,cd=(temp-s(d[0])-s(d[1]))/2,det=(b[0]-c[0])*(c[1]-d[1])-(c[0]-d[0])*(b[1]-c[1]);
    return [(bc*(c[1]-d[1])-cd*(b[1]-c[1]))/det,((b[0]-c[0])*cd-(c[0]-d[0])*bc)/det];
}
s=a=>a*a;
d=(a,b)=>Math.sqrt(s(a[0]-b[0])+s(a[1]-b[1]));
r=n=>Math.round(n*100)/100;
golf=g=>(g.length==1||g[0][0][0]!=g[1][0][0]&&golf(g.slice(1,g.length)))&&h(g[0]);
h=g=>(g.length==1||g[0][0]!=g[1][0]&&h(g.slice(1,g.length)))&&i(g[0]);
i=g=>g.length==1||g[0]!=g[1]&&i(g.slice(1,g.length));
myMax=(a,b)=>(a>b)?a:b;
rotateList=(e, r)=>{
    while(r--){
        e.push(e.shift());    
    }
    return e;
}
sureNot=l=>(l.startsWith('not '))?l:"not "+l;
twoMonkeys=(a,b)=>a===b;
function listCombination(arr1, arr2) {
    var arr = [];
    for(var i = 0; i < arr1.length; i++){
        arr.push(arr1[i]);
        arr.push(arr2[i]);
    }
    return arr;
}
strLength=l=>l.length;
var pure_numbers = [
    [ // 0
        [1,1,0],
        [1,0,1],
        [1,0,1],
        [1,0,1],
        [0,1,1],
    ],
    [ // 1
        [0,1,0],
        [1,1,0],
        [0,1,0],
        [0,1,0],
        [0,1,0],
    ],
    [ // 2
        [1,1,1],
        [0,0,1],
        [0,1,1],
        [1,0,0],
        [1,1,1],
    ],
    [ // 3
        [1,1,1],
        [0,0,1],
        [0,1,0],
        [0,0,1],
        [1,1,1],
    ],
    [ // 4
        [1,0,1],
        [1,0,1],
        [1,1,1],
        [0,0,1],
        [0,0,1],
    ],
    [ // 5
        [1,1,1],
        [1,0,0],
        [1,1,0],
        [0,0,1],
        [1,1,0],
    ],
    [ // 6
        [0,1,1],
        [1,0,0],
        [1,1,1],
        [1,0,1],
        [0,1,1],
    ],
    [ // 7
        [1,1,1],
        [0,0,1],
        [0,1,0],
        [1,0,0],
        [1,0,0],
    ],
    [ // 8
        [1,1,1],
        [1,0,1],
        [1,1,1],
        [1,0,1],
        [1,1,1],
    ],
    [ // 9
        [0,1,1],
        [1,0,1],
        [1,1,1],
        [0,0,1],
        [1,1,0],
    ]
], index = 0;
recognize=(a)=>{
    var returnInt = "";
    var numbers = [];
    for(var y = 0; y < a.length; y++){
        var index = 0;
        while(a[y].length > 1){
            a[y].shift();
            if(!numbers[index]){
                numbers[index] = [];
            }
            numbers[index].push(a[y].splice(0,3));
            index++;
        }
    }
    for(var i = 0; i < numbers.length; i++){
        var this_num = JSON.stringify(numbers[i]).replace(/\[/g, "").replace(/\]/g, "");
        for(var a = 0; a < pure_numbers.length; a++){
            var that_num = JSON.stringify(pure_numbers[a]).replace(/\[/g, "").replace(/\]/g, "");
            if(differences(this_num, that_num) < 2){
                returnInt += a;
            }
        }
    }
    return ~~returnInt;
}
differences=(a, b)=>a.split(",").reduceRight((p,c,i)=>p+(c!==b.split(",")[i]),0);