├── .DS_Store ├── .gitattributes ├── .gitignore ├── Using closures to share class state └── index.js ├── codewars-Count-the-smiley-faces- └── index.js ├── codewars-Directions-Reduction └── index.js ├── codewars-Extract-the-domain-name-from-a-URL └── index.js ├── codewars-Fibonacci-Tribonacci-and-friends └── index.js ├── codewars-Give-me-a-Diamond └── index.js ├── codewars-IQ-Test └── index.js ├── codewars-Integers--Recreation-One └── index.js ├── codewars-Land-perimeter └── index.js ├── codewars-Maximum-subarray-sum └── index.js ├── codewars-Mexican-Wave └── index.js ├── codewars-Mod4-Regex └── index.js ├── codewars-Moves-in-squared-strings-1 └── index.js ├── codewars-Moving-Zeros-To-The-End └── index.js ├── codewars-Multiplication-Tables └── index.js ├── codewars-Pete-the-baker └── index.js ├── codewars-Regex-Password-Validation └── index.js ├── codewars-Simple-Events └── index.js ├── codewars-Sum-of-Pairs └── index.js ├── codewars-Sum-of-odd-numbers ├── index.js ├── report.20200826.184054.39572.0.001.json ├── report.20200826.184213.39617.0.001.json ├── report.20200826.184254.39745.0.001.json └── report.20200826.184444.39860.0.001.json ├── codewars-Take-a-Number-And-Sum-Its-Digits-Raised-To-The-Consecutive-Powers └── index.js ├── codewars-The-Vowel-Code └── index.js ├── codewars-The-observed-PIN └── index.js ├── codewars-Tic-Tac-Toe-Checker └── index.js ├── codewars-Two-Sum └── index.js ├── codewars-Unique-In-Order └── index.js ├── codewars-factorial └── index.js ├── codewars-find-the-capitals └── find-the-capitals.js ├── codewars-plus1-Array └── index.js ├── codewars-round-up-to-the-next-multiple-of-5 └── index.js ├── codewars-titlecase ├── README.md └── codewars-titlecase.js ├── codewars-valid-braces.js ├── divisors.js ├── duplicate-encoder.js ├── findFriends.js ├── is-isogram.js ├── isValidWalk.js ├── openOrSenior.js └── range-extension └── index.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguelmanalo/my-codewars/cf27712d9faee76107a281ddfc45ce679dadbb3f/.DS_Store -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /Using closures to share class state/index.js: -------------------------------------------------------------------------------- 1 | // Using closures to share class state - 5 kyu 2 | // https://www.codewars.com/kata/53583765d5493bfdf5001b35/train/javascript 3 | // In object-oriented programming, it is sometimes useful to have private shared state among all instances of a class; in other languages, like ruby, this shared state would be tracked with a class variable. In javascript we achieve this through closures and immediately-invoked function expressions. 4 | 5 | // In this kata, I want you to write make a Cat constructor that takes arguments name and weight to instantiate a new cat object. The constructor should also have an averageWeight method that returns the average weight of cats created with the constructor. 6 | 7 | // garfield = new Cat('garfield', 25); 8 | // Cat.averageWeight(); // 25 9 | 10 | // felix = new Cat('felix', 15); 11 | // Cat.averageWeight(); // now 20 12 | // But that's not all. Cats can change weight. Use Object.defineProperty to write custom setters and getters for the weight property so that the following works properly even as instances change their weight value: 13 | 14 | // felix.weight = 25; 15 | // felix.weight // 25 16 | // Cat.averageWeight(); // now 25 17 | // Object.defineProperty must be used to pass all tests. Storing a reference to all instances and recalculating the average weight each time is easier, but would prevent garbage collection from working properly if used in a production environment. 18 | 19 | // Finally, since average weight is an aggregate statistic it's important that we validate constructor arguments so that no cats are created without a specified weight; so, make sure to throw an error if both arguments are not recieved by the constructor. 20 | 21 | // Summary of requirements: 22 | // Cat constructor, requiring arguments for name and weight 23 | // Throw an error if name or weight not specified when invoking the constructor. 24 | // Cat.averageWeight() method should give the average weight of all cat instances created with Cat, even after if the instance's properties have changed. 25 | // Must use Object.defineProperty 26 | 27 | // FUNDAMENTALS, CLOSURES, BASIC LANGUAGE FEATURES, DESIGN PATTERNS, DESIGN PRINCIPLES, INHERITANCE, OBJECT-ORIENTED PROGRAMMING, POLYMORPHISM 28 | 29 | // Let's make a Cat constructor! 30 | var Cat = (function () { 31 | // ... your code here. 32 | this.name = name 33 | }()); 34 | 35 | fluffy = new Cat('fluffy', 15); 36 | garfield = new Cat('garfield', 25); 37 | 38 | 39 | // Test.assertEquals(fluffy.weight, 15); 40 | // Test.assertEquals(fluffy instanceof Cat, true); 41 | // Test.assertEquals(fluffy.averageWeight, undefined); 42 | // Test.assertEquals(typeof Cat.averageWeight, "function"); 43 | // Test.assertEquals(Cat.averageWeight(), 20); -------------------------------------------------------------------------------- /codewars-Count-the-smiley-faces-/index.js: -------------------------------------------------------------------------------- 1 | // Count the smiley faces! - 6 kyu - codewars 2 | // https://www.codewars.com/kata/583203e6eb35d7980400002a/train/javascript 3 | 4 | // Given an array (arr) as an argument complete the function countSmileys that should return the total number of smiling faces. 5 | 6 | // Rules for a smiling face: 7 | // Each smiley face must contain a valid pair of eyes. Eyes can be marked as : or ; 8 | // A smiley face can have a nose but it does not have to. Valid characters for a nose are - or ~ 9 | // Every smiling face must have a smiling mouth that should be marked with either ) or D 10 | // No additional characters are allowed except for those mentioned. 11 | 12 | // Valid smiley face examples: :) :D ;-D :~) 13 | // Invalid smiley faces: ;( :> :} :] 14 | 15 | // Example 16 | // countSmileys([':)', ';(', ';}', ':-D']); // should return 2; 17 | // countSmileys([';D', ':-(', ':-)', ';~)']); // should return 3; 18 | // countSmileys([';]', ':[', ';*', ':$', ';-D']); // should return 1; 19 | 20 | // Note 21 | // In case of an empty array return 0. You will not be tested with invalid input (input will always be an array). Order of the face (eyes, nose, mouth) elements will always be the same. 22 | 23 | //return the total number of smiling faces in the array 24 | // const countSmileys = arr => { 25 | // // In case of an empty array return 0. 26 | // if (arr.length === 0) return 0; 27 | 28 | // let numFaces = 0; 29 | 30 | // for (let i = 0; i < arr.length; i++) { 31 | // let faceSplit = arr[i].split(''); 32 | 33 | // // go mouth-first through the face 34 | // for (let k = faceSplit.length - 1; k > 0; k--) { 35 | // if (faceSplit.length === 3) { 36 | // if ((faceSplit[k] === ')' || faceSplit[k] === 'D') && (faceSplit[k - 1] === '-' || faceSplit[k - 1] === '~') && (faceSplit[k - 2] === ':' || faceSplit[k - 2] === ';')) numFaces++; 37 | // } else { 38 | // // was getting false positives here, didn't have parens around the OR. 39 | // if ((faceSplit[k] === ')' || faceSplit[k] === 'D') && (faceSplit[k - 1] === ':' || faceSplit[k - 1] === ';')) { 40 | // numFaces++; 41 | // } 42 | // } 43 | // } 44 | // } 45 | // return numFaces; 46 | // } 47 | 48 | // Refactored to use Regex 49 | const countSmileys = arr => { 50 | if (arr.length === 0) return 0; 51 | let numFaces = 0; 52 | 53 | arr.forEach((item) => { 54 | if (/^[:|;][-|~]?[)|D]$/.test(item)) numFaces++; 55 | }); 56 | 57 | return numFaces; 58 | } 59 | 60 | // console.log(countSmileys([])); // 0 61 | console.log(countSmileys([':D',':~)',';~D',':)'])); // 4 62 | console.log(countSmileys([':)',':(',':D',':O',':;'])); // 2 63 | console.log(countSmileys([';]', ':[', ';*', ':$', ';-D'])); // 1 64 | 65 | // My Notes 66 | // strings, : ; 67 | // nose optional - ~ 68 | // mouth required ) D 69 | // no other chars allowed 70 | // empty array return 0 71 | // no invalid inputs will be given 72 | // faces will always be going to the right 73 | // faces are strings so I can check them with bracket notation 74 | // maybe i can blow them up with split and use array methods -------------------------------------------------------------------------------- /codewars-Directions-Reduction/index.js: -------------------------------------------------------------------------------- 1 | // Directions Reduction - 5 kyu 2 | // https://www.codewars.com/kata/550f22f4d758534c1100025a/train/javascript 3 | // Once upon a time, on a way through the old wild mountainous west,… 4 | // … a man was given directions to go from one point to another. The directions were "NORTH", "SOUTH", "WEST", "EAST". Clearly "NORTH" and "SOUTH" are opposite, "WEST" and "EAST" too. 5 | 6 | // Going to one direction and coming back the opposite direction right away is a needless effort. Since this is the wild west, with dreadfull weather and not much water, it's important to save yourself some energy, otherwise you might die of thirst! 7 | 8 | // How I crossed a mountain desert the smart way. 9 | 10 | // The directions given to the man are, for example, the following (depending on the language): 11 | // ["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]. 12 | 13 | // You can immediatly see that going "NORTH" and immediately "SOUTH" is not reasonable, better stay to the same place! So the task is to give to the man a simplified version of the plan. A better plan in this case is simply: 14 | 15 | // ["WEST"] 16 | 17 | // Other examples: 18 | // In ["NORTH", "SOUTH", "EAST", "WEST"], the direction "NORTH" + "SOUTH" is going north and coming back right away. 19 | 20 | // The path becomes ["EAST", "WEST"], now "EAST" and "WEST" annihilate each other, therefore, the final result is [] (nil in Clojure). 21 | 22 | // In ["NORTH", "EAST", "WEST", "SOUTH", "WEST", "WEST"], "NORTH" and "SOUTH" are not directly opposite but they become directly opposite after the reduction of "EAST" and "WEST" so the whole path is reducible to ["WEST", "WEST"]. 23 | 24 | // Task 25 | // Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed (W<->E or S<->N side by side). 26 | 27 | // Notes 28 | // Not all paths can be made simpler. The path ["NORTH", "WEST", "SOUTH", "EAST"] is not reducible. "NORTH" and "WEST", "WEST" and "SOUTH", "SOUTH" and "EAST" are not directly opposite of each other and can't become such. Hence the result path is itself : ["NORTH", "WEST", "SOUTH", "EAST"]. 29 | 30 | // FUNDAMENTALS 31 | 32 | const dirReduc = arr => { 33 | // make a copy of the arr argument and mutate that copy 34 | const copyArr = arr.slice(); 35 | // iterate through the array and see if the next value in the array is a polar opposite 36 | const pairChecker = arr => { 37 | let madeChanges = false; 38 | for (let i = 0, len = arr.length; i < len; i++) { 39 | if ((arr[i] === "NORTH" && arr[i + 1] === "SOUTH") || (arr[i] === "SOUTH" && arr[i + 1] === "NORTH")) { 40 | // if the current value and the next value are indeed polar opposites, splice them both out and set the madeChanges flag to true 41 | arr.splice(i, 2); 42 | madeChanges = true; 43 | } 44 | else if ((arr[i] === "WEST" && arr[i + 1] === "EAST") || (arr[i] === "EAST" && arr[i + 1] === "WEST")) { 45 | // if the current value and the next value are indeed polar opposites, splice them both out and set the madeChanges flag to true 46 | arr.splice(i, 2); 47 | madeChanges = true; 48 | } 49 | } 50 | // set a boolean flag inside the function scope called madeChanges to see if the given array iteration needed any splicing, if it didn't need any changes the flag never gets set to true and the recursive call doesn't happen and the final arr value is returned 51 | return madeChanges === true ? pairChecker(arr) : arr; 52 | } 53 | return pairChecker(copyArr); 54 | } 55 | 56 | // console.log(dirReduc(["NORTH", "SOUTH"])); // [] 57 | // console.log(dirReduc(["SOUTH", "NORTH"])); // [] 58 | // console.log(dirReduc(["WEST", "EAST"])); // [] 59 | // console.log(dirReduc(["EAST", "WEST"])); // [] 60 | 61 | // console.log(dirReduc(["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"])); //["WEST"] 62 | // console.log(dirReduc(["NORTH", "WEST", "SOUTH", "EAST"])); // ["NORTH", "WEST", "SOUTH", "EAST"] 63 | // console.log(dirReduc(["NORTH", "SOUTH", "EAST", "WEST", "EAST", "WEST"])); // [] 64 | // console.log(dirReduc(["NORTH", "EAST", "WEST", "SOUTH", "WEST", "WEST"])); // ["WEST", "WEST"] -------------------------------------------------------------------------------- /codewars-Extract-the-domain-name-from-a-URL/index.js: -------------------------------------------------------------------------------- 1 | // Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example: 2 | 3 | // domainName("http://github.com/carbonfive/raygun") == "github" 4 | // domainName("http://www.zombie-bites.com") == "zombie-bites" 5 | // domainName("https://www.cnet.com") == "cnet" 6 | 7 | const domainName = (domainStr) => 8 | { 9 | // let domainRegex = /(?!w)(?!/http/)(\w+)(?!\.)/g; 10 | let domainRegex = /(?!http|https|co|www)(?=\w+)/ 11 | let result = domainStr.match(domainRegex); 12 | console.log(result) 13 | return result; 14 | } 15 | 16 | console.log(domainName("http://google.com")); // "google" 17 | console.log(domainName("http://google.co.jp")); // "google" 18 | console.log(domainName("www.xakep.ru")); // "xakep" 19 | console.log(domainName("https://youtube.com")); // "youtube" 20 | 21 | // My Notes 22 | // let domainRegex2 = /(http://|https://)(www.)/ 23 | // look for multiple strings of lettesr and numbers followed by a dot 24 | // let domainRegex3 = /()/ 25 | -------------------------------------------------------------------------------- /codewars-Fibonacci-Tribonacci-and-friends/index.js: -------------------------------------------------------------------------------- 1 | // Tribonacci Sequence - codewars 2 | // https://www.codewars.com/kata/556deca17c58da83c00002db/train/javascript 3 | 4 | // Well met with Fibonacci bigger brother, AKA Tribonacci. 5 | 6 | // As 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 :( 7 | 8 | // So, if we are to start our Tribonacci sequence with [1, 1, 1] as a starting input (AKA signature), we have this sequence: 9 | 10 | // [1, 1 ,1, 3, 5, 9, 17, 31, ...] 11 | // But 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: 12 | 13 | // [0, 0, 1, 1, 2, 4, 7, 13, 24, ...] 14 | // Well, 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. 15 | 16 | // Signature will always contain 3 numbers; n will always be a non-negative number; if n == 0, then return an empty array (except in C return NULL) and be ready for anything else which is not clearly specified ;) 17 | 18 | // If you enjoyed this kata more advanced and generalized version of it can be found in the Xbonacci kata 19 | 20 | const tribonacci = (signature, n) => { 21 | const answerArr = []; 22 | // handle the given edge case 23 | if (n === 0) return answerArr; 24 | 25 | // if n < signature, handle it 26 | if (n < 3) { 27 | for (let s = 0; answerArr.length < n; s++) { 28 | answerArr.push(signature[s]); 29 | } 30 | return answerArr; 31 | } 32 | 33 | // if n > 3 put the whole signature in the answerArr 34 | signature.forEach(item => { answerArr.push(item); }); 35 | 36 | // calculate the Tribianni and push it onto answerArr until we reach desired length n 37 | for (let k = 0; answerArr.length < n; k++) { 38 | answerArr.push((answerArr[k] + answerArr[k + 1] + answerArr[k + 2])); 39 | } 40 | return answerArr; 41 | } 42 | 43 | // console.log(tribonacci([1,1,1], 10)); // [1,1,1,3,5,9,17,31,57,105] 44 | // console.log(tribonacci([0,0,1], 10)); // [0,0,1,1,2,4,7,13,24,44] 45 | // console.log(tribonacci([0,1,1], 10)); // [0,1,1,2,4,7,13,24,44,81] 46 | // console.log(tribonacci([1,0,0], 10)); // [1,0,0,1,1,2,4,7,13,24] 47 | // console.log(tribonacci([0,0,0], 10)); // [0,0,0,0,0,0,0,0,0,0] 48 | // console.log(tribonacci([1,2,3], 10)); // [1,2,3,6,11,20,37,68,125,230] 49 | // console.log(tribonacci([3,2,1], 10)); // [3,2,1,6,9,16,31,56,103,190] 50 | // console.log(tribonacci([1,1,1], 1)); // [ 1 ] 51 | // console.log(tribonacci([1,2,1], 2)); // [ 1 ] 52 | // console.log(tribonacci([300,200,100], 0)); // [] 53 | // console.log(tribonacci([0.5,0.5,0.5], 30)); // [0.5,0.5,0.5,1.5,2.5,4.5,8.5,15.5,28.5,52.5,96.5,177.5,326.5,600.5,1104.5,2031.5,3736.5,6872.5,12640.5,23249.5,42762.5,78652.5,144664.5,266079.5,489396.5,900140.5,1655616.5,3045153.5,5600910.5,10301680.5] -------------------------------------------------------------------------------- /codewars-Give-me-a-Diamond/index.js: -------------------------------------------------------------------------------- 1 | // Give me a Diamond - codewars (6 kyu) 2 | // FUNDAMENTALS STRINGS 3 | // https://www.codewars.com/kata/5503013e34137eeeaa001648/train/javascript 4 | // 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. 5 | 6 | // Task 7 | // You need to return a string that looks like a diamond shape when printed on the screen, using asterisk (*) characters. Trailing spaces should be removed, and every line must be terminated with a newline character (\n). 8 | 9 | // Return null/nil/None/... if the input is an even number or negative, as it is not possible to print a diamond of even or negative size. 10 | 11 | // Examples 12 | // A size 3 diamond: 13 | 14 | // * 15 | // *** 16 | // * 17 | // ...which would appear as a string of " *\n***\n *\n" 18 | 19 | // A size 5 diamond: 20 | 21 | // * 22 | // *** 23 | // ***** 24 | // *** 25 | // * 26 | // ...that is: " *\n ***\n*****\n ***\n *\n" 27 | 28 | const diamond = n => { 29 | // Return null/nil/None/... if the input is an even number or negative 30 | if (n % 2 === 0 || n < 0) return null; 31 | const diamMaker = []; 32 | 33 | diamondRight: for (let s = n; s >= 0; s -= 2) { 34 | // every line of the diamond has to be on a new line 35 | diamMaker.push('*'.repeat(s) + '\n'); 36 | } 37 | 38 | diamondLeft: for (let s = n - 2; s >= 0; s -= 2) { 39 | // i start at the center of the diamond minus the row already completed above and radiate outwards to the left 40 | // unshift lets me go left while iterating in the same way for d 41 | diamMaker.unshift('*'.repeat(s) + '\n'); 42 | } 43 | spaceLoopLeft: for (let i = Math.floor(diamMaker.length / 2); i >= 0; i--) { 44 | // this was strangely hard 45 | // start in the middle, don't ever add spaces to the middle 46 | // iterate i and concat the appropriate amount of spaces 47 | // I guess i was trying to iterate both the diamonds and the spaces together and couldn't quite make the logic work for my brain 48 | diamMaker[i] = ' '.repeat(Math.floor(diamMaker.length / 2) - i).concat(diamMaker[i]); 49 | } 50 | spaceLoopRight: for (let i = 0; i <= Math.floor(diamMaker.length / 2); i++) { 51 | diamMaker[Math.floor(diamMaker.length / 2) + i] = ' '.repeat(i).concat(diamMaker[Math.floor(diamMaker.length / 2) + i]); 52 | } 53 | return diamMaker.join(''); 54 | } 55 | 56 | console.log(diamond(1)); 57 | console.log(diamond(1) === "*\n"); // "*\n" 58 | console.log(diamond(3)); 59 | console.log(diamond(3) === " *\n***\n *\n"); // " *\n***\n *\n" 60 | console.log(diamond(5)); 61 | console.log(diamond(5) === " *\n ***\n*****\n ***\n *\n"); // " *\n ***\n*****\n ***\n *\n" 62 | console.log(diamond(2)); // null 63 | console.log(diamond(-3)); // null 64 | console.log(diamond(0)); // null -------------------------------------------------------------------------------- /codewars-IQ-Test/index.js: -------------------------------------------------------------------------------- 1 | // IQ Test - codewars 2 | // https://www.codewars.com/kata/552c028c030765286c00007d/train/javascript 3 | 4 | // Bob 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. 5 | 6 | // ! 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) 7 | 8 | // ##Examples : 9 | // iqTest("2 4 7 8 10") => 3 // Third number is odd, while the rest of the numbers are even 10 | // iqTest("1 2 1 1") => 2 // Second number is even, while the rest of the numbers are odd 11 | 12 | const iqTest = numStr => { 13 | // make even and odd arrays 14 | const even = []; 15 | const odd = []; 16 | 17 | // argument is given as string, so i turn it into numbers in an array 18 | // could use a for-loop, went with forEach 19 | numStr.split(' ').forEach((item, index) => { 20 | // if item is even, log the index where it is 21 | // if item is odd, log the index where it is 22 | item % 2 === 0 ? even.push(index) : odd.push(index); 23 | }); 24 | 25 | // whichever array length is bigger means that the lower count is the outlier, return the index of the outlier plus 1 because Bob needs it in that format 26 | return even.length > odd.length ? odd[0] + 1 : even[0] + 1; 27 | } 28 | 29 | console.log(iqTest("2 4 7 8 10")); // 3, "Third number is odd, while the rest of the numbers are even" 30 | console.log(iqTest("1 2 2")); // 1, "First number is odd, while the rest of the numbers are even" -------------------------------------------------------------------------------- /codewars-Integers--Recreation-One/index.js: -------------------------------------------------------------------------------- 1 | // Integers: Recreation One - 5kyu 2 | // https://www.codewars.com/kata/55aa075506463dac6600010d/train/javascript 3 | // Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square! 4 | 5 | // Given two integers m, n (1 <= m <= n) we want to find all integers between m and n whose sum of squared divisors is itself a square. 42 is such a number. 6 | 7 | // The result will be an array of arrays or of tuples (in C an array of Pair) or a string, each subarray having two elements, first the number whose squared divisors is a square and then the sum of the squared divisors. 8 | 9 | // #Examples: 10 | // list_squared(1, 250) --> [[1, 1], [42, 2500], [246, 84100]] 11 | // list_squared(42, 250) --> [[42, 2500], [246, 84100]] 12 | // The form of the examples may change according to the language, see Example Tests: for more details. 13 | 14 | // FUNDAMENTALS, ALGORITHMS, OPTIMIZATION 15 | 16 | const listSquared = (m, n) => { 17 | const answerArr = []; 18 | const divisorObj = {}; 19 | 20 | // sort every number and it's divisors into my divisorObj 21 | for (let i = m; i <= n; i++) { 22 | for (j = 1; j <= i; j++) { 23 | if (!divisorObj[i]) divisorObj[i] = []; 24 | if (i % j === 0) divisorObj[i].push(j); 25 | } 26 | } 27 | 28 | // evaluate the sum of the divisors when it's calculated 29 | for (const property in divisorObj) { 30 | let sqSum = divisorObj[property].map(item => item * item).reduce((acc, cv) => acc + cv, 0); 31 | if (Math.sqrt(sqSum) % 1 === 0) answerArr.push([Number(property), sqSum]); 32 | } 33 | return answerArr; 34 | } 35 | 36 | console.log(listSquared(1, 250)); // [[1, 1], [42, 2500], [246, 84100]]) 37 | // console.log(listSquared(42, 250)); // [[42, 2500], [246, 84100]]) 38 | // console.log(listSquared(250, 500)); // [[287, 84100]]) -------------------------------------------------------------------------------- /codewars-Land-perimeter/index.js: -------------------------------------------------------------------------------- 1 | // Land perimeter - 5 kyu 2 | // codewars.com/kata/5839c48f0cf94640a20001d3/train/javascript 3 | 4 | // Task: 5 | // Given an array arr of strings complete the function landPerimeter by calculating the total perimeter of all the islands. Each piece of land will be marked with 'X' while the water fields are represented as 'O'. Consider each tile being a perfect 1 x 1 piece of land. Some examples for better visualization: 6 | 7 | // ['XOOXO', 8 | // 'XOOXO', 9 | // 'OOOXO', 10 | // 'XXOXO', 11 | // 'OXOOO'] 12 | 13 | // should return: "Total land perimeter: 24", 14 | 15 | // while 16 | 17 | // ['XOOO', 18 | // 'XOXO', 19 | // 'XOXO', 20 | // 'OOXX', 21 | // 'OOOO'] 22 | 23 | // should return: "Total land perimeter: 18" 24 | 25 | // FUNDAMENTALS, LOOPS, CONTROL FLOW, BASIC LANGUAGE FEATURES 26 | 27 | const landPerimeter = arr => { 28 | // declare a number to hold all the additions of the Xs I find 29 | let perimeterSum = 0; 30 | // iterate through the given array argument 31 | for (let i = 0; i < arr.length; i++) { 32 | // iterate through each individual string in the given array 33 | for (let j = 0; j < arr[i].length; j++) { 34 | // see if a char is an X 35 | if (arr[i][j] === 'X') { 36 | // other Xs will minus the potential perimeter of an X which starts at 4 for a free standing X 37 | let tempPeriVal = 4; 38 | // check horizontally to see if there's other Xs and if there are, minus 1 from tempPeriVal 39 | if (arr[i][j - 1] === 'X') tempPeriVal--; 40 | if (arr[i][j + 1] === 'X') tempPeriVal--; 41 | // check vertically to see if there's other Xs and if there are, minus 1 from tempPeriVal 42 | if (arr[i + 1] !== undefined && arr[i + 1][j] === 'X') tempPeriVal--; 43 | if (arr[i - 1] !== undefined && arr[i - 1][j] === 'X') tempPeriVal--; 44 | // store the calculated value of that X in perimeterSum 45 | perimeterSum += tempPeriVal; 46 | // move onto the next item in the string 47 | } 48 | } 49 | } 50 | // return the sum of all the X-values in the format that was provided 51 | return `Total land perimeter: ${perimeterSum}`; 52 | } 53 | 54 | console.log(landPerimeter(['XOOXO', 'XOOXO', 'OOOXO', 'XXOXO', 'OXOOO'])); // "Total land perimeter: 24" 55 | console.log(landPerimeter(["OXOOOX", "OXOXOO", "XXOOOX", "OXXXOO", "OOXOOX", "OXOOOO", "OOXOOX", "OOXOOO", "OXOOOO", "OXOOXX"])); // "Total land perimeter: 60" 56 | console.log(landPerimeter(["OXOOO", "OOXXX", "OXXOO", "XOOOO", "XOOOO", "XXXOO", "XOXOO", "OOOXO", "OXOOX", "XOOOO", "OOOXO"])); // "Total land perimeter: 52" 57 | console.log(landPerimeter(["XXXXXOOO", "OOXOOOOO", "OOOOOOXO", "XXXOOOXO", "OXOXXOOX"])); // "Total land perimeter: 40" 58 | console.log(landPerimeter(["XOOOXOO", "OXOOOOO", "XOXOXOO", "OXOXXOO", "OOOOOXX", "OOOXOXX", "XXXXOXO"])); // "Total land perimeter: 54" 59 | console.log(landPerimeter(["OOOOXO", "XOXOOX", "XXOXOX", "XOXOOO", "OOOOOO", "OOOXOO", "OOXXOO"])); // "Total land perimeter: 40" -------------------------------------------------------------------------------- /codewars-Maximum-subarray-sum/index.js: -------------------------------------------------------------------------------- 1 | // 5 kyu - Maximum subarray sum 2 | // https://www.codewars.com/kata/54521e9ec8e60bc4de000d6c/train/javascript 3 | 4 | // The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers: 5 | 6 | // maxSequence([-2, 1, -3, 4, -1, 2, 1, -5, 4]) 7 | // // should be 6: [4, -1, 2, 1] 8 | // Easy case is when the list is made up of only positive numbers and the maximum sum is the sum of the whole array. If the list is made up of only negative numbers, return 0 instead. 9 | 10 | // Empty list is considered to have zero greatest sum. Note that the empty list or array is also a valid sublist/subarray. 11 | 12 | // FUNDAMENTALS, ALGORITHMS, LISTS, DATA STRUCTURES, DYNAMIC PROGRAMMING 13 | 14 | const maxSequence = arr => { 15 | // declare a variable to store the greatest sum I've found so far 16 | let greatestSum = 0; 17 | // an empty list has a return value of 0 18 | if (arr.length === 0) return 0; 19 | // if the given arr is only positive numbers the return value is the sum of the whole arr 20 | else if (arr.every(item => item > 0)) return arr.reduce((acc, cv) => acc + cv, 0); 21 | // if the given arr is only negative numbers the return value is 0 22 | else if (arr.every(item => item < 0)) return 0; 23 | // for mixed positive and negative integer arrays I iterate through the array making sums. So, sum of 0 and 1 store that somewhere then sum of 0, 1, and 2 and compare that to what's stored in greatestSum then sum of 0, 1, 2, and 3 and so forth 24 | // make a nested for loop with the inner loop marking the new beginning spot of the start of the slice, so the slice isn't stuck at the beginning of the array. It can check for all the different combinations of sums within the array 25 | startAtBeginningLoop: for (let i = 0; i < arr.length; i++) { 26 | // since I'm using slice, j needs to mark the end-point of the slice so j has to be one more than the final array index value 27 | // 28 | oneStepAheadLoop: for (let j = i + 1; j < arr.length + 1; j++) { 29 | let tempSum = arr.slice(i, j).reduce((acc, cv) => acc + cv, 0); 30 | // if the sum it's found right now is greater than the sum greaterSum had previously, greatestSum is now that sum 31 | if (tempSum > greatestSum) greatestSum = tempSum; 32 | } 33 | } 34 | // return that stored value after the whole array is iterated because that means I have found the greatest sum among the combinations 35 | return greatestSum; 36 | } 37 | 38 | console.log(maxSequence([-2, 1, -3, 4, -1, 2, 1, -5, 4])); // 6 39 | console.log(maxSequence([])); // 0, empty array 40 | console.log(maxSequence([1, 2, 3,])); // 6, all positive 41 | console.log(maxSequence([-1, -2, -3,])); // 0, all negatives -------------------------------------------------------------------------------- /codewars-Mexican-Wave/index.js: -------------------------------------------------------------------------------- 1 | // Mexican Wave 2 | // https://www.codewars.com/kata/58f5c63f1e26ecda7e000029/train/javascript 3 | 4 | // Introduction 5 | // The 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. 6 | // 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: https://en.wikipedia.org/wiki/Wave_(audience)) 7 | 8 | // Task 9 | // In 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. 10 | 11 | // Rules 12 | // 1. The input string will always be lower case but maybe empty. 13 | // 2. If the character in the string is whitespace then pass over it as if it was an empty seat. 14 | 15 | // Example 16 | // wave("hello") => ["Hello", "hEllo", "heLlo", "helLo", "hellO"] 17 | 18 | const wave = str => { 19 | // Code here 20 | const answerArray = []; 21 | let splitStr = str.split(''); 22 | 23 | // the for-loop method 24 | for (let i = 0; i < splitStr.length ; i++) { 25 | // skip the whitespace 26 | if (splitStr[i] !== ' ') { 27 | 28 | // make each letter uppercase 29 | splitStr[i] = splitStr[i].toUpperCase(); 30 | 31 | // make all other items lowercase 32 | // iterate left from where I am at i 33 | for (let k = i - 1; k >= 0; k--) { 34 | splitStr[k] = splitStr[k].toLowerCase(); 35 | } 36 | answerArray.push(splitStr.join('')); 37 | } 38 | } 39 | return answerArray; 40 | } 41 | 42 | // console.log(wave("mig uel")); // Should return: ["Mig uel", "mIg uel", "miG uel", "mig Uel", "mig uEl", "mig ueL"] 43 | // console.log(wave("")); // Should return: [] 44 | console.log(wave(" gap ")); // Should return: [" Gap ", " gAp ", " gaP "] 45 | // console.log(wave("hello")); // Should return: ["Hello", "hEllo", "heLlo", "helLo", "hellO"] 46 | // console.log(wave("codewars")); // Should return: ["Codewars", "cOdewars", "coDewars", "codEwars", "codeWars", "codewArs", "codewaRs", "codewarS"] 47 | console.log(wave("two words")); // Should return: ["Two words", "tWo words", "twO words", "two Words", "two wOrds", "two woRds", "two worDs", "two wordS"] -------------------------------------------------------------------------------- /codewars-Mod4-Regex/index.js: -------------------------------------------------------------------------------- 1 | // Mod4 Regex - 5 kyu 2 | // codewars.com/kata/54746b7ab2bc2868a0000acf/train/javascript 3 | // NOTE: This kata requires a decent knowledge of Regular Expressions. As such, it's best to learn about it before tackling this kata. Some good places to start are: the MDN pages, and Regular-Expressions.info. 4 | 5 | // You are to write a Regular Expression that matches any string with at least one number divisible by 4 (with no remainder). In most languages, you could do this easily by using number % 4 == 0. How would you do it with Regex? 6 | 7 | // A number will start with [ and end with ]. They may (or may not) include a plus or minus symbol at the start; this should be taken into account. Leading zeros may be present, and should be ignored (no octals here ;P). There may be other text in the string, outside of the number; this should also be ignored. Also, all numbers will be integers; any floats should be ignored. 8 | 9 | // If there are no valid numbers defined as above, there should be no match made by your regex. 10 | 11 | // So here are some examples: 12 | 13 | // "[+05620]" // 5620 is divisible by 4 (valid) 14 | // "[+05621]" // 5621 is not divisible by 4 (invalid) 15 | // "[-55622]" // -55622 is not divisible by 4 (invalid) 16 | // "[005623]" // 5623 invalid 17 | // "[005624]" // 5624 valid 18 | // "[-05628]" // valid 19 | // "[005632]" // valid 20 | // "[555636]" // valid 21 | // "[+05640]" // valid 22 | // "[005600]" // valid 23 | // "the beginning [0] ... [invalid] numb[3]rs ... the end" // 0 is valid 24 | // "No, [2014] isn't a multiple of 4..." // 2014 is invalid 25 | // "...may be [+002016] will be." // 2016 is valid 26 | 27 | // NOTE: Only Mod4.test(str) will be used, so your expression will just need make a match of some kind. 28 | 29 | // FUNDAMENTALS, REGULAR EXPRESSIONS, DECLARATIVE PROGRAMMING, ADVANCED LANGUAGE FEATURES, STRINGS 30 | 31 | var Mod4 = /\-*(?!~)\d+/g; 32 | 33 | console.log(Mod4.test("[+05620]")); // true 34 | console.log("[+05620]".match(Mod4)); // 5620 is divisible by 4 (valid) 35 | console.log("[+05621]".match(Mod4)); // 5621 is not divisible by 4 (invalid) 36 | console.log("[-55622]".match(Mod4)); // -55622 is not divisible by 4 (invalid) 37 | console.log("[005623]".match(Mod4)); // 5623 invalid 38 | console.log("[005624]".match(Mod4)); // 5624 valid 39 | console.log("[-05628]".match(Mod4)); // valid 40 | console.log("[005632]".match(Mod4)); // valid 41 | console.log("[555636]".match(Mod4)); // valid 42 | console.log("[~24]".match(Mod4)); // invalid 43 | console.log("[-55622]".match(Mod4)); // invalid 44 | console.log("the beginning [0] ... [invalid] numb[3]rs ... the end".match(Mod4)); // 0 is valid 45 | console.log("No, [2014] isn't a multiple of 4...".match(Mod4)); // 2014 is invalid 46 | console.log("...may be [+002016] will be.".match(Mod4)); // 2016 is valid -------------------------------------------------------------------------------- /codewars-Moves-in-squared-strings-1/index.js: -------------------------------------------------------------------------------- 1 | // Moves in squared strings (Part I) 2 | // https://www.codewars.com/kata/56dbe0e313c2f63be4000b25/train/javascript 3 | 4 | // This kata is the first of a sequence of four about "Squared Strings". 5 | // You are given a string of n lines, each substring being n characters long: For example: 6 | // s = "abcd\nefgh\nijkl\nmnop" 7 | 8 | // We will study some transformations of this square of strings. 9 | 10 | // Vertical mirror: vert_mirror (or vertMirror or vert-mirror) 11 | // vert_mirror(s) => "dcba\nhgfe\nlkji\nponm" 12 | 13 | // Horizontal mirror: hor_mirror (or horMirror or hor-mirror) 14 | // hor_mirror(s) => "mnop\nijkl\nefgh\nabcd" 15 | 16 | // or printed: 17 | // vertical mirror |horizontal mirror 18 | // abcd --> dcba |abcd --> mnop 19 | // efgh hgfe |efgh ijkl 20 | // ijkl lkji |ijkl efgh 21 | // mnop ponm |mnop abcd 22 | // Task: 23 | 24 | // Write these two functions 25 | // and high-order function oper(fct, s) where 26 | 27 | // fct is the function of one variable f to apply to the string s (fct will be one of vertMirror, horMirror) 28 | // Examples: 29 | 30 | // s = "abcd\nefgh\nijkl\nmnop" 31 | // oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm" 32 | // oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd" 33 | 34 | // Note: 35 | // The form of the parameter fct in oper changes according to the language. You can see each form according to the language in "Sample Tests". 36 | 37 | const vertMirror = str => { 38 | const holdingReversed = []; 39 | let newStrArr = str.split('\n').forEach((string) => { 40 | let reversed = ''; 41 | for (let i = 1; i <= string.length; i++) { 42 | reversed += string[string.length - i]; 43 | } 44 | holdingReversed.push(reversed); 45 | }); 46 | return holdingReversed.join('\n'); 47 | } 48 | 49 | const horMirror = str => str.split('\n').reverse().join('\n'); 50 | 51 | const oper = (funct, str) => funct(str); 52 | 53 | console.log(oper(vertMirror, "abcd\nefgh\nijkl\nmnop")); // "dcba\nhgfe\nlkji\nponm" 54 | console.log(oper(horMirror, "abcd\nefgh\nijkl\nmnop")); // "mnop\nijkl\nefgh\nabcd" 55 | 56 | console.log(oper(vertMirror, "hSgdHQ\nHnDMao\nClNNxX\niRvxxH\nbqTVvA\nwvSyRu")); // "QHdgSh\noaMDnH\nXxNNlC\nHxxvRi\nAvVTqb\nuRySvw" 57 | console.log(oper(vertMirror, "IzOTWE\nkkbeCM\nWuzZxM\nvDddJw\njiJyHF\nPVHfSx")); // "EWTOzI\nMCebkk\nMxZzuW\nwJddDv\nFHyJij\nxSfHVP" 58 | console.log(oper(horMirror, "lVHt\nJVhv\nCSbg\nyeCt")); // "yeCt\nCSbg\nJVhv\nlVHt" 59 | console.log(oper(horMirror, "njMK\ndbrZ\nLPKo\ncEYz")); // "cEYz\nLPKo\ndbrZ\nnjMK" 60 | 61 | // Notes 62 | // Array.join() 63 | // const elements = ['Fire', 'Air', 'Water']; 64 | 65 | // console.log(elements.join()); 66 | // expected output: "Fire,Air,Water" 67 | 68 | // console.log(elements.join('')); 69 | // expected output: "FireAirWater" 70 | 71 | // console.log(elements.join('-')); 72 | // expected output: "Fire-Air-Water" 73 | -------------------------------------------------------------------------------- /codewars-Moving-Zeros-To-The-End/index.js: -------------------------------------------------------------------------------- 1 | // Moving Zeros To The End - 5 kyu 2 | // https://www.codewars.com/kata/52597aa56021e91c93000cb0/train/javascript 3 | // Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. 4 | 5 | // moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0] 6 | 7 | const moveZeros = arr => { 8 | const arrCopy = arr.slice(); 9 | const zeroHolder = []; 10 | const nonZeroHolder = []; 11 | 12 | for (let i = 0; i < arrCopy.length; i++) { 13 | arrCopy[i] === 0 ? zeroHolder.push(arrCopy[i]) : nonZeroHolder.push(arrCopy[i]); 14 | } 15 | return nonZeroHolder.concat(zeroHolder); 16 | } 17 | 18 | console.log(moveZeros([1,2,0,1,0,1,0,3,0,1])); // [ 1, 2, 1, 1, 3, 1, 0, 0, 0, 0 ] 19 | console.log(moveZeros([false,1,0,1,2,0,1,3,"a"])); // [ false, 1, 1, 2, 1, 3, "a", 0, 0 ] -------------------------------------------------------------------------------- /codewars-Multiplication-Tables/index.js: -------------------------------------------------------------------------------- 1 | // Multiplication Tables - 6 kyu 2 | // https://www.codewars.com/kata/5432fd1c913a65b28f000342/train/javascript 3 | 4 | // Create a function that accepts dimensions, of Rows x Columns, as parameters in order to create a multiplication table sized according to the given dimensions. 5 | // **The return value of the function must be an array, and the numbers must be Fixnums, NOT strings. 6 | 7 | // Example: 8 | // multiplication_table(3,3) 9 | 10 | // 1 2 3 11 | // 2 4 6 12 | // 3 6 9 13 | 14 | // -->[[1,2,3],[2,4,6],[3,6,9]] 15 | 16 | // Each 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. 17 | 18 | // FUNDAMENTALS, MATHEMATICS, ALGORITHMS, NUMBERS 19 | 20 | const multiplicationTable = (row, col) => { 21 | const mainArr = []; 22 | 23 | // make the array structure based on how many rows are given 24 | for (let i = 1; i <= row; i++) { 25 | mainArr.push(new Array()); 26 | } 27 | 28 | // fill the first row with 1 to however many columns are needed 29 | for (let j = 1; j <= col; j++) { 30 | mainArr[0].push(j); 31 | } 32 | 33 | // fill the rest of the rows with calculated values 34 | // my outer loop here has to use row as the check, not col because I'm calucalting down each row with k and m is iterating horizontally 35 | for (let k = 1; k < row; k++) { 36 | for (let m = 0; m < mainArr[0].length; m++) { 37 | mainArr[k].push(mainArr[0][m] * (k + 1)); 38 | } 39 | } 40 | return mainArr; 41 | } 42 | 43 | console.log(multiplicationTable(4,3)); 44 | console.log(multiplicationTable(2,2)); // [[1,2],[2,4]]) 45 | console.log(multiplicationTable(3,3)); // [[1,2,3],[2,4,6],[3,6,9]]) 46 | console.log(multiplicationTable(2,5)); // [[1,2,3,4],[2,4,6,8],[3,6,9,12]]) 47 | console.log(multiplicationTable(4,4)); // [[1,2,3,4],[2,4,6,8],[3,6,9,12],[4,8,12,16]]) 48 | console.log(multiplicationTable(2,5)); // [[1,2,3,4,5],[2,4,6,8,10]]) -------------------------------------------------------------------------------- /codewars-Pete-the-baker/index.js: -------------------------------------------------------------------------------- 1 | // 5 kyu - Pete, the baker 2 | // Pete likes to bake some cakes. He has some recipes and ingredients. Unfortunately he is not good in maths. Can you help him to find out, how many cakes he could bake considering his recipes? 3 | 4 | // Write a function cakes(), which takes the recipe (object) and the available ingredients (also an object) and returns the maximum number of cakes Pete can bake (integer). For simplicity there are no units for the amounts (e.g. 1 lb of flour or 200 g of sugar are simply 1 or 200). Ingredients that are not present in the objects, can be considered as 0. 5 | 6 | // Examples: 7 | // // must return 2 8 | // cakes({flour: 500, sugar: 200, eggs: 1}, {flour: 1200, sugar: 1200, eggs: 5, milk: 200}); 9 | // // must return 0 10 | // cakes({apples: 3, flour: 300, sugar: 150, milk: 100, oil: 100}, {sugar: 500, flour: 2000, milk: 2000}); 11 | 12 | // ALGORITHMS 13 | 14 | function cakes(recipe, availIng) { 15 | // check to see if i have all the ingredients on hand 16 | // loop through recipe properties and check them against ingredients properties 17 | const ingArr = Object.keys(availIng); 18 | const reciArr = Object.keys(recipe); 19 | const potentialCakes = []; 20 | 21 | for (let i = 0; i < reciArr.length; i++) { 22 | // if the recipe calls for something I don't have, return 0 23 | if (!ingArr.includes(reciArr[i])) return 0; 24 | } 25 | 26 | for (const propertyIng in availIng) { 27 | for (const propertyRecipe in recipe) { 28 | // if the ingredients match while i iterate and neither are 0, do the division and push the result 29 | if (propertyIng === propertyRecipe && (availIng[propertyIng] > 0 && recipe[propertyRecipe] > 0)) { 30 | potentialCakes.push(availIng[propertyIng] / recipe[propertyRecipe]) 31 | } 32 | // if either ingredient is zero, just return 0 33 | else if (recipe[propertyRecipe] <= 0) { 34 | return 0; 35 | } 36 | } 37 | } 38 | // have to use the spread argument to pass the multiple values of an array as individual numbers to the Math function 39 | return Math.floor(Math.min(...potentialCakes)); 40 | } 41 | 42 | const recipe4 = {"flour":11,"cream":82,"butter":98}; 43 | const available4 = {"oil":4200,"nuts":8100,"cocoa":300,"chocolate":9100,"milk":300,"apples":0,"sugar":3700,"cream":4900,"flour":7600,"eggs":8900,"butter":8200,"crumbles":0,"pears":2700}; 44 | console.log(cakes(recipe4, available4)); // Expected: 59, instead got: 0 45 | 46 | const recipe3 = {"eggs":0,"pears":94,"crumbles":37}; 47 | const available3 = {"crumbles":800,"flour":5700,"apples":7200,"cream":300,"chocolate":9500,"butter":5400,"oil":4600,"eggs":2000,"cocoa":8200,"nuts":9000,"milk":8500,"sugar":2000,"pears":9600}; 48 | console.log(cakes(recipe3, available3)); // Expected: 0, instead got: 21 49 | 50 | const recipe1 = {flour: 500, sugar: 200, eggs: 1}; 51 | const available1 = {flour: 1200, sugar: 1200, eggs: 5, milk: 200}; 52 | // console.log(cakes(recipe1, available1)); // 2 53 | 54 | const recipe2 = {apples: 3, flour: 300, sugar: 150, milk: 100, oil: 100}; 55 | const available2 = {sugar: 500, flour: 2000, milk: 2000}; 56 | // console.log(cakes(recipe2, available2)); // 0 57 | 58 | // My Notes 59 | // look at avail first, then compare recipe against it 60 | // or just look for the same key label in both at the same time 61 | // the first instance something comes back as not enough or not even there i can return 0 -------------------------------------------------------------------------------- /codewars-Regex-Password-Validation/index.js: -------------------------------------------------------------------------------- 1 | // Regex Password Validation - 5 kyu 2 | // You need to write regex that will validate a password to make sure it meets the following criteria: 3 | 4 | // At least six characters long 5 | // contains a lowercase letter 6 | // contains an uppercase letter 7 | // contains a number 8 | // Valid passwords will only be alphanumeric characters. 9 | 10 | // FUNDAMENTALS, REGULAR EXPRESSIONS, DECLARATIVE PROGRAMMING, ADVANCED LANGUAGE FEATURES, STRINGS, VALIDATION, ALGORITHMS, UTILITIES 11 | 12 | const validate = password => /^(?!\W)(?=.*?[A-Z])(?=.*?[a-z])(?=.*?\d)\w{6,}$/.test(password); 13 | 14 | // /^?/ means scan the whole string 15 | // (?!\W) means eliminate the string if it contians anything that isn't a-z, A-Z, or 0-9 16 | // (?=.*?[A-Z]) means the string has to have at least one capital letter 17 | // (?=.*?[\d]) means at least one digit 18 | // \w{6,} means at least six chars of a-z, A-Z, or 0-9 19 | 20 | console.log(validate('djI38D55')); // 'djI38D55 - Expected true'); 21 | console.log(validate('a2.d412')); // 'a2.d412 - Expected false'); 22 | console.log(validate('JHD5FJ53')); // 'JHD5FJ53 - Expected false'); 23 | console.log(validate('!fdjn345')); // '!fdjn345 - Expected false'); 24 | console.log(validate('jfkdfj3j')); // 'jfkdfj3j - Expected false'); 25 | console.log(validate('123')); // '123 - Expected false'); 26 | console.log(validate('abc')); // 'abc - Expected false'); 27 | console.log(validate('Password123')); // 'Password123 - Expected true'); 28 | 29 | // My Notes 30 | // this: https://techearl.com/regular-expressions/regex-password-strength-validation 31 | // was the big help, the answer really. I couldn't figure out how to match more than one group at a time with negative and positive lookaheads -------------------------------------------------------------------------------- /codewars-Simple-Events/index.js: -------------------------------------------------------------------------------- 1 | // Simple Events - 5 kyu 2 | // codewars.com/kata/52d3b68215be7c2d5300022f/train/javascript 3 | // Your goal is to write an Event constructor function, which can be used to make event objects. 4 | 5 | // An event object should work like this: 6 | 7 | // it has a .subscribe() method, which takes a function and stores it as its handler 8 | // it has an .unsubscribe() method, which takes a function and removes it from its handlers 9 | // it has an .emit() method, which takes an arbitrary number of arguments and calls all the stored functions with these arguments 10 | // As this is an elementary example of events, there are some simplifications: 11 | 12 | // all functions are called with correct arguments (e.g. only functions will be passed to unsubscribe) 13 | // you should not worry about the order of handlers' execution 14 | // the handlers will not attempt to modify an event object (e.g. add or remove handlers) 15 | // the context of handlers' execution is not important 16 | // each handler will be subscribed at most once at any given moment of time. It can still be unsubscribed and then subscribed again 17 | // Also see an example test fixture for suggested usage 18 | 19 | // FUNDAMENTALS, DESIGN PATTERNS, DESIGN PRINCIPLES, EVENT HANDLING, PUBSUB 20 | 21 | function Event() { 22 | //your implementation goes here 23 | this.handler = []; 24 | } 25 | 26 | // subscribe method takes a function and stores it as its handler 27 | Event.prototype.subscribe = function(inputFunc) { 28 | this.handler.push(inputFunc); 29 | // console.log(`subscribed`); 30 | }; 31 | 32 | // unsubscribe method takes a f and removes it from its handlers 33 | Event.prototype.unsubscribe = function(inputFunc) { 34 | let beforeRemoval; 35 | let afterRemoval; 36 | 37 | for (let i = 0; i < this.handler.length; i++) { 38 | console.log(this.handler) 39 | if (this.handler[i] === inputFunc) { 40 | beforeRemoval = this.handler.slice(0, i); 41 | afterRemoval = this.handler.slice(i + 1, this.handler.length - 1); 42 | this.handler = beforeRemoval.concat(afterRemoval); 43 | } 44 | } 45 | // console.log('unsubbed') 46 | }; 47 | 48 | // emit method takes an arbitrary num of args and calls all the stored funcs with those args 49 | Event.prototype.emit = function (...args) { 50 | for (let i = 0; i < this.handler.length; i++) { 51 | this.handler[0](...args) 52 | } 53 | } 54 | 55 | 56 | 57 | var event = new Event(); 58 | 59 | function f() { 60 | f.calls = (f.calls || 0) + 1; 61 | f.args = Array.prototype.slice.call(arguments); 62 | } 63 | 64 | event.subscribe(f); 65 | console.log(event.emit(1, 'foo', true)); 66 | // event.emit(1, 'foo', true); 67 | 68 | console.log(f.calls === 1); // calls a handler 69 | console.log(f.args); 70 | // Test.assertSimilar(f.args, [1, 'foo', true]); // passes arguments 71 | 72 | event.unsubscribe(f); 73 | // event.emit(2); 74 | console.log(event.emit(2)); 75 | 76 | console.log(f.calls === 1); //no second call -------------------------------------------------------------------------------- /codewars-Sum-of-Pairs/index.js: -------------------------------------------------------------------------------- 1 | // Sum of Pairs 2 | // Given a list of integers and a single sum value, return the first two values (parse from the left please) in order of appearance that add up to form the sum. 3 | 4 | // sum_pairs([11, 3, 7, 5], 10) 5 | // # ^--^ 3 + 7 = 10 6 | // == [3, 7] 7 | 8 | // sum_pairs([4, 3, 2, 3, 4], 6) 9 | // # ^-----^ 4 + 2 = 6, indices: 0, 2 * 10 | // # ^-----^ 3 + 3 = 6, indices: 1, 3 11 | // # ^-----^ 2 + 4 = 6, indices: 2, 4 12 | // # * entire pair is earlier, and therefore is the correct answer 13 | // == [4, 2] 14 | 15 | // sum_pairs([0, 0, -2, 3], 2) 16 | // # there are no pairs of values that can be added to produce 2. 17 | // == None/nil/undefined (Based on the language) 18 | 19 | // sum_pairs([10, 5, 2, 3, 7, 5], 10) 20 | // # ^-----------^ 5 + 5 = 10, indices: 1, 5 21 | // # ^--^ 3 + 7 = 10, indices: 3, 4 * 22 | // # * entire pair is earlier, and therefore is the correct answer 23 | // == [3, 7] 24 | 25 | // Negative numbers and duplicate numbers can and will appear. 26 | 27 | // NOTE: There will also be lists tested of lengths upwards of 10,000,000 elements. Be sure your code doesn't time out. 28 | 29 | const sum_pairs = (arr, target) => { 30 | // this will check to see if a sum found later is at an earlier index than the pair already found 31 | let indexCheck = [, ]; 32 | // answerValues is initiated as undefined because if no match is found, undefined is returned 33 | let answerValues; 34 | startAtBeginningLoop: for (let i = 0, len = arr.length; i < len; i++) { 35 | // j is set to i + 1 so that i and j are never the same value 36 | oneStepAheadLoop: for (let j = i + 1; j < len + 1; j++) { 37 | // if a target match is found 38 | if (arr[i] + arr[j] === target) { 39 | // if a target match is found and either index value is at a lower index than the match already saved, set answerValues to the new pair and set indexCheck also to the new pair of indices 40 | if (i < indexCheck[0] || j < indexCheck[1]) { 41 | indexCheck[0] = i; 42 | indexCheck[1] = j; 43 | answerValues[0] = arr[i]; 44 | answerValues[1] = arr[j]; 45 | // this is what happens the first time a target match is found, indexCheck has both its values left undefined to start 46 | } else if (indexCheck[0] === undefined) { 47 | answerValues = [,]; 48 | answerValues[0] = arr[i]; 49 | answerValues[1] = arr[j]; 50 | indexCheck[0] = i; 51 | indexCheck[1] = j; 52 | } 53 | } 54 | } 55 | } 56 | return answerValues; 57 | } 58 | 59 | // Tests 60 | const l1 = [1, 4, 8, 7, 3, 15]; 61 | const l2 = [1, -2, 3, 0, -6, 1]; 62 | const l3 = [20, -13, 40]; 63 | const l4 = [1, 2, 3, 4, 1, 0]; 64 | const l5 = [10, 5, 2, 3, 7, 5]; 65 | const l6 = [4, -2, 3, 3, 4]; 66 | const l7 = [0, 2, 0]; 67 | const l8 = [5, 9, 13, -3]; 68 | 69 | console.log(sum_pairs(l1, 8)); // [1, 7] 70 | console.log(sum_pairs(l2, -6)); // [0, -6] 71 | console.log(sum_pairs(l3, -7)); // undefined 72 | console.log(sum_pairs(l4, 2)); // [1, 1] 73 | console.log(sum_pairs([10, 5, 2, 3, 7, 5], 10)); // [3, 7] 74 | console.log(sum_pairs([4, -2, 3, 3, 4], 8)); // [4, 4] 75 | console.log(sum_pairs(l7, 0)); // [0, 0] 76 | console.log(sum_pairs(l8, 10)); // [13, -3] 77 | 78 | // console.log(sum_pairs(l1, 8)); // [1, 7] Basic: ["+l1+"] should return [1, 7] for sum = 8"); 79 | // console.log(sum_pairs(l2, -6)); // [0, -6] Negatives: ["+l2+"] should return [0, -6] for sum = -6"); 80 | // console.log(sum_pairs(l3, -7)); // undefined No Match: ["+l3+"] should return undefined for sum = -7"); 81 | // console.log(sum_pairs(l4, 2)); // [1, 1] First Match From Left: ["+l4+"] should return [1, 1] for sum = 2 "); 82 | // console.log(sum_pairs(l5, 10)); // [3, 7] First Match From Left REDUX!: ["+l5+"] should return [3, 7] for sum = 10 "); 83 | // console.log(sum_pairs(l6, 8)); // [4, 4] Duplicates: ["+l6+"] should return [4, 4] for sum = 8"); 84 | // console.log(sum_pairs(l7, 0)); // [0, 0] Zeroes: ["+l7+"] should return [0, 0] for sum = 0"); 85 | // console.log(sum_pairs(l8, 10)); // [13, -3] Subtraction: ["+l8+"] should return [13, -3] for sum = 10"); -------------------------------------------------------------------------------- /codewars-Sum-of-odd-numbers/index.js: -------------------------------------------------------------------------------- 1 | // Sum of odd numbers 2 | // Given the triangle of consecutive odd numbers: 3 | // 1 4 | // 3 5 5 | // 7 9 11 6 | // 13 15 17 19 7 | // 21 23 25 27 29 8 | // ... 9 | 10 | // Calculate the row sums of this triangle from the row index (starting at index 1) e.g.: 11 | // rowSumOddNumbers(1); // 1 12 | // rowSumOddNumbers(2); // 3 + 5 = 8 13 | 14 | // function rowSumOddNumbers(num, memo) { 15 | // // TODO 16 | 17 | // } 18 | 19 | //triangleObj[2]: [3, 5,] 20 | 21 | // console.log(rowSumOddNumbers(1)); // 1 22 | // console.log(rowSumOddNumbers(2)); // 3 + 5 = 8 23 | // console.log(rowSumOddNumbers(42)); // 74088 24 | 25 | 26 | // const howManyOddNums = (num) => { 27 | // let oddNums = 0; 28 | // for (let i = 1; i <= num; i++) { 29 | // oddNums += i; 30 | // } 31 | // return oddNums; 32 | // } 33 | 34 | // const oddArrayMaker = (num) => { 35 | // const oddArray = []; 36 | // for (let i = 0; i < num; i++) { 37 | // if (i % 2 === 1) oddArray.push(i); 38 | // } 39 | // console.log(oddArray); 40 | // return oddArray; 41 | // } 42 | 43 | function rowSumOddNumbers(num) { 44 | // TODO 45 | let oddNums = 0; 46 | for (let i = 0; i <= num; i++) { 47 | oddNums += i; 48 | } 49 | //oddNums is the array length I want and I want to fill that array with odd numbers only 50 | 51 | const oddArray = []; 52 | // i-odd stops getting pushed when oddArray is full of the required number of odd 53 | for (let i = 0; oddArray.length < oddNums; i++) { 54 | if (i % 2 === 1) oddArray.push(i); 55 | } 56 | 57 | // to be minused from oddArray to make into newArray 58 | // I only want the values from the num-row, not all the nums before it 59 | let minus = 0; 60 | for (let i = 0; i <= num - 1; i++) { 61 | minus += i; 62 | } 63 | 64 | return oddArray.slice(minus).reduce((runningTotal, currVal) => runningTotal += currVal, 0); 65 | } 66 | 67 | console.log(rowSumOddNumbers(1)); // 1 68 | console.log(rowSumOddNumbers(2)); // 3 + 5 = 8 69 | console.log(rowSumOddNumbers(3)); // 7 + 9 + 11 = 27 70 | console.log(rowSumOddNumbers(4)); // 13 + 15 + 17 + 19 = 64 71 | console.log(rowSumOddNumbers(5)); // 125 72 | console.log(rowSumOddNumbers(42)); // 74088 73 | 74 | //// keep only the NUM items of the end of the array for summing 75 | 76 | // console.log(oddArrayMaker(howManyOddNums(2))); // 77 | // console.log(oddArrayMaker(howManyOddNums(3))); // 78 | // console.log(oddArrayMaker(howManyOddNums(4))); // 79 | // console.log(oddArrayMaker(howManyOddNums(5))); // 80 | 81 | // console.log(howManyOddNums(2)); // 3 82 | // console.log(howManyOddNums(3)); // 6 83 | // console.log(howManyOddNums(4)); // 10 84 | // console.log(howManyOddNums(5)); // 15 85 | 86 | // Given the triangle of consecutive odd numbers: 87 | // 1 88 | // 3 5 89 | // 7 9 11 90 | // 13 15 17 19 91 | // 21 23 25 27 29 92 | // ... 93 | 94 | const sumNum = (num) => { 95 | let answer = 0; 96 | for (let i = 0; i < num; i++) { 97 | answer += i; 98 | } 99 | return answer; 100 | } 101 | 102 | console.log(sumNum(4)); -------------------------------------------------------------------------------- /codewars-Sum-of-odd-numbers/report.20200826.184054.39572.0.001.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "header": { 4 | "reportVersion": 2, 5 | "event": "Allocation failed - JavaScript heap out of memory", 6 | "trigger": "FatalError", 7 | "filename": "report.20200826.184054.39572.0.001.json", 8 | "dumpEventTime": "2020-08-26T18:40:54Z", 9 | "dumpEventTimeStamp": "1598481654942", 10 | "processId": 39572, 11 | "threadId": null, 12 | "cwd": "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers", 13 | "commandLine": [ 14 | "/usr/local/bin/node", 15 | "-r", 16 | "/Users/miguelmanalo/.vscode/extensions/wallabyjs.quokka-vscode-1.0.315/dist/wallaby/node_modules/esm", 17 | "/Users/miguelmanalo/.vscode/extensions/wallabyjs.quokka-vscode-1.0.315/dist/wallaby/server.js", 18 | "runner", 19 | "0", 20 | "50731", 21 | "quokka@1.0.0", 22 | "", 23 | "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers/node_modules", 24 | "quokka_fake_path/original", 25 | "", 26 | "" 27 | ], 28 | "nodejsVersion": "v12.16.3", 29 | "wordSize": 64, 30 | "arch": "x64", 31 | "platform": "darwin", 32 | "componentVersions": { 33 | "node": "12.16.3", 34 | "v8": "7.8.279.23-node.35", 35 | "uv": "1.34.2", 36 | "zlib": "1.2.11", 37 | "brotli": "1.0.7", 38 | "ares": "1.16.0", 39 | "modules": "72", 40 | "nghttp2": "1.40.0", 41 | "napi": "5", 42 | "llhttp": "2.0.4", 43 | "http_parser": "2.9.3", 44 | "openssl": "1.1.1g", 45 | "cldr": "36.0", 46 | "icu": "65.1", 47 | "tz": "2019c", 48 | "unicode": "12.1" 49 | }, 50 | "release": { 51 | "name": "node", 52 | "lts": "Erbium", 53 | "headersUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3-headers.tar.gz", 54 | "sourceUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3.tar.gz" 55 | }, 56 | "osName": "Darwin", 57 | "osRelease": "19.6.0", 58 | "osVersion": "Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64", 59 | "osMachine": "x86_64", 60 | "cpus": [ 61 | { 62 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 63 | "speed": 2900, 64 | "user": 57685520, 65 | "nice": 0, 66 | "sys": 52612460, 67 | "idle": 300371500, 68 | "irq": 0 69 | }, 70 | { 71 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 72 | "speed": 2900, 73 | "user": 22714840, 74 | "nice": 0, 75 | "sys": 13245710, 76 | "idle": 374706740, 77 | "irq": 0 78 | }, 79 | { 80 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 81 | "speed": 2900, 82 | "user": 63513580, 83 | "nice": 0, 84 | "sys": 31504590, 85 | "idle": 315649130, 86 | "irq": 0 87 | }, 88 | { 89 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 90 | "speed": 2900, 91 | "user": 19711850, 92 | "nice": 0, 93 | "sys": 10774840, 94 | "idle": 380180600, 95 | "irq": 0 96 | } 97 | ], 98 | "networkInterfaces": [ 99 | { 100 | "name": "lo0", 101 | "internal": true, 102 | "mac": "00:00:00:00:00:00", 103 | "address": "127.0.0.1", 104 | "netmask": "255.0.0.0", 105 | "family": "IPv4" 106 | }, 107 | { 108 | "name": "lo0", 109 | "internal": true, 110 | "mac": "00:00:00:00:00:00", 111 | "address": "::1", 112 | "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 113 | "family": "IPv6", 114 | "scopeid": 0 115 | }, 116 | { 117 | "name": "lo0", 118 | "internal": true, 119 | "mac": "00:00:00:00:00:00", 120 | "address": "fe80::1", 121 | "netmask": "ffff:ffff:ffff:ffff::", 122 | "family": "IPv6", 123 | "scopeid": 1 124 | }, 125 | { 126 | "name": "en5", 127 | "internal": false, 128 | "mac": "ac:de:48:00:11:22", 129 | "address": "fe80::aede:48ff:fe00:1122", 130 | "netmask": "ffff:ffff:ffff:ffff::", 131 | "family": "IPv6", 132 | "scopeid": 4 133 | }, 134 | { 135 | "name": "en0", 136 | "internal": false, 137 | "mac": "78:4f:43:75:7c:ce", 138 | "address": "fe80::4d7:7119:e845:dc1e", 139 | "netmask": "ffff:ffff:ffff:ffff::", 140 | "family": "IPv6", 141 | "scopeid": 5 142 | }, 143 | { 144 | "name": "en0", 145 | "internal": false, 146 | "mac": "78:4f:43:75:7c:ce", 147 | "address": "192.168.0.102", 148 | "netmask": "255.255.255.0", 149 | "family": "IPv4" 150 | }, 151 | { 152 | "name": "awdl0", 153 | "internal": false, 154 | "mac": "9e:d8:38:5c:9e:51", 155 | "address": "fe80::9cd8:38ff:fe5c:9e51", 156 | "netmask": "ffff:ffff:ffff:ffff::", 157 | "family": "IPv6", 158 | "scopeid": 12 159 | }, 160 | { 161 | "name": "llw0", 162 | "internal": false, 163 | "mac": "9e:d8:38:5c:9e:51", 164 | "address": "fe80::9cd8:38ff:fe5c:9e51", 165 | "netmask": "ffff:ffff:ffff:ffff::", 166 | "family": "IPv6", 167 | "scopeid": 13 168 | }, 169 | { 170 | "name": "utun0", 171 | "internal": false, 172 | "mac": "00:00:00:00:00:00", 173 | "address": "fe80::c3f7:5ecd:9768:67a7", 174 | "netmask": "ffff:ffff:ffff:ffff::", 175 | "family": "IPv6", 176 | "scopeid": 14 177 | }, 178 | { 179 | "name": "utun1", 180 | "internal": false, 181 | "mac": "00:00:00:00:00:00", 182 | "address": "fe80::3774:4216:a75:284e", 183 | "netmask": "ffff:ffff:ffff:ffff::", 184 | "family": "IPv6", 185 | "scopeid": 15 186 | }, 187 | { 188 | "name": "utun2", 189 | "internal": false, 190 | "mac": "00:00:00:00:00:00", 191 | "address": "fe80::c735:f07d:4d22:6fe1", 192 | "netmask": "ffff:ffff:ffff:ffff::", 193 | "family": "IPv6", 194 | "scopeid": 16 195 | }, 196 | { 197 | "name": "utun3", 198 | "internal": false, 199 | "mac": "00:00:00:00:00:00", 200 | "address": "fe80::1cb0:f953:fab0:ed", 201 | "netmask": "ffff:ffff:ffff:ffff::", 202 | "family": "IPv6", 203 | "scopeid": 17 204 | }, 205 | { 206 | "name": "utun4", 207 | "internal": false, 208 | "mac": "00:00:00:00:00:00", 209 | "address": "fe80::e7b9:66e3:4340:aa34", 210 | "netmask": "ffff:ffff:ffff:ffff::", 211 | "family": "IPv6", 212 | "scopeid": 18 213 | }, 214 | { 215 | "name": "utun5", 216 | "internal": false, 217 | "mac": "00:00:00:00:00:00", 218 | "address": "fe80::a25f:8cb1:b75b:8a35", 219 | "netmask": "ffff:ffff:ffff:ffff::", 220 | "family": "IPv6", 221 | "scopeid": 19 222 | }, 223 | { 224 | "name": "utun6", 225 | "internal": false, 226 | "mac": "00:00:00:00:00:00", 227 | "address": "10.5.0.2", 228 | "netmask": "255.255.0.0", 229 | "family": "IPv4" 230 | } 231 | ], 232 | "host": "ComputerYes.local" 233 | }, 234 | "javascriptStack": { 235 | "message": "No stack.", 236 | "stack": [ 237 | "Unavailable." 238 | ] 239 | }, 240 | "nativeStack": [ 241 | { 242 | "pc": "0x00000001001643e7", 243 | "symbol": "report::TriggerNodeReport(v8::Isolate*, node::Environment*, char const*, char const*, std::__1::basic_string, std::__1::allocator > const&, v8::Local) [/usr/local/bin/node]" 244 | }, 245 | { 246 | "pc": "0x0000000100086438", 247 | "symbol": "node::OnFatalError(char const*, char const*) [/usr/local/bin/node]" 248 | }, 249 | { 250 | "pc": "0x0000000100187727", 251 | "symbol": "v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]" 252 | }, 253 | { 254 | "pc": "0x00000001001876c7", 255 | "symbol": "v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]" 256 | }, 257 | { 258 | "pc": "0x0000000100312e75", 259 | "symbol": "v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]" 260 | }, 261 | { 262 | "pc": "0x00000001002e7c8a", 263 | "symbol": "v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::RootIndex, int, v8::internal::Object, v8::internal::AllocationType) [/usr/local/bin/node]" 264 | }, 265 | { 266 | "pc": "0x000000010045fed4", 267 | "symbol": "v8::internal::(anonymous namespace)::ElementsAccessorBase >::GrowCapacity(v8::internal::Handle, unsigned int) [/usr/local/bin/node]" 268 | }, 269 | { 270 | "pc": "0x0000000100612d4c", 271 | "symbol": "v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]" 272 | }, 273 | { 274 | "pc": "0x0000000100972e59", 275 | "symbol": "Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]" 276 | }, 277 | { 278 | "pc": "0x000035229472ee94", 279 | "symbol": "" 280 | }, 281 | { 282 | "pc": "0x00000001008f8804", 283 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 284 | }, 285 | { 286 | "pc": "0x00000001008f8804", 287 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 288 | }, 289 | { 290 | "pc": "0x00000001008f8804", 291 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 292 | }, 293 | { 294 | "pc": "0x00000001008f8804", 295 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 296 | }, 297 | { 298 | "pc": "0x0000000100925e55", 299 | "symbol": "Builtins_GeneratorPrototypeNext [/usr/local/bin/node]" 300 | } 301 | ], 302 | "javascriptHeap": { 303 | "totalMemory": 2029797376, 304 | "totalCommittedMemory": 2017569544, 305 | "usedMemory": 1994540536, 306 | "availableMemory": 184777216, 307 | "memoryLimit": 2197815296, 308 | "heapSpaces": { 309 | "read_only_space": { 310 | "memorySize": 262144, 311 | "committedMemory": 33088, 312 | "capacity": 32808, 313 | "used": 32808, 314 | "available": 0 315 | }, 316 | "new_space": { 317 | "memorySize": 33554432, 318 | "committedMemory": 21850832, 319 | "capacity": 16759296, 320 | "used": 0, 321 | "available": 16759296 322 | }, 323 | "old_space": { 324 | "memorySize": 22683648, 325 | "committedMemory": 22476072, 326 | "capacity": 21762856, 327 | "used": 21762856, 328 | "available": 0 329 | }, 330 | "code_space": { 331 | "memorySize": 692224, 332 | "committedMemory": 608352, 333 | "capacity": 393696, 334 | "used": 393696, 335 | "available": 0 336 | }, 337 | "map_space": { 338 | "memorySize": 790528, 339 | "committedMemory": 786800, 340 | "capacity": 605280, 341 | "used": 605280, 342 | "available": 0 343 | }, 344 | "large_object_space": { 345 | "memorySize": 1038983168, 346 | "committedMemory": 1038983168, 347 | "capacity": 1038964872, 348 | "used": 1038964872, 349 | "available": 0 350 | }, 351 | "code_large_object_space": { 352 | "memorySize": 49152, 353 | "committedMemory": 49152, 354 | "capacity": 2784, 355 | "used": 2784, 356 | "available": 0 357 | }, 358 | "new_large_object_space": { 359 | "memorySize": 932782080, 360 | "committedMemory": 932782080, 361 | "capacity": 932778240, 362 | "used": 932778240, 363 | "available": 0 364 | } 365 | } 366 | }, 367 | "resourceUsage": { 368 | "userCpuSeconds": 5.98089, 369 | "kernelCpuSeconds": 1.19182, 370 | "cpuConsumptionPercent": 71.727, 371 | "maxRss": 2093880442880, 372 | "pageFaults": { 373 | "IORequired": 35, 374 | "IONotRequired": 704068 375 | }, 376 | "fsActivity": { 377 | "reads": 0, 378 | "writes": 0 379 | } 380 | }, 381 | "libuv": [ 382 | ], 383 | "workers": [ 384 | ], 385 | "environmentVariables": { 386 | "USER": "miguelmanalo", 387 | "DISPLAY": "/private/tmp/com.apple.launchd.RBsXwlIBbO/org.macosforge.xquartz:0", 388 | "LOGNAME": "miguelmanalo", 389 | "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/bin:/usr/bin", 390 | "SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.lH8EY2rzsS/Listeners", 391 | "HOME": "/Users/miguelmanalo", 392 | "SHELL": "/bin/bash", 393 | "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0", 394 | "TMPDIR": "/var/folders/2n/67dnz7mj0bn7m6b8d8jgfrtc0000gn/T/", 395 | "XPC_SERVICE_NAME": "com.microsoft.VSCode.20436", 396 | "XPC_FLAGS": "0x0", 397 | "ORIGINAL_XDG_CURRENT_DESKTOP": "undefined", 398 | "VSCODE_NLS_CONFIG": "{\"locale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}", 399 | "VSCODE_NODE_CACHED_DATA_DIR": "/Users/miguelmanalo/Library/Application Support/Code/CachedData/3dd905126b34dcd4de81fa624eb3a8cbe7485f13", 400 | "VSCODE_LOGS": "/Users/miguelmanalo/Library/Application Support/Code/logs/20200822T120024", 401 | "VSCODE_IPC_HOOK": "/Users/miguelmanalo/Library/Application Support/Code/1.48.1-main.sock", 402 | "VSCODE_PID": "40256", 403 | "COMMAND_MODE": "unix2003", 404 | "PWD": "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers", 405 | "LOCAL_GIT_DIRECTORY": "/Applications/GitHub Desktop.app/Contents/Resources/app/git", 406 | "SHLVL": "1", 407 | "_": "/Applications/Visual Studio Code.app/Contents/MacOS/Electron", 408 | "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": "true", 409 | "VSCODE_CLI": "1", 410 | "ELECTRON_NO_ATTACH_CONSOLE": "1", 411 | "AMD_ENTRYPOINT": "vs/workbench/services/extensions/node/extensionHostProcess", 412 | "PIPE_LOGGING": "true", 413 | "VERBOSE_LOGGING": "true", 414 | "VSCODE_IPC_HOOK_EXTHOST": "/var/folders/2n/67dnz7mj0bn7m6b8d8jgfrtc0000gn/T/vscode-ipc-ef77b617-3e4f-45b3-8bf3-00ffa05eabc4.sock", 415 | "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true", 416 | "VSCODE_LOG_STACK": "false", 417 | "WALLABY_PRODUCTION": "true", 418 | "WALLABY_USE_WSL": "false", 419 | "DEBUG": "wallaby:.*", 420 | "DEBUG_COLORS": "no", 421 | "quokka": "{\"globalConfigFile\":\"/Users/miguelmanalo/.quokka/config.json\",\"tempDir\":\"/Users/miguelmanalo/.quokka/data/fj7oz\",\"autoDetect\":true,\"pro\":false,\"builtInPlugins\":[],\"stdEsm\":true}", 422 | "undefined": "", 423 | "ESM_OPTIONS": "{\"await\":true}", 424 | "WALLABY_ENV": "true" 425 | }, 426 | "userLimits": { 427 | "core_file_size_blocks": { 428 | "soft": 0, 429 | "hard": "unlimited" 430 | }, 431 | "data_seg_size_kbytes": { 432 | "soft": "unlimited", 433 | "hard": "unlimited" 434 | }, 435 | "file_size_blocks": { 436 | "soft": "unlimited", 437 | "hard": "unlimited" 438 | }, 439 | "max_locked_memory_bytes": { 440 | "soft": "unlimited", 441 | "hard": "unlimited" 442 | }, 443 | "max_memory_size_kbytes": { 444 | "soft": "unlimited", 445 | "hard": "unlimited" 446 | }, 447 | "open_files": { 448 | "soft": 24576, 449 | "hard": "unlimited" 450 | }, 451 | "stack_size_bytes": { 452 | "soft": 8388608, 453 | "hard": 67104768 454 | }, 455 | "cpu_time_seconds": { 456 | "soft": "unlimited", 457 | "hard": "unlimited" 458 | }, 459 | "max_user_processes": { 460 | "soft": 2784, 461 | "hard": 4176 462 | }, 463 | "virtual_memory_kbytes": { 464 | "soft": "unlimited", 465 | "hard": "unlimited" 466 | } 467 | }, 468 | "sharedObjects": [ 469 | "/usr/local/bin/node", 470 | "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation", 471 | "/usr/lib/libSystem.B.dylib", 472 | "/usr/lib/libc++.1.dylib", 473 | "/usr/lib/libobjc.A.dylib", 474 | "/usr/lib/libfakelink.dylib", 475 | "/usr/lib/libDiagnosticMessagesClient.dylib", 476 | "/usr/lib/libicucore.A.dylib", 477 | "/usr/lib/libz.1.dylib", 478 | "/usr/lib/libc++abi.dylib", 479 | "/usr/lib/system/libcache.dylib", 480 | "/usr/lib/system/libcommonCrypto.dylib", 481 | "/usr/lib/system/libcompiler_rt.dylib", 482 | "/usr/lib/system/libcopyfile.dylib", 483 | "/usr/lib/system/libcorecrypto.dylib", 484 | "/usr/lib/system/libdispatch.dylib", 485 | "/usr/lib/system/libdyld.dylib", 486 | "/usr/lib/system/libkeymgr.dylib", 487 | "/usr/lib/system/liblaunch.dylib", 488 | "/usr/lib/system/libmacho.dylib", 489 | "/usr/lib/system/libquarantine.dylib", 490 | "/usr/lib/system/libremovefile.dylib", 491 | "/usr/lib/system/libsystem_asl.dylib", 492 | "/usr/lib/system/libsystem_blocks.dylib", 493 | "/usr/lib/system/libsystem_c.dylib", 494 | "/usr/lib/system/libsystem_configuration.dylib", 495 | "/usr/lib/system/libsystem_coreservices.dylib", 496 | "/usr/lib/system/libsystem_darwin.dylib", 497 | "/usr/lib/system/libsystem_dnssd.dylib", 498 | "/usr/lib/system/libsystem_featureflags.dylib", 499 | "/usr/lib/system/libsystem_info.dylib", 500 | "/usr/lib/system/libsystem_m.dylib", 501 | "/usr/lib/system/libsystem_malloc.dylib", 502 | "/usr/lib/system/libsystem_networkextension.dylib", 503 | "/usr/lib/system/libsystem_notify.dylib", 504 | "/usr/lib/system/libsystem_sandbox.dylib", 505 | "/usr/lib/system/libsystem_secinit.dylib", 506 | "/usr/lib/system/libsystem_kernel.dylib", 507 | "/usr/lib/system/libsystem_platform.dylib", 508 | "/usr/lib/system/libsystem_pthread.dylib", 509 | "/usr/lib/system/libsystem_symptoms.dylib", 510 | "/usr/lib/system/libsystem_trace.dylib", 511 | "/usr/lib/system/libunwind.dylib", 512 | "/usr/lib/system/libxpc.dylib" 513 | ] 514 | } -------------------------------------------------------------------------------- /codewars-Sum-of-odd-numbers/report.20200826.184213.39617.0.001.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "header": { 4 | "reportVersion": 2, 5 | "event": "Allocation failed - JavaScript heap out of memory", 6 | "trigger": "FatalError", 7 | "filename": "report.20200826.184213.39617.0.001.json", 8 | "dumpEventTime": "2020-08-26T18:42:13Z", 9 | "dumpEventTimeStamp": "1598481733884", 10 | "processId": 39617, 11 | "threadId": null, 12 | "cwd": "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers", 13 | "commandLine": [ 14 | "/usr/local/bin/node", 15 | "-r", 16 | "/Users/miguelmanalo/.vscode/extensions/wallabyjs.quokka-vscode-1.0.315/dist/wallaby/node_modules/esm", 17 | "/Users/miguelmanalo/.vscode/extensions/wallabyjs.quokka-vscode-1.0.315/dist/wallaby/server.js", 18 | "runner", 19 | "0", 20 | "50731", 21 | "quokka@1.0.0", 22 | "", 23 | "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers/node_modules", 24 | "quokka_fake_path/original", 25 | "", 26 | "" 27 | ], 28 | "nodejsVersion": "v12.16.3", 29 | "wordSize": 64, 30 | "arch": "x64", 31 | "platform": "darwin", 32 | "componentVersions": { 33 | "node": "12.16.3", 34 | "v8": "7.8.279.23-node.35", 35 | "uv": "1.34.2", 36 | "zlib": "1.2.11", 37 | "brotli": "1.0.7", 38 | "ares": "1.16.0", 39 | "modules": "72", 40 | "nghttp2": "1.40.0", 41 | "napi": "5", 42 | "llhttp": "2.0.4", 43 | "http_parser": "2.9.3", 44 | "openssl": "1.1.1g", 45 | "cldr": "36.0", 46 | "icu": "65.1", 47 | "tz": "2019c", 48 | "unicode": "12.1" 49 | }, 50 | "release": { 51 | "name": "node", 52 | "lts": "Erbium", 53 | "headersUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3-headers.tar.gz", 54 | "sourceUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3.tar.gz" 55 | }, 56 | "osName": "Darwin", 57 | "osRelease": "19.6.0", 58 | "osVersion": "Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64", 59 | "osMachine": "x86_64", 60 | "cpus": [ 61 | { 62 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 63 | "speed": 2900, 64 | "user": 57717410, 65 | "nice": 0, 66 | "sys": 52628580, 67 | "idle": 300402440, 68 | "irq": 0 69 | }, 70 | { 71 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 72 | "speed": 2900, 73 | "user": 22723170, 74 | "nice": 0, 75 | "sys": 13250690, 76 | "idle": 374772380, 77 | "irq": 0 78 | }, 79 | { 80 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 81 | "speed": 2900, 82 | "user": 63546850, 83 | "nice": 0, 84 | "sys": 31517180, 85 | "idle": 315682210, 86 | "irq": 0 87 | }, 88 | { 89 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 90 | "speed": 2900, 91 | "user": 19719160, 92 | "nice": 0, 93 | "sys": 10779030, 94 | "idle": 380248030, 95 | "irq": 0 96 | } 97 | ], 98 | "networkInterfaces": [ 99 | { 100 | "name": "lo0", 101 | "internal": true, 102 | "mac": "00:00:00:00:00:00", 103 | "address": "127.0.0.1", 104 | "netmask": "255.0.0.0", 105 | "family": "IPv4" 106 | }, 107 | { 108 | "name": "lo0", 109 | "internal": true, 110 | "mac": "00:00:00:00:00:00", 111 | "address": "::1", 112 | "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 113 | "family": "IPv6", 114 | "scopeid": 0 115 | }, 116 | { 117 | "name": "lo0", 118 | "internal": true, 119 | "mac": "00:00:00:00:00:00", 120 | "address": "fe80::1", 121 | "netmask": "ffff:ffff:ffff:ffff::", 122 | "family": "IPv6", 123 | "scopeid": 1 124 | }, 125 | { 126 | "name": "en5", 127 | "internal": false, 128 | "mac": "ac:de:48:00:11:22", 129 | "address": "fe80::aede:48ff:fe00:1122", 130 | "netmask": "ffff:ffff:ffff:ffff::", 131 | "family": "IPv6", 132 | "scopeid": 4 133 | }, 134 | { 135 | "name": "en0", 136 | "internal": false, 137 | "mac": "78:4f:43:75:7c:ce", 138 | "address": "fe80::4d7:7119:e845:dc1e", 139 | "netmask": "ffff:ffff:ffff:ffff::", 140 | "family": "IPv6", 141 | "scopeid": 5 142 | }, 143 | { 144 | "name": "en0", 145 | "internal": false, 146 | "mac": "78:4f:43:75:7c:ce", 147 | "address": "192.168.0.102", 148 | "netmask": "255.255.255.0", 149 | "family": "IPv4" 150 | }, 151 | { 152 | "name": "awdl0", 153 | "internal": false, 154 | "mac": "9e:d8:38:5c:9e:51", 155 | "address": "fe80::9cd8:38ff:fe5c:9e51", 156 | "netmask": "ffff:ffff:ffff:ffff::", 157 | "family": "IPv6", 158 | "scopeid": 12 159 | }, 160 | { 161 | "name": "llw0", 162 | "internal": false, 163 | "mac": "9e:d8:38:5c:9e:51", 164 | "address": "fe80::9cd8:38ff:fe5c:9e51", 165 | "netmask": "ffff:ffff:ffff:ffff::", 166 | "family": "IPv6", 167 | "scopeid": 13 168 | }, 169 | { 170 | "name": "utun0", 171 | "internal": false, 172 | "mac": "00:00:00:00:00:00", 173 | "address": "fe80::c3f7:5ecd:9768:67a7", 174 | "netmask": "ffff:ffff:ffff:ffff::", 175 | "family": "IPv6", 176 | "scopeid": 14 177 | }, 178 | { 179 | "name": "utun1", 180 | "internal": false, 181 | "mac": "00:00:00:00:00:00", 182 | "address": "fe80::3774:4216:a75:284e", 183 | "netmask": "ffff:ffff:ffff:ffff::", 184 | "family": "IPv6", 185 | "scopeid": 15 186 | }, 187 | { 188 | "name": "utun2", 189 | "internal": false, 190 | "mac": "00:00:00:00:00:00", 191 | "address": "fe80::c735:f07d:4d22:6fe1", 192 | "netmask": "ffff:ffff:ffff:ffff::", 193 | "family": "IPv6", 194 | "scopeid": 16 195 | }, 196 | { 197 | "name": "utun3", 198 | "internal": false, 199 | "mac": "00:00:00:00:00:00", 200 | "address": "fe80::1cb0:f953:fab0:ed", 201 | "netmask": "ffff:ffff:ffff:ffff::", 202 | "family": "IPv6", 203 | "scopeid": 17 204 | }, 205 | { 206 | "name": "utun4", 207 | "internal": false, 208 | "mac": "00:00:00:00:00:00", 209 | "address": "fe80::e7b9:66e3:4340:aa34", 210 | "netmask": "ffff:ffff:ffff:ffff::", 211 | "family": "IPv6", 212 | "scopeid": 18 213 | }, 214 | { 215 | "name": "utun5", 216 | "internal": false, 217 | "mac": "00:00:00:00:00:00", 218 | "address": "fe80::a25f:8cb1:b75b:8a35", 219 | "netmask": "ffff:ffff:ffff:ffff::", 220 | "family": "IPv6", 221 | "scopeid": 19 222 | }, 223 | { 224 | "name": "utun6", 225 | "internal": false, 226 | "mac": "00:00:00:00:00:00", 227 | "address": "10.5.0.2", 228 | "netmask": "255.255.0.0", 229 | "family": "IPv4" 230 | } 231 | ], 232 | "host": "ComputerYes.local" 233 | }, 234 | "javascriptStack": { 235 | "message": "No stack.", 236 | "stack": [ 237 | "Unavailable." 238 | ] 239 | }, 240 | "nativeStack": [ 241 | { 242 | "pc": "0x00000001001643e7", 243 | "symbol": "report::TriggerNodeReport(v8::Isolate*, node::Environment*, char const*, char const*, std::__1::basic_string, std::__1::allocator > const&, v8::Local) [/usr/local/bin/node]" 244 | }, 245 | { 246 | "pc": "0x0000000100086438", 247 | "symbol": "node::OnFatalError(char const*, char const*) [/usr/local/bin/node]" 248 | }, 249 | { 250 | "pc": "0x0000000100187727", 251 | "symbol": "v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]" 252 | }, 253 | { 254 | "pc": "0x00000001001876c7", 255 | "symbol": "v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]" 256 | }, 257 | { 258 | "pc": "0x0000000100312e75", 259 | "symbol": "v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]" 260 | }, 261 | { 262 | "pc": "0x00000001002e7c8a", 263 | "symbol": "v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::RootIndex, int, v8::internal::Object, v8::internal::AllocationType) [/usr/local/bin/node]" 264 | }, 265 | { 266 | "pc": "0x000000010045fed4", 267 | "symbol": "v8::internal::(anonymous namespace)::ElementsAccessorBase >::GrowCapacity(v8::internal::Handle, unsigned int) [/usr/local/bin/node]" 268 | }, 269 | { 270 | "pc": "0x0000000100612d4c", 271 | "symbol": "v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]" 272 | }, 273 | { 274 | "pc": "0x0000000100972e59", 275 | "symbol": "Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]" 276 | }, 277 | { 278 | "pc": "0x000011a1d86fb4f7", 279 | "symbol": "" 280 | }, 281 | { 282 | "pc": "0x00000001008f8804", 283 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 284 | }, 285 | { 286 | "pc": "0x00000001008f8804", 287 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 288 | }, 289 | { 290 | "pc": "0x00000001008f8804", 291 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 292 | }, 293 | { 294 | "pc": "0x00000001008f8804", 295 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 296 | }, 297 | { 298 | "pc": "0x0000000100925e55", 299 | "symbol": "Builtins_GeneratorPrototypeNext [/usr/local/bin/node]" 300 | } 301 | ], 302 | "javascriptHeap": { 303 | "totalMemory": 2029010944, 304 | "totalCommittedMemory": 1994884128, 305 | "usedMemory": 1993848504, 306 | "availableMemory": 185563648, 307 | "memoryLimit": 2197815296, 308 | "heapSpaces": { 309 | "read_only_space": { 310 | "memorySize": 262144, 311 | "committedMemory": 33088, 312 | "capacity": 32808, 313 | "used": 32808, 314 | "available": 0 315 | }, 316 | "new_space": { 317 | "memorySize": 33554432, 318 | "committedMemory": 35840, 319 | "capacity": 16759296, 320 | "used": 0, 321 | "available": 16759296 322 | }, 323 | "old_space": { 324 | "memorySize": 21897216, 325 | "committedMemory": 21792216, 326 | "capacity": 21080840, 327 | "used": 21080840, 328 | "available": 0 329 | }, 330 | "code_space": { 331 | "memorySize": 430080, 332 | "committedMemory": 404064, 333 | "capacity": 374080, 334 | "used": 374080, 335 | "available": 0 336 | }, 337 | "map_space": { 338 | "memorySize": 1052672, 339 | "committedMemory": 804520, 340 | "capacity": 614880, 341 | "used": 614880, 342 | "available": 0 343 | }, 344 | "large_object_space": { 345 | "memorySize": 1038983168, 346 | "committedMemory": 1038983168, 347 | "capacity": 1038964872, 348 | "used": 1038964872, 349 | "available": 0 350 | }, 351 | "code_large_object_space": { 352 | "memorySize": 49152, 353 | "committedMemory": 49152, 354 | "capacity": 2784, 355 | "used": 2784, 356 | "available": 0 357 | }, 358 | "new_large_object_space": { 359 | "memorySize": 932782080, 360 | "committedMemory": 932782080, 361 | "capacity": 932778240, 362 | "used": 932778240, 363 | "available": 0 364 | } 365 | } 366 | }, 367 | "resourceUsage": { 368 | "userCpuSeconds": 11.8938, 369 | "kernelCpuSeconds": 1.28566, 370 | "cpuConsumptionPercent": 21.2572, 371 | "maxRss": 2070606249984, 372 | "pageFaults": { 373 | "IORequired": 0, 374 | "IONotRequired": 705346 375 | }, 376 | "fsActivity": { 377 | "reads": 0, 378 | "writes": 0 379 | } 380 | }, 381 | "libuv": [ 382 | ], 383 | "workers": [ 384 | ], 385 | "environmentVariables": { 386 | "USER": "miguelmanalo", 387 | "DISPLAY": "/private/tmp/com.apple.launchd.RBsXwlIBbO/org.macosforge.xquartz:0", 388 | "LOGNAME": "miguelmanalo", 389 | "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/bin:/usr/bin", 390 | "SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.lH8EY2rzsS/Listeners", 391 | "HOME": "/Users/miguelmanalo", 392 | "SHELL": "/bin/bash", 393 | "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0", 394 | "TMPDIR": "/var/folders/2n/67dnz7mj0bn7m6b8d8jgfrtc0000gn/T/", 395 | "XPC_SERVICE_NAME": "com.microsoft.VSCode.20436", 396 | "XPC_FLAGS": "0x0", 397 | "ORIGINAL_XDG_CURRENT_DESKTOP": "undefined", 398 | "VSCODE_NLS_CONFIG": "{\"locale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}", 399 | "VSCODE_NODE_CACHED_DATA_DIR": "/Users/miguelmanalo/Library/Application Support/Code/CachedData/3dd905126b34dcd4de81fa624eb3a8cbe7485f13", 400 | "VSCODE_LOGS": "/Users/miguelmanalo/Library/Application Support/Code/logs/20200822T120024", 401 | "VSCODE_IPC_HOOK": "/Users/miguelmanalo/Library/Application Support/Code/1.48.1-main.sock", 402 | "VSCODE_PID": "40256", 403 | "COMMAND_MODE": "unix2003", 404 | "PWD": "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers", 405 | "LOCAL_GIT_DIRECTORY": "/Applications/GitHub Desktop.app/Contents/Resources/app/git", 406 | "SHLVL": "1", 407 | "_": "/Applications/Visual Studio Code.app/Contents/MacOS/Electron", 408 | "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": "true", 409 | "VSCODE_CLI": "1", 410 | "ELECTRON_NO_ATTACH_CONSOLE": "1", 411 | "AMD_ENTRYPOINT": "vs/workbench/services/extensions/node/extensionHostProcess", 412 | "PIPE_LOGGING": "true", 413 | "VERBOSE_LOGGING": "true", 414 | "VSCODE_IPC_HOOK_EXTHOST": "/var/folders/2n/67dnz7mj0bn7m6b8d8jgfrtc0000gn/T/vscode-ipc-ef77b617-3e4f-45b3-8bf3-00ffa05eabc4.sock", 415 | "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true", 416 | "VSCODE_LOG_STACK": "false", 417 | "WALLABY_PRODUCTION": "true", 418 | "WALLABY_USE_WSL": "false", 419 | "DEBUG": "wallaby:.*", 420 | "DEBUG_COLORS": "no", 421 | "quokka": "{\"globalConfigFile\":\"/Users/miguelmanalo/.quokka/config.json\",\"tempDir\":\"/Users/miguelmanalo/.quokka/data/fj7oz\",\"autoDetect\":true,\"pro\":false,\"builtInPlugins\":[],\"stdEsm\":true}", 422 | "undefined": "", 423 | "ESM_OPTIONS": "{\"await\":true}", 424 | "WALLABY_ENV": "true" 425 | }, 426 | "userLimits": { 427 | "core_file_size_blocks": { 428 | "soft": 0, 429 | "hard": "unlimited" 430 | }, 431 | "data_seg_size_kbytes": { 432 | "soft": "unlimited", 433 | "hard": "unlimited" 434 | }, 435 | "file_size_blocks": { 436 | "soft": "unlimited", 437 | "hard": "unlimited" 438 | }, 439 | "max_locked_memory_bytes": { 440 | "soft": "unlimited", 441 | "hard": "unlimited" 442 | }, 443 | "max_memory_size_kbytes": { 444 | "soft": "unlimited", 445 | "hard": "unlimited" 446 | }, 447 | "open_files": { 448 | "soft": 24576, 449 | "hard": "unlimited" 450 | }, 451 | "stack_size_bytes": { 452 | "soft": 8388608, 453 | "hard": 67104768 454 | }, 455 | "cpu_time_seconds": { 456 | "soft": "unlimited", 457 | "hard": "unlimited" 458 | }, 459 | "max_user_processes": { 460 | "soft": 2784, 461 | "hard": 4176 462 | }, 463 | "virtual_memory_kbytes": { 464 | "soft": "unlimited", 465 | "hard": "unlimited" 466 | } 467 | }, 468 | "sharedObjects": [ 469 | "/usr/local/bin/node", 470 | "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation", 471 | "/usr/lib/libSystem.B.dylib", 472 | "/usr/lib/libc++.1.dylib", 473 | "/usr/lib/libobjc.A.dylib", 474 | "/usr/lib/libfakelink.dylib", 475 | "/usr/lib/libDiagnosticMessagesClient.dylib", 476 | "/usr/lib/libicucore.A.dylib", 477 | "/usr/lib/libz.1.dylib", 478 | "/usr/lib/libc++abi.dylib", 479 | "/usr/lib/system/libcache.dylib", 480 | "/usr/lib/system/libcommonCrypto.dylib", 481 | "/usr/lib/system/libcompiler_rt.dylib", 482 | "/usr/lib/system/libcopyfile.dylib", 483 | "/usr/lib/system/libcorecrypto.dylib", 484 | "/usr/lib/system/libdispatch.dylib", 485 | "/usr/lib/system/libdyld.dylib", 486 | "/usr/lib/system/libkeymgr.dylib", 487 | "/usr/lib/system/liblaunch.dylib", 488 | "/usr/lib/system/libmacho.dylib", 489 | "/usr/lib/system/libquarantine.dylib", 490 | "/usr/lib/system/libremovefile.dylib", 491 | "/usr/lib/system/libsystem_asl.dylib", 492 | "/usr/lib/system/libsystem_blocks.dylib", 493 | "/usr/lib/system/libsystem_c.dylib", 494 | "/usr/lib/system/libsystem_configuration.dylib", 495 | "/usr/lib/system/libsystem_coreservices.dylib", 496 | "/usr/lib/system/libsystem_darwin.dylib", 497 | "/usr/lib/system/libsystem_dnssd.dylib", 498 | "/usr/lib/system/libsystem_featureflags.dylib", 499 | "/usr/lib/system/libsystem_info.dylib", 500 | "/usr/lib/system/libsystem_m.dylib", 501 | "/usr/lib/system/libsystem_malloc.dylib", 502 | "/usr/lib/system/libsystem_networkextension.dylib", 503 | "/usr/lib/system/libsystem_notify.dylib", 504 | "/usr/lib/system/libsystem_sandbox.dylib", 505 | "/usr/lib/system/libsystem_secinit.dylib", 506 | "/usr/lib/system/libsystem_kernel.dylib", 507 | "/usr/lib/system/libsystem_platform.dylib", 508 | "/usr/lib/system/libsystem_pthread.dylib", 509 | "/usr/lib/system/libsystem_symptoms.dylib", 510 | "/usr/lib/system/libsystem_trace.dylib", 511 | "/usr/lib/system/libunwind.dylib", 512 | "/usr/lib/system/libxpc.dylib" 513 | ] 514 | } -------------------------------------------------------------------------------- /codewars-Sum-of-odd-numbers/report.20200826.184254.39745.0.001.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "header": { 4 | "reportVersion": 2, 5 | "event": "Allocation failed - JavaScript heap out of memory", 6 | "trigger": "FatalError", 7 | "filename": "report.20200826.184254.39745.0.001.json", 8 | "dumpEventTime": "2020-08-26T18:42:54Z", 9 | "dumpEventTimeStamp": "1598481774777", 10 | "processId": 39745, 11 | "threadId": null, 12 | "cwd": "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers", 13 | "commandLine": [ 14 | "/usr/local/bin/node", 15 | "-r", 16 | "/Users/miguelmanalo/.vscode/extensions/wallabyjs.quokka-vscode-1.0.315/dist/wallaby/node_modules/esm", 17 | "/Users/miguelmanalo/.vscode/extensions/wallabyjs.quokka-vscode-1.0.315/dist/wallaby/server.js", 18 | "runner", 19 | "0", 20 | "50731", 21 | "quokka@1.0.0", 22 | "", 23 | "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers/node_modules", 24 | "quokka_fake_path/original", 25 | "", 26 | "" 27 | ], 28 | "nodejsVersion": "v12.16.3", 29 | "wordSize": 64, 30 | "arch": "x64", 31 | "platform": "darwin", 32 | "componentVersions": { 33 | "node": "12.16.3", 34 | "v8": "7.8.279.23-node.35", 35 | "uv": "1.34.2", 36 | "zlib": "1.2.11", 37 | "brotli": "1.0.7", 38 | "ares": "1.16.0", 39 | "modules": "72", 40 | "nghttp2": "1.40.0", 41 | "napi": "5", 42 | "llhttp": "2.0.4", 43 | "http_parser": "2.9.3", 44 | "openssl": "1.1.1g", 45 | "cldr": "36.0", 46 | "icu": "65.1", 47 | "tz": "2019c", 48 | "unicode": "12.1" 49 | }, 50 | "release": { 51 | "name": "node", 52 | "lts": "Erbium", 53 | "headersUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3-headers.tar.gz", 54 | "sourceUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3.tar.gz" 55 | }, 56 | "osName": "Darwin", 57 | "osRelease": "19.6.0", 58 | "osVersion": "Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64", 59 | "osMachine": "x86_64", 60 | "cpus": [ 61 | { 62 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 63 | "speed": 2900, 64 | "user": 57734840, 65 | "nice": 0, 66 | "sys": 52637510, 67 | "idle": 300416970, 68 | "irq": 0 69 | }, 70 | { 71 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 72 | "speed": 2900, 73 | "user": 22727570, 74 | "nice": 0, 75 | "sys": 13253160, 76 | "idle": 374806390, 77 | "irq": 0 78 | }, 79 | { 80 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 81 | "speed": 2900, 82 | "user": 63565270, 83 | "nice": 0, 84 | "sys": 31524200, 85 | "idle": 315697650, 86 | "irq": 0 87 | }, 88 | { 89 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 90 | "speed": 2900, 91 | "user": 19722820, 92 | "nice": 0, 93 | "sys": 10781080, 94 | "idle": 380283230, 95 | "irq": 0 96 | } 97 | ], 98 | "networkInterfaces": [ 99 | { 100 | "name": "lo0", 101 | "internal": true, 102 | "mac": "00:00:00:00:00:00", 103 | "address": "127.0.0.1", 104 | "netmask": "255.0.0.0", 105 | "family": "IPv4" 106 | }, 107 | { 108 | "name": "lo0", 109 | "internal": true, 110 | "mac": "00:00:00:00:00:00", 111 | "address": "::1", 112 | "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 113 | "family": "IPv6", 114 | "scopeid": 0 115 | }, 116 | { 117 | "name": "lo0", 118 | "internal": true, 119 | "mac": "00:00:00:00:00:00", 120 | "address": "fe80::1", 121 | "netmask": "ffff:ffff:ffff:ffff::", 122 | "family": "IPv6", 123 | "scopeid": 1 124 | }, 125 | { 126 | "name": "en5", 127 | "internal": false, 128 | "mac": "ac:de:48:00:11:22", 129 | "address": "fe80::aede:48ff:fe00:1122", 130 | "netmask": "ffff:ffff:ffff:ffff::", 131 | "family": "IPv6", 132 | "scopeid": 4 133 | }, 134 | { 135 | "name": "en0", 136 | "internal": false, 137 | "mac": "78:4f:43:75:7c:ce", 138 | "address": "fe80::4d7:7119:e845:dc1e", 139 | "netmask": "ffff:ffff:ffff:ffff::", 140 | "family": "IPv6", 141 | "scopeid": 5 142 | }, 143 | { 144 | "name": "en0", 145 | "internal": false, 146 | "mac": "78:4f:43:75:7c:ce", 147 | "address": "192.168.0.102", 148 | "netmask": "255.255.255.0", 149 | "family": "IPv4" 150 | }, 151 | { 152 | "name": "awdl0", 153 | "internal": false, 154 | "mac": "9e:d8:38:5c:9e:51", 155 | "address": "fe80::9cd8:38ff:fe5c:9e51", 156 | "netmask": "ffff:ffff:ffff:ffff::", 157 | "family": "IPv6", 158 | "scopeid": 12 159 | }, 160 | { 161 | "name": "llw0", 162 | "internal": false, 163 | "mac": "9e:d8:38:5c:9e:51", 164 | "address": "fe80::9cd8:38ff:fe5c:9e51", 165 | "netmask": "ffff:ffff:ffff:ffff::", 166 | "family": "IPv6", 167 | "scopeid": 13 168 | }, 169 | { 170 | "name": "utun0", 171 | "internal": false, 172 | "mac": "00:00:00:00:00:00", 173 | "address": "fe80::c3f7:5ecd:9768:67a7", 174 | "netmask": "ffff:ffff:ffff:ffff::", 175 | "family": "IPv6", 176 | "scopeid": 14 177 | }, 178 | { 179 | "name": "utun1", 180 | "internal": false, 181 | "mac": "00:00:00:00:00:00", 182 | "address": "fe80::3774:4216:a75:284e", 183 | "netmask": "ffff:ffff:ffff:ffff::", 184 | "family": "IPv6", 185 | "scopeid": 15 186 | }, 187 | { 188 | "name": "utun2", 189 | "internal": false, 190 | "mac": "00:00:00:00:00:00", 191 | "address": "fe80::c735:f07d:4d22:6fe1", 192 | "netmask": "ffff:ffff:ffff:ffff::", 193 | "family": "IPv6", 194 | "scopeid": 16 195 | }, 196 | { 197 | "name": "utun3", 198 | "internal": false, 199 | "mac": "00:00:00:00:00:00", 200 | "address": "fe80::1cb0:f953:fab0:ed", 201 | "netmask": "ffff:ffff:ffff:ffff::", 202 | "family": "IPv6", 203 | "scopeid": 17 204 | }, 205 | { 206 | "name": "utun4", 207 | "internal": false, 208 | "mac": "00:00:00:00:00:00", 209 | "address": "fe80::e7b9:66e3:4340:aa34", 210 | "netmask": "ffff:ffff:ffff:ffff::", 211 | "family": "IPv6", 212 | "scopeid": 18 213 | }, 214 | { 215 | "name": "utun5", 216 | "internal": false, 217 | "mac": "00:00:00:00:00:00", 218 | "address": "fe80::a25f:8cb1:b75b:8a35", 219 | "netmask": "ffff:ffff:ffff:ffff::", 220 | "family": "IPv6", 221 | "scopeid": 19 222 | }, 223 | { 224 | "name": "utun6", 225 | "internal": false, 226 | "mac": "00:00:00:00:00:00", 227 | "address": "10.5.0.2", 228 | "netmask": "255.255.0.0", 229 | "family": "IPv4" 230 | } 231 | ], 232 | "host": "ComputerYes.local" 233 | }, 234 | "javascriptStack": { 235 | "message": "No stack.", 236 | "stack": [ 237 | "Unavailable." 238 | ] 239 | }, 240 | "nativeStack": [ 241 | { 242 | "pc": "0x00000001001643e7", 243 | "symbol": "report::TriggerNodeReport(v8::Isolate*, node::Environment*, char const*, char const*, std::__1::basic_string, std::__1::allocator > const&, v8::Local) [/usr/local/bin/node]" 244 | }, 245 | { 246 | "pc": "0x0000000100086438", 247 | "symbol": "node::OnFatalError(char const*, char const*) [/usr/local/bin/node]" 248 | }, 249 | { 250 | "pc": "0x0000000100187727", 251 | "symbol": "v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]" 252 | }, 253 | { 254 | "pc": "0x00000001001876c7", 255 | "symbol": "v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]" 256 | }, 257 | { 258 | "pc": "0x0000000100312e75", 259 | "symbol": "v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]" 260 | }, 261 | { 262 | "pc": "0x00000001002e7c8a", 263 | "symbol": "v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::RootIndex, int, v8::internal::Object, v8::internal::AllocationType) [/usr/local/bin/node]" 264 | }, 265 | { 266 | "pc": "0x000000010045fed4", 267 | "symbol": "v8::internal::(anonymous namespace)::ElementsAccessorBase >::GrowCapacity(v8::internal::Handle, unsigned int) [/usr/local/bin/node]" 268 | }, 269 | { 270 | "pc": "0x0000000100612d4c", 271 | "symbol": "v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]" 272 | }, 273 | { 274 | "pc": "0x0000000100972e59", 275 | "symbol": "Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]" 276 | }, 277 | { 278 | "pc": "0x00001c24bc46e614", 279 | "symbol": "" 280 | }, 281 | { 282 | "pc": "0x00000001008f8804", 283 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 284 | }, 285 | { 286 | "pc": "0x00000001008f8804", 287 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 288 | }, 289 | { 290 | "pc": "0x00000001008f8804", 291 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 292 | }, 293 | { 294 | "pc": "0x00000001008f8804", 295 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 296 | }, 297 | { 298 | "pc": "0x0000000100925e55", 299 | "symbol": "Builtins_GeneratorPrototypeNext [/usr/local/bin/node]" 300 | } 301 | ], 302 | "javascriptHeap": { 303 | "totalMemory": 2786156544, 304 | "totalCommittedMemory": 2774026976, 305 | "usedMemory": 2750955728, 306 | "availableMemory": 16843184, 307 | "memoryLimit": 2197815296, 308 | "heapSpaces": { 309 | "read_only_space": { 310 | "memorySize": 262144, 311 | "committedMemory": 33088, 312 | "capacity": 32808, 313 | "used": 32808, 314 | "available": 0 315 | }, 316 | "new_space": { 317 | "memorySize": 33554432, 318 | "committedMemory": 21927416, 319 | "capacity": 16759296, 320 | "used": 0, 321 | "available": 16759296 322 | }, 323 | "old_space": { 324 | "memorySize": 22683648, 325 | "committedMemory": 22500824, 326 | "capacity": 21898296, 327 | "used": 21814408, 328 | "available": 83888 329 | }, 330 | "code_space": { 331 | "memorySize": 692224, 332 | "committedMemory": 605280, 333 | "capacity": 413184, 334 | "used": 413184, 335 | "available": 0 336 | }, 337 | "map_space": { 338 | "memorySize": 790528, 339 | "committedMemory": 786800, 340 | "capacity": 605680, 341 | "used": 605680, 342 | "available": 0 343 | }, 344 | "large_object_space": { 345 | "memorySize": 1795342336, 346 | "committedMemory": 1795342336, 347 | "capacity": 1795308624, 348 | "used": 1795308624, 349 | "available": 0 350 | }, 351 | "code_large_object_space": { 352 | "memorySize": 49152, 353 | "committedMemory": 49152, 354 | "capacity": 2784, 355 | "used": 2784, 356 | "available": 0 357 | }, 358 | "new_large_object_space": { 359 | "memorySize": 932782080, 360 | "committedMemory": 932782080, 361 | "capacity": 932778240, 362 | "used": 932778240, 363 | "available": 0 364 | } 365 | } 366 | }, 367 | "resourceUsage": { 368 | "userCpuSeconds": 6.16635, 369 | "kernelCpuSeconds": 1.18043, 370 | "cpuConsumptionPercent": 66.7889, 371 | "maxRss": 2868367065088, 372 | "pageFaults": { 373 | "IORequired": 0, 374 | "IONotRequired": 704163 375 | }, 376 | "fsActivity": { 377 | "reads": 0, 378 | "writes": 0 379 | } 380 | }, 381 | "libuv": [ 382 | ], 383 | "workers": [ 384 | ], 385 | "environmentVariables": { 386 | "USER": "miguelmanalo", 387 | "DISPLAY": "/private/tmp/com.apple.launchd.RBsXwlIBbO/org.macosforge.xquartz:0", 388 | "LOGNAME": "miguelmanalo", 389 | "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/bin:/usr/bin", 390 | "SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.lH8EY2rzsS/Listeners", 391 | "HOME": "/Users/miguelmanalo", 392 | "SHELL": "/bin/bash", 393 | "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0", 394 | "TMPDIR": "/var/folders/2n/67dnz7mj0bn7m6b8d8jgfrtc0000gn/T/", 395 | "XPC_SERVICE_NAME": "com.microsoft.VSCode.20436", 396 | "XPC_FLAGS": "0x0", 397 | "ORIGINAL_XDG_CURRENT_DESKTOP": "undefined", 398 | "VSCODE_NLS_CONFIG": "{\"locale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}", 399 | "VSCODE_NODE_CACHED_DATA_DIR": "/Users/miguelmanalo/Library/Application Support/Code/CachedData/3dd905126b34dcd4de81fa624eb3a8cbe7485f13", 400 | "VSCODE_LOGS": "/Users/miguelmanalo/Library/Application Support/Code/logs/20200822T120024", 401 | "VSCODE_IPC_HOOK": "/Users/miguelmanalo/Library/Application Support/Code/1.48.1-main.sock", 402 | "VSCODE_PID": "40256", 403 | "COMMAND_MODE": "unix2003", 404 | "PWD": "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers", 405 | "LOCAL_GIT_DIRECTORY": "/Applications/GitHub Desktop.app/Contents/Resources/app/git", 406 | "SHLVL": "1", 407 | "_": "/Applications/Visual Studio Code.app/Contents/MacOS/Electron", 408 | "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": "true", 409 | "VSCODE_CLI": "1", 410 | "ELECTRON_NO_ATTACH_CONSOLE": "1", 411 | "AMD_ENTRYPOINT": "vs/workbench/services/extensions/node/extensionHostProcess", 412 | "PIPE_LOGGING": "true", 413 | "VERBOSE_LOGGING": "true", 414 | "VSCODE_IPC_HOOK_EXTHOST": "/var/folders/2n/67dnz7mj0bn7m6b8d8jgfrtc0000gn/T/vscode-ipc-ef77b617-3e4f-45b3-8bf3-00ffa05eabc4.sock", 415 | "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true", 416 | "VSCODE_LOG_STACK": "false", 417 | "WALLABY_PRODUCTION": "true", 418 | "WALLABY_USE_WSL": "false", 419 | "DEBUG": "wallaby:.*", 420 | "DEBUG_COLORS": "no", 421 | "quokka": "{\"globalConfigFile\":\"/Users/miguelmanalo/.quokka/config.json\",\"tempDir\":\"/Users/miguelmanalo/.quokka/data/fj7oz\",\"autoDetect\":true,\"pro\":false,\"builtInPlugins\":[],\"stdEsm\":true}", 422 | "undefined": "", 423 | "ESM_OPTIONS": "{\"await\":true}", 424 | "WALLABY_ENV": "true" 425 | }, 426 | "userLimits": { 427 | "core_file_size_blocks": { 428 | "soft": 0, 429 | "hard": "unlimited" 430 | }, 431 | "data_seg_size_kbytes": { 432 | "soft": "unlimited", 433 | "hard": "unlimited" 434 | }, 435 | "file_size_blocks": { 436 | "soft": "unlimited", 437 | "hard": "unlimited" 438 | }, 439 | "max_locked_memory_bytes": { 440 | "soft": "unlimited", 441 | "hard": "unlimited" 442 | }, 443 | "max_memory_size_kbytes": { 444 | "soft": "unlimited", 445 | "hard": "unlimited" 446 | }, 447 | "open_files": { 448 | "soft": 24576, 449 | "hard": "unlimited" 450 | }, 451 | "stack_size_bytes": { 452 | "soft": 8388608, 453 | "hard": 67104768 454 | }, 455 | "cpu_time_seconds": { 456 | "soft": "unlimited", 457 | "hard": "unlimited" 458 | }, 459 | "max_user_processes": { 460 | "soft": 2784, 461 | "hard": 4176 462 | }, 463 | "virtual_memory_kbytes": { 464 | "soft": "unlimited", 465 | "hard": "unlimited" 466 | } 467 | }, 468 | "sharedObjects": [ 469 | "/usr/local/bin/node", 470 | "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation", 471 | "/usr/lib/libSystem.B.dylib", 472 | "/usr/lib/libc++.1.dylib", 473 | "/usr/lib/libobjc.A.dylib", 474 | "/usr/lib/libfakelink.dylib", 475 | "/usr/lib/libDiagnosticMessagesClient.dylib", 476 | "/usr/lib/libicucore.A.dylib", 477 | "/usr/lib/libz.1.dylib", 478 | "/usr/lib/libc++abi.dylib", 479 | "/usr/lib/system/libcache.dylib", 480 | "/usr/lib/system/libcommonCrypto.dylib", 481 | "/usr/lib/system/libcompiler_rt.dylib", 482 | "/usr/lib/system/libcopyfile.dylib", 483 | "/usr/lib/system/libcorecrypto.dylib", 484 | "/usr/lib/system/libdispatch.dylib", 485 | "/usr/lib/system/libdyld.dylib", 486 | "/usr/lib/system/libkeymgr.dylib", 487 | "/usr/lib/system/liblaunch.dylib", 488 | "/usr/lib/system/libmacho.dylib", 489 | "/usr/lib/system/libquarantine.dylib", 490 | "/usr/lib/system/libremovefile.dylib", 491 | "/usr/lib/system/libsystem_asl.dylib", 492 | "/usr/lib/system/libsystem_blocks.dylib", 493 | "/usr/lib/system/libsystem_c.dylib", 494 | "/usr/lib/system/libsystem_configuration.dylib", 495 | "/usr/lib/system/libsystem_coreservices.dylib", 496 | "/usr/lib/system/libsystem_darwin.dylib", 497 | "/usr/lib/system/libsystem_dnssd.dylib", 498 | "/usr/lib/system/libsystem_featureflags.dylib", 499 | "/usr/lib/system/libsystem_info.dylib", 500 | "/usr/lib/system/libsystem_m.dylib", 501 | "/usr/lib/system/libsystem_malloc.dylib", 502 | "/usr/lib/system/libsystem_networkextension.dylib", 503 | "/usr/lib/system/libsystem_notify.dylib", 504 | "/usr/lib/system/libsystem_sandbox.dylib", 505 | "/usr/lib/system/libsystem_secinit.dylib", 506 | "/usr/lib/system/libsystem_kernel.dylib", 507 | "/usr/lib/system/libsystem_platform.dylib", 508 | "/usr/lib/system/libsystem_pthread.dylib", 509 | "/usr/lib/system/libsystem_symptoms.dylib", 510 | "/usr/lib/system/libsystem_trace.dylib", 511 | "/usr/lib/system/libunwind.dylib", 512 | "/usr/lib/system/libxpc.dylib" 513 | ] 514 | } -------------------------------------------------------------------------------- /codewars-Sum-of-odd-numbers/report.20200826.184444.39860.0.001.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "header": { 4 | "reportVersion": 2, 5 | "event": "Allocation failed - JavaScript heap out of memory", 6 | "trigger": "FatalError", 7 | "filename": "report.20200826.184444.39860.0.001.json", 8 | "dumpEventTime": "2020-08-26T18:44:44Z", 9 | "dumpEventTimeStamp": "1598481884416", 10 | "processId": 39860, 11 | "threadId": null, 12 | "cwd": "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers", 13 | "commandLine": [ 14 | "/usr/local/bin/node", 15 | "-r", 16 | "/Users/miguelmanalo/.vscode/extensions/wallabyjs.quokka-vscode-1.0.315/dist/wallaby/node_modules/esm", 17 | "/Users/miguelmanalo/.vscode/extensions/wallabyjs.quokka-vscode-1.0.315/dist/wallaby/server.js", 18 | "runner", 19 | "0", 20 | "50731", 21 | "quokka@1.0.0", 22 | "", 23 | "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers/node_modules", 24 | "quokka_fake_path/original", 25 | "", 26 | "" 27 | ], 28 | "nodejsVersion": "v12.16.3", 29 | "wordSize": 64, 30 | "arch": "x64", 31 | "platform": "darwin", 32 | "componentVersions": { 33 | "node": "12.16.3", 34 | "v8": "7.8.279.23-node.35", 35 | "uv": "1.34.2", 36 | "zlib": "1.2.11", 37 | "brotli": "1.0.7", 38 | "ares": "1.16.0", 39 | "modules": "72", 40 | "nghttp2": "1.40.0", 41 | "napi": "5", 42 | "llhttp": "2.0.4", 43 | "http_parser": "2.9.3", 44 | "openssl": "1.1.1g", 45 | "cldr": "36.0", 46 | "icu": "65.1", 47 | "tz": "2019c", 48 | "unicode": "12.1" 49 | }, 50 | "release": { 51 | "name": "node", 52 | "lts": "Erbium", 53 | "headersUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3-headers.tar.gz", 54 | "sourceUrl": "https://nodejs.org/download/release/v12.16.3/node-v12.16.3.tar.gz" 55 | }, 56 | "osName": "Darwin", 57 | "osRelease": "19.6.0", 58 | "osVersion": "Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64", 59 | "osMachine": "x86_64", 60 | "cpus": [ 61 | { 62 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 63 | "speed": 2900, 64 | "user": 57783020, 65 | "nice": 0, 66 | "sys": 52658110, 67 | "idle": 300457830, 68 | "irq": 0 69 | }, 70 | { 71 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 72 | "speed": 2900, 73 | "user": 22738160, 74 | "nice": 0, 75 | "sys": 13258970, 76 | "idle": 374899640, 77 | "irq": 0 78 | }, 79 | { 80 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 81 | "speed": 2900, 82 | "user": 63615590, 83 | "nice": 0, 84 | "sys": 31540250, 85 | "idle": 315740920, 86 | "irq": 0 87 | }, 88 | { 89 | "model": "Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz", 90 | "speed": 2900, 91 | "user": 19731460, 92 | "nice": 0, 93 | "sys": 10785960, 94 | "idle": 380379340, 95 | "irq": 0 96 | } 97 | ], 98 | "networkInterfaces": [ 99 | { 100 | "name": "lo0", 101 | "internal": true, 102 | "mac": "00:00:00:00:00:00", 103 | "address": "127.0.0.1", 104 | "netmask": "255.0.0.0", 105 | "family": "IPv4" 106 | }, 107 | { 108 | "name": "lo0", 109 | "internal": true, 110 | "mac": "00:00:00:00:00:00", 111 | "address": "::1", 112 | "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 113 | "family": "IPv6", 114 | "scopeid": 0 115 | }, 116 | { 117 | "name": "lo0", 118 | "internal": true, 119 | "mac": "00:00:00:00:00:00", 120 | "address": "fe80::1", 121 | "netmask": "ffff:ffff:ffff:ffff::", 122 | "family": "IPv6", 123 | "scopeid": 1 124 | }, 125 | { 126 | "name": "en5", 127 | "internal": false, 128 | "mac": "ac:de:48:00:11:22", 129 | "address": "fe80::aede:48ff:fe00:1122", 130 | "netmask": "ffff:ffff:ffff:ffff::", 131 | "family": "IPv6", 132 | "scopeid": 4 133 | }, 134 | { 135 | "name": "en0", 136 | "internal": false, 137 | "mac": "78:4f:43:75:7c:ce", 138 | "address": "fe80::4d7:7119:e845:dc1e", 139 | "netmask": "ffff:ffff:ffff:ffff::", 140 | "family": "IPv6", 141 | "scopeid": 5 142 | }, 143 | { 144 | "name": "en0", 145 | "internal": false, 146 | "mac": "78:4f:43:75:7c:ce", 147 | "address": "192.168.0.102", 148 | "netmask": "255.255.255.0", 149 | "family": "IPv4" 150 | }, 151 | { 152 | "name": "awdl0", 153 | "internal": false, 154 | "mac": "9e:d8:38:5c:9e:51", 155 | "address": "fe80::9cd8:38ff:fe5c:9e51", 156 | "netmask": "ffff:ffff:ffff:ffff::", 157 | "family": "IPv6", 158 | "scopeid": 12 159 | }, 160 | { 161 | "name": "llw0", 162 | "internal": false, 163 | "mac": "9e:d8:38:5c:9e:51", 164 | "address": "fe80::9cd8:38ff:fe5c:9e51", 165 | "netmask": "ffff:ffff:ffff:ffff::", 166 | "family": "IPv6", 167 | "scopeid": 13 168 | }, 169 | { 170 | "name": "utun0", 171 | "internal": false, 172 | "mac": "00:00:00:00:00:00", 173 | "address": "fe80::c3f7:5ecd:9768:67a7", 174 | "netmask": "ffff:ffff:ffff:ffff::", 175 | "family": "IPv6", 176 | "scopeid": 14 177 | }, 178 | { 179 | "name": "utun1", 180 | "internal": false, 181 | "mac": "00:00:00:00:00:00", 182 | "address": "fe80::3774:4216:a75:284e", 183 | "netmask": "ffff:ffff:ffff:ffff::", 184 | "family": "IPv6", 185 | "scopeid": 15 186 | }, 187 | { 188 | "name": "utun2", 189 | "internal": false, 190 | "mac": "00:00:00:00:00:00", 191 | "address": "fe80::c735:f07d:4d22:6fe1", 192 | "netmask": "ffff:ffff:ffff:ffff::", 193 | "family": "IPv6", 194 | "scopeid": 16 195 | }, 196 | { 197 | "name": "utun3", 198 | "internal": false, 199 | "mac": "00:00:00:00:00:00", 200 | "address": "fe80::1cb0:f953:fab0:ed", 201 | "netmask": "ffff:ffff:ffff:ffff::", 202 | "family": "IPv6", 203 | "scopeid": 17 204 | }, 205 | { 206 | "name": "utun4", 207 | "internal": false, 208 | "mac": "00:00:00:00:00:00", 209 | "address": "fe80::e7b9:66e3:4340:aa34", 210 | "netmask": "ffff:ffff:ffff:ffff::", 211 | "family": "IPv6", 212 | "scopeid": 18 213 | }, 214 | { 215 | "name": "utun5", 216 | "internal": false, 217 | "mac": "00:00:00:00:00:00", 218 | "address": "fe80::a25f:8cb1:b75b:8a35", 219 | "netmask": "ffff:ffff:ffff:ffff::", 220 | "family": "IPv6", 221 | "scopeid": 19 222 | }, 223 | { 224 | "name": "utun6", 225 | "internal": false, 226 | "mac": "00:00:00:00:00:00", 227 | "address": "10.5.0.2", 228 | "netmask": "255.255.0.0", 229 | "family": "IPv4" 230 | } 231 | ], 232 | "host": "ComputerYes.local" 233 | }, 234 | "javascriptStack": { 235 | "message": "No stack.", 236 | "stack": [ 237 | "Unavailable." 238 | ] 239 | }, 240 | "nativeStack": [ 241 | { 242 | "pc": "0x00000001001643e7", 243 | "symbol": "report::TriggerNodeReport(v8::Isolate*, node::Environment*, char const*, char const*, std::__1::basic_string, std::__1::allocator > const&, v8::Local) [/usr/local/bin/node]" 244 | }, 245 | { 246 | "pc": "0x0000000100086438", 247 | "symbol": "node::OnFatalError(char const*, char const*) [/usr/local/bin/node]" 248 | }, 249 | { 250 | "pc": "0x0000000100187727", 251 | "symbol": "v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]" 252 | }, 253 | { 254 | "pc": "0x00000001001876c7", 255 | "symbol": "v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]" 256 | }, 257 | { 258 | "pc": "0x0000000100312e75", 259 | "symbol": "v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]" 260 | }, 261 | { 262 | "pc": "0x00000001002e7c8a", 263 | "symbol": "v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::RootIndex, int, v8::internal::Object, v8::internal::AllocationType) [/usr/local/bin/node]" 264 | }, 265 | { 266 | "pc": "0x000000010045fed4", 267 | "symbol": "v8::internal::(anonymous namespace)::ElementsAccessorBase >::GrowCapacity(v8::internal::Handle, unsigned int) [/usr/local/bin/node]" 268 | }, 269 | { 270 | "pc": "0x0000000100612d4c", 271 | "symbol": "v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]" 272 | }, 273 | { 274 | "pc": "0x0000000100972e59", 275 | "symbol": "Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]" 276 | }, 277 | { 278 | "pc": "0x00001e36185dbd1e", 279 | "symbol": "" 280 | }, 281 | { 282 | "pc": "0x00000001008f8804", 283 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 284 | }, 285 | { 286 | "pc": "0x00000001008f8804", 287 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 288 | }, 289 | { 290 | "pc": "0x00000001008f8804", 291 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 292 | }, 293 | { 294 | "pc": "0x00000001008f8804", 295 | "symbol": "Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]" 296 | }, 297 | { 298 | "pc": "0x0000000100925e55", 299 | "symbol": "Builtins_GeneratorPrototypeNext [/usr/local/bin/node]" 300 | } 301 | ], 302 | "javascriptHeap": { 303 | "totalMemory": 2029273088, 304 | "totalCommittedMemory": 1995013088, 305 | "usedMemory": 1993792392, 306 | "availableMemory": 185301504, 307 | "memoryLimit": 2197815296, 308 | "heapSpaces": { 309 | "read_only_space": { 310 | "memorySize": 262144, 311 | "committedMemory": 33088, 312 | "capacity": 32808, 313 | "used": 32808, 314 | "available": 0 315 | }, 316 | "new_space": { 317 | "memorySize": 33554432, 318 | "committedMemory": 35840, 319 | "capacity": 16759296, 320 | "used": 0, 321 | "available": 16759296 322 | }, 323 | "old_space": { 324 | "memorySize": 21897216, 325 | "committedMemory": 21765512, 326 | "capacity": 21024216, 327 | "used": 21024216, 328 | "available": 0 329 | }, 330 | "code_space": { 331 | "memorySize": 692224, 332 | "committedMemory": 564288, 333 | "capacity": 374432, 334 | "used": 374432, 335 | "available": 0 336 | }, 337 | "map_space": { 338 | "memorySize": 1052672, 339 | "committedMemory": 799960, 340 | "capacity": 615040, 341 | "used": 615040, 342 | "available": 0 343 | }, 344 | "large_object_space": { 345 | "memorySize": 1038983168, 346 | "committedMemory": 1038983168, 347 | "capacity": 1038964872, 348 | "used": 1038964872, 349 | "available": 0 350 | }, 351 | "code_large_object_space": { 352 | "memorySize": 49152, 353 | "committedMemory": 49152, 354 | "capacity": 2784, 355 | "used": 2784, 356 | "available": 0 357 | }, 358 | "new_large_object_space": { 359 | "memorySize": 932782080, 360 | "committedMemory": 932782080, 361 | "capacity": 932778240, 362 | "used": 932778240, 363 | "available": 0 364 | } 365 | } 366 | }, 367 | "resourceUsage": { 368 | "userCpuSeconds": 17.5179, 369 | "kernelCpuSeconds": 1.34966, 370 | "cpuConsumptionPercent": 28.1606, 371 | "maxRss": 2071122149376, 372 | "pageFaults": { 373 | "IORequired": 2, 374 | "IONotRequired": 705391 375 | }, 376 | "fsActivity": { 377 | "reads": 0, 378 | "writes": 0 379 | } 380 | }, 381 | "libuv": [ 382 | ], 383 | "workers": [ 384 | ], 385 | "environmentVariables": { 386 | "USER": "miguelmanalo", 387 | "DISPLAY": "/private/tmp/com.apple.launchd.RBsXwlIBbO/org.macosforge.xquartz:0", 388 | "LOGNAME": "miguelmanalo", 389 | "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin:/usr/local/bin:/usr/bin", 390 | "SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.lH8EY2rzsS/Listeners", 391 | "HOME": "/Users/miguelmanalo", 392 | "SHELL": "/bin/bash", 393 | "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0", 394 | "TMPDIR": "/var/folders/2n/67dnz7mj0bn7m6b8d8jgfrtc0000gn/T/", 395 | "XPC_SERVICE_NAME": "com.microsoft.VSCode.20436", 396 | "XPC_FLAGS": "0x0", 397 | "ORIGINAL_XDG_CURRENT_DESKTOP": "undefined", 398 | "VSCODE_NLS_CONFIG": "{\"locale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}", 399 | "VSCODE_NODE_CACHED_DATA_DIR": "/Users/miguelmanalo/Library/Application Support/Code/CachedData/3dd905126b34dcd4de81fa624eb3a8cbe7485f13", 400 | "VSCODE_LOGS": "/Users/miguelmanalo/Library/Application Support/Code/logs/20200822T120024", 401 | "VSCODE_IPC_HOOK": "/Users/miguelmanalo/Library/Application Support/Code/1.48.1-main.sock", 402 | "VSCODE_PID": "40256", 403 | "COMMAND_MODE": "unix2003", 404 | "PWD": "/Users/miguelmanalo/Dropbox/Projects/Programming/codesmith-csx/codewars-Sum-of-odd-numbers", 405 | "LOCAL_GIT_DIRECTORY": "/Applications/GitHub Desktop.app/Contents/Resources/app/git", 406 | "SHLVL": "1", 407 | "_": "/Applications/Visual Studio Code.app/Contents/MacOS/Electron", 408 | "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": "true", 409 | "VSCODE_CLI": "1", 410 | "ELECTRON_NO_ATTACH_CONSOLE": "1", 411 | "AMD_ENTRYPOINT": "vs/workbench/services/extensions/node/extensionHostProcess", 412 | "PIPE_LOGGING": "true", 413 | "VERBOSE_LOGGING": "true", 414 | "VSCODE_IPC_HOOK_EXTHOST": "/var/folders/2n/67dnz7mj0bn7m6b8d8jgfrtc0000gn/T/vscode-ipc-ef77b617-3e4f-45b3-8bf3-00ffa05eabc4.sock", 415 | "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true", 416 | "VSCODE_LOG_STACK": "false", 417 | "WALLABY_PRODUCTION": "true", 418 | "WALLABY_USE_WSL": "false", 419 | "DEBUG": "wallaby:.*", 420 | "DEBUG_COLORS": "no", 421 | "quokka": "{\"globalConfigFile\":\"/Users/miguelmanalo/.quokka/config.json\",\"tempDir\":\"/Users/miguelmanalo/.quokka/data/fj7oz\",\"autoDetect\":true,\"pro\":false,\"builtInPlugins\":[],\"stdEsm\":true}", 422 | "undefined": "", 423 | "ESM_OPTIONS": "{\"await\":true}", 424 | "WALLABY_ENV": "true" 425 | }, 426 | "userLimits": { 427 | "core_file_size_blocks": { 428 | "soft": 0, 429 | "hard": "unlimited" 430 | }, 431 | "data_seg_size_kbytes": { 432 | "soft": "unlimited", 433 | "hard": "unlimited" 434 | }, 435 | "file_size_blocks": { 436 | "soft": "unlimited", 437 | "hard": "unlimited" 438 | }, 439 | "max_locked_memory_bytes": { 440 | "soft": "unlimited", 441 | "hard": "unlimited" 442 | }, 443 | "max_memory_size_kbytes": { 444 | "soft": "unlimited", 445 | "hard": "unlimited" 446 | }, 447 | "open_files": { 448 | "soft": 24576, 449 | "hard": "unlimited" 450 | }, 451 | "stack_size_bytes": { 452 | "soft": 8388608, 453 | "hard": 67104768 454 | }, 455 | "cpu_time_seconds": { 456 | "soft": "unlimited", 457 | "hard": "unlimited" 458 | }, 459 | "max_user_processes": { 460 | "soft": 2784, 461 | "hard": 4176 462 | }, 463 | "virtual_memory_kbytes": { 464 | "soft": "unlimited", 465 | "hard": "unlimited" 466 | } 467 | }, 468 | "sharedObjects": [ 469 | "/usr/local/bin/node", 470 | "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation", 471 | "/usr/lib/libSystem.B.dylib", 472 | "/usr/lib/libc++.1.dylib", 473 | "/usr/lib/libobjc.A.dylib", 474 | "/usr/lib/libfakelink.dylib", 475 | "/usr/lib/libDiagnosticMessagesClient.dylib", 476 | "/usr/lib/libicucore.A.dylib", 477 | "/usr/lib/libz.1.dylib", 478 | "/usr/lib/libc++abi.dylib", 479 | "/usr/lib/system/libcache.dylib", 480 | "/usr/lib/system/libcommonCrypto.dylib", 481 | "/usr/lib/system/libcompiler_rt.dylib", 482 | "/usr/lib/system/libcopyfile.dylib", 483 | "/usr/lib/system/libcorecrypto.dylib", 484 | "/usr/lib/system/libdispatch.dylib", 485 | "/usr/lib/system/libdyld.dylib", 486 | "/usr/lib/system/libkeymgr.dylib", 487 | "/usr/lib/system/liblaunch.dylib", 488 | "/usr/lib/system/libmacho.dylib", 489 | "/usr/lib/system/libquarantine.dylib", 490 | "/usr/lib/system/libremovefile.dylib", 491 | "/usr/lib/system/libsystem_asl.dylib", 492 | "/usr/lib/system/libsystem_blocks.dylib", 493 | "/usr/lib/system/libsystem_c.dylib", 494 | "/usr/lib/system/libsystem_configuration.dylib", 495 | "/usr/lib/system/libsystem_coreservices.dylib", 496 | "/usr/lib/system/libsystem_darwin.dylib", 497 | "/usr/lib/system/libsystem_dnssd.dylib", 498 | "/usr/lib/system/libsystem_featureflags.dylib", 499 | "/usr/lib/system/libsystem_info.dylib", 500 | "/usr/lib/system/libsystem_m.dylib", 501 | "/usr/lib/system/libsystem_malloc.dylib", 502 | "/usr/lib/system/libsystem_networkextension.dylib", 503 | "/usr/lib/system/libsystem_notify.dylib", 504 | "/usr/lib/system/libsystem_sandbox.dylib", 505 | "/usr/lib/system/libsystem_secinit.dylib", 506 | "/usr/lib/system/libsystem_kernel.dylib", 507 | "/usr/lib/system/libsystem_platform.dylib", 508 | "/usr/lib/system/libsystem_pthread.dylib", 509 | "/usr/lib/system/libsystem_symptoms.dylib", 510 | "/usr/lib/system/libsystem_trace.dylib", 511 | "/usr/lib/system/libunwind.dylib", 512 | "/usr/lib/system/libxpc.dylib" 513 | ] 514 | } -------------------------------------------------------------------------------- /codewars-Take-a-Number-And-Sum-Its-Digits-Raised-To-The-Consecutive-Powers/index.js: -------------------------------------------------------------------------------- 1 | // Take a Number And Sum Its Digits Raised To The Consecutive Powers 2 | // The 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. 3 | 4 | // In effect: 89 = 8^1 + 9^2 5 | 6 | // The next number in having this property is 135. 7 | // See this property again: 135 = 1^1 + 3^2 + 5^3 8 | 9 | // We 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. 10 | 11 | // If there are no numbers of this kind in the range [a, b] the function should output an empty list. 12 | // sumDigPow(90, 100) == [] 13 | 14 | function sumDigPow(a, b) { 15 | let holdingStr = ''; 16 | let onesCheck; 17 | let tensCheck; 18 | let hundredsCheck; 19 | let thousandsCheck; 20 | let tenThousandsCheck; 21 | let hundredThousandsCheck; 22 | let millionCheck; 23 | let numbersSum; 24 | const answer = []; 25 | 26 | parameterFor: for (a; b >= a; a++) { 27 | holdingStr = a.toString(); 28 | //this has to be inside this loop or all the numbers get pushed together in the same array 29 | const checkArray = []; 30 | 31 | //separate out each number and do the exponent 32 | for (let i = 0; i <= holdingStr.length; i++) { 33 | if (i === 0 && holdingStr[0] !== undefined) { 34 | onesCheck = Math.pow(holdingStr[0], 1); 35 | } else if (i === 1 && holdingStr[1] !== undefined) { 36 | tensCheck = Math.pow(holdingStr[1], 2); 37 | } else if (i === 2 && holdingStr[2] !== undefined) { 38 | hundredsCheck = Math.pow(holdingStr[2], 3); 39 | } else if (i === 3 && holdingStr[3] !== undefined) { 40 | thousandsCheck = Math.pow(holdingStr[3], 4); 41 | } else if (i === 4 && holdingStr[4] !== undefined) { 42 | tenThousandsCheck = Math.pow(holdingStr[4], 5); 43 | } else if (i === 5 && holdingStr[5] !== undefined) { 44 | hundredThousandsCheck = Math.pow(holdingStr[5], 6); 45 | } else if (i === 6 && holdingStr[6] !== undefined) { 46 | millionCheck = Math.pow(holdingStr[6], 7); 47 | } 48 | } 49 | 50 | //push the exponents into the array to be summed 51 | checkArray.push(onesCheck); 52 | if (tensCheck !== undefined) { 53 | checkArray.push(tensCheck); 54 | } 55 | 56 | if (hundredsCheck !== undefined) { 57 | checkArray.push(hundredsCheck); 58 | } 59 | 60 | if (thousandsCheck !== undefined) { 61 | checkArray.push(thousandsCheck); 62 | } 63 | 64 | if (tenThousandsCheck !== undefined) { 65 | checkArray.push(tenThousandsCheck); 66 | } 67 | 68 | if (hundredThousandsCheck !== undefined) { 69 | checkArray.push(hundredThousandsCheck); 70 | } 71 | if (millionCheck !== undefined) { 72 | checkArray.push(millionCheck); 73 | } 74 | 75 | //use reduce to sum the array for each indiv number 76 | numbersSum = checkArray.reduce((runningTotal, currVal) => runningTotal + currVal, 0); 77 | 78 | //if the sum matches the original argument, pass it to the answer array 79 | if (numbersSum === a) { 80 | answer.push(a); 81 | } 82 | } 83 | return answer; 84 | } 85 | 86 | // console.log(sumDigPow(1, 10)); // [1, 2, 3, 4, 5, 6, 7, 8, 9] 87 | // console.log(sumDigPow(1, 100)); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 89] 88 | // console.log(sumDigPow(10, 100)); // [89] 89 | // console.log(sumDigPow(90, 100)); // [] 90 | // console.log(sumDigPow(90, 150)); // [135] 91 | // console.log(sumDigPow(50, 150)); // [89, 135] 92 | // console.log(sumDigPow(10, 150)); // [89, 135] 93 | // console.log(sumDigPow(2632374, 2647088)); // [2646798] 94 | -------------------------------------------------------------------------------- /codewars-The-Vowel-Code/index.js: -------------------------------------------------------------------------------- 1 | // The Vowel Code - 6 kyu 2 | // https://www.codewars.com/kata/53697be005f803751e0015aa/train/javascript 3 | // Step 1: Create a function called encode() to replace all the lowercase vowels in a given string with numbers according to the following pattern: 4 | 5 | // a -> 1 6 | // e -> 2 7 | // i -> 3 8 | // o -> 4 9 | // u -> 5 10 | // For example, encode("hello") would return "h2ll4". There is no need to worry about uppercase vowels in this kata. 11 | 12 | // Step 2: Now create a function called decode() to turn the numbers back into vowels according to the same pattern shown above. 13 | 14 | // For example, decode("h3 th2r2") would return "hi there". 15 | 16 | // For the sake of simplicity, you can assume that any numbers passed into the function will correspond to vowels. 17 | 18 | // FUNDAMENTALS, ARRAYS, STRINGS, FUNCTIONS, CONTROL FLOW, BASIC LANGUAGE FEATURES, REGULAR EXPRESSIONS, DECLARATIVE PROGRAMMING, ADVANCED LANGUAGE FEATURES 19 | 20 | const encode = string => { 21 | let splitStr = string.split(''); 22 | 23 | for (let i = 0; i < splitStr.length; i++) { 24 | switch (splitStr[i]) { 25 | case 'a': 26 | splitStr[i] = '1'; 27 | break; 28 | case 'e': 29 | splitStr[i] = '2'; 30 | break; 31 | case 'i': 32 | splitStr[i] = '3'; 33 | break; 34 | case 'o': 35 | splitStr[i] = '4'; 36 | break; 37 | case 'u': 38 | splitStr[i] = '5'; 39 | break; 40 | default: 41 | break; 42 | } 43 | } 44 | return splitStr.join(''); 45 | } 46 | 47 | const decode = string => { 48 | let splitStr = string.split(''); 49 | 50 | for (let i = 0; i < splitStr.length; i++) { 51 | switch (splitStr[i]) { 52 | case '1': 53 | splitStr[i] = 'a'; 54 | break; 55 | case '2': 56 | splitStr[i] = 'e'; 57 | break; 58 | case '3': 59 | splitStr[i] = 'i'; 60 | break; 61 | case '4': 62 | splitStr[i] = 'o'; 63 | break; 64 | case '5': 65 | splitStr[i] = 'u'; 66 | break; 67 | default: 68 | break; 69 | } 70 | } 71 | return splitStr.join(''); 72 | } 73 | 74 | console.log(encode('hello')); // 'h2ll4' 75 | console.log(encode('How are you today?')); // 'H4w 1r2 y45 t4d1y?' 76 | console.log(encode('This is an encoding test.')); // 'Th3s 3s 1n 2nc4d3ng t2st.' 77 | console.log(decode('h2ll4')); // 'hello' -------------------------------------------------------------------------------- /codewars-The-observed-PIN/index.js: -------------------------------------------------------------------------------- 1 | // The observed PIN - 4 kyu 2 | // Alright, detective, one of our colleagues successfully observed our target person, Robby the robber. We followed him to a secret warehouse, where we assume to find all the stolen stuff. The door to this warehouse is secured by an electronic combination lock. Unfortunately our spy isn't sure about the PIN he saw, when Robby entered it. 3 | 4 | // The keypad has the following layout: 5 | 6 | // ┌───┬───┬───┐ 7 | // │ 1 │ 2 │ 3 │ 8 | // ├───┼───┼───┤ 9 | // │ 4 │ 5 │ 6 │ 10 | // ├───┼───┼───┤ 11 | // │ 7 │ 8 │ 9 │ 12 | // └───┼───┼───┘ 13 | // │ 0 │ 14 | // └───┘ 15 | // He noted the PIN 1357, but he also said, it is possible that each of the digits he saw could actually be another adjacent digit (horizontally or vertically, but not diagonally). E.g. instead of the 1 it could also be the 2 or 4. And instead of the 5 it could also be the 2, 4, 6 or 8. 16 | 17 | // He also mentioned, he knows this kind of locks. You can enter an unlimited amount of wrong PINs, they never finally lock the system or sound the alarm. That's why we can try out all possible (*) variations. 18 | 19 | // * possible in sense of: the observed PIN itself and all variations considering the adjacent digits 20 | 21 | // Can you help us to find all those variations? It would be nice to have a function, that returns an array (or a list in Java and C#) of all variations for an observed PIN with a length of 1 to 8 digits. We could name the function getPINs (get_pins in python, GetPINs in C#). But please note that all PINs, the observed one and also the results, must be strings, because of potentially leading '0's. We already prepared some test cases for you. 22 | 23 | // Detective, we are counting on you! 24 | 25 | // ALGORITHMS 26 | 27 | function getPINs(observed) { 28 | // TODO: This is your job, detective! 29 | const numPadArr = [ 30 | [ 1, 2, 3, ], 31 | [ 4, 5, 6, ], 32 | [ 7, 8, 9, ], 33 | [ , 0, , ] 34 | ]; 35 | for (let i = 0; i < numPadArr.length; i++) { 36 | 37 | } 38 | } 39 | 40 | // console.log(getPINs('8')); // ["5", "7", "8", "9", "0"] 41 | console.log(getPINs('11')); // ["11", "22", "44", "12", "21", "14", "41", "24", "42"] 42 | // console.log(getPINs('369')); // ["339","366","399","658","636","258","268","669","668","266","369","398","256","296","259","368","638","396","238","356","659","639","666","359","336","299","338","696","269","358","656","698","699","298","236","239"] 43 | 44 | // My Notes 45 | // build array of the numpad 46 | // four rows 47 | // for the zero row, null, 0, null 48 | // or may be just an array of 0 49 | // const numPadArr = [ 50 | // [ 1, 2, 3, ], 51 | // [ 4, 5, 6, ], 52 | // [ 7, 8, 9, ], 53 | // [ , 0, , ] 54 | // ]; 55 | // for 6 numPadArr[1][2] 56 | // all it's horizontal mates are at 5 at numPadArr[1, 1] 57 | // vertical mates are at 3 at numPadArr[0][2], numPadArr[2][2] 58 | // 8's vertical mate is at 0 at numPadArr[3][1] 59 | 60 | // you have to split the number into single digits 61 | // horizontally you move plus j, minus j in the same row 62 | // vertically you move plus minus i in the same 'column' 63 | 64 | // but how do i get all the various combinations? -------------------------------------------------------------------------------- /codewars-Tic-Tac-Toe-Checker/index.js: -------------------------------------------------------------------------------- 1 | // Tic-Tac-Toe Checker - 5 kyu 2 | // https://www.codewars.com/kata/525caa5c1bf619d28c000335/train/javascript 3 | 4 | // If we were to set up a Tic-Tac-Toe game, we would want to know whether the board's current state is solved, wouldn't we? Our goal is to create a function that will check that for us! 5 | 6 | // Assume that the board comes in the form of a 3x3 array, where the value is 0 if a spot is empty, 1 if it is an "X", or 2 if it is an "O", like so: 7 | 8 | // [[0, 0, 1], 9 | // [0, 1, 2], 10 | // [2, 1, 0]] 11 | // We want our function to return: 12 | 13 | // -1 if the board is not yet finished (there are empty spots), 14 | // 1 if "X" won, 15 | // 2 if "O" won, 16 | // 0 if it's a cat's game (i.e. a draw). 17 | // You may assume that the board passed in is valid in the context of a game of Tic-Tac-Toe. 18 | 19 | // ALGORITHMS, ARRAYS 20 | 21 | const isSolved = board => { 22 | for (let i = 0; i < board.length; i++) { 23 | // horizontal matches 24 | // [0,0], [1,0], [2,0] match col 1 25 | // [0,1], [1,1], [2,1] match col 2 26 | // [0,2], [1,2], [2,2] match col 3 27 | if ((board[i][0] === board[i][1]) && (board[i][0] === board[i][2])) { 28 | switch (board[i][0]) { 29 | case 1: 30 | return 1; 31 | case 2: 32 | return 2; 33 | } 34 | } 35 | 36 | // vertical matches 37 | // [0,0], [0,1], [0,2] match row 1 38 | // [1,0], [1,1], [1,2] match row 2 39 | // [2,0], [2,1], [2,2] match row 3 40 | if ((board[0][i] === board[1][i]) && (board[0][i] === board[2][i])) { 41 | switch (board[0][i]) { 42 | case 1: 43 | return 1; 44 | case 2: 45 | return 2; 46 | } 47 | } 48 | } 49 | 50 | // diagonal matches 51 | // [0,0], [1,1], [2,2] 52 | // [0,2], [1,1], [2,0] 53 | if ((board[0][0] === board[1][1]) && (board[0][0] === board[2][2]) || (board[0][2] === board[1][1]) && board[1][1] === board[2][0]) { 54 | switch (board[1][1]) { 55 | case 1: 56 | return 1; 57 | case 2: 58 | return 2; 59 | } 60 | } 61 | 62 | // if no matches are found, and there's still 0s return -1 63 | // if no matches are found but the board is full return tie 0 64 | return (board[0].includes(0) || board[1].includes(0) || board[2].includes(0)) ? -1 : 0; 65 | } 66 | 67 | // console.log(isSolved([[0, 0, 1], [0, 1, 2], [2, 1, 0]])); // -1 68 | // console.log(isSolved([[2, 2, 2], [0, 0, 0], [0, 0, 0]])); // 2 69 | // console.log(isSolved([[1, 1, 0], [2, 1, 0], [2, 1, 0]])); // 1 70 | // console.log(isSolved([[2, 1, 0], [0, 2, 0], [2, 1, 2]])); // 2 71 | console.log(isSolved([[1, 2, 1], [2, 2, 1], [2, 1, 2]])); // 0 72 | 73 | // console.log(isSolved( 74 | // [ 75 | // [1,2,1], 76 | // [2,2,1], 77 | // [2,1,2] 78 | // ])); // -1 79 | 80 | // console.log(isSolved( 81 | // [ 82 | // [0,0,1], 83 | // [0,1,2], 84 | // [2,1,0] 85 | // ])); // -1 -------------------------------------------------------------------------------- /codewars-Two-Sum/index.js: -------------------------------------------------------------------------------- 1 | // Two Sum 2 | // https://www.codewars.com/kata/52c31f8e6605bcc646000082/train/javascript 3 | // Write 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 a tuple like so: (index1, index2). 4 | 5 | // For the purposes of this kata, some tests may have multiple answers; any valid solutions will be accepted. 6 | 7 | // The 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). 8 | 9 | // Based on: http://oj.leetcode.com/problems/two-sum/ 10 | 11 | const twoSum = (arr, target) => { 12 | startAtBeginningLoop: for (let i = 0; i < arr.length; i++) { 13 | oneStepAheadLoop: for (let j = i + 1; j < arr.length + 1 && arr[j] !== undefined; j++) { 14 | if (arr[i] + arr[j] === target) return [i ,j]; 15 | } 16 | } 17 | } 18 | 19 | console.log(twoSum([1,2,3], 4)); // [0,2] 20 | console.log(twoSum([1234,5678,9012], 14690)); // [1,2] 21 | console.log(twoSum([2,2,3], 4)); // [0,1] -------------------------------------------------------------------------------- /codewars-Unique-In-Order/index.js: -------------------------------------------------------------------------------- 1 | // Codewars - Fundamentals: Unique In Order (6 kyu) 2 | // https://www.codewars.com/kata/54e6533c92449cc251001667/train/javascript 3 | 4 | // Implement 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. 5 | 6 | // For example: 7 | // uniqueInOrder('AAAABBBCCDAABBB') == ['A', 'B', 'C', 'D', 'A', 'B'] 8 | // uniqueInOrder('ABBCcAD') == ['A', 'B', 'C', 'c', 'A', 'D'] 9 | // uniqueInOrder([1,2,2,3,3]) == [1,2,3] 10 | 11 | const uniqueInOrder = (iterable) => { 12 | const answerArray = []; 13 | //if I don't want to distinguish between a string and an array 14 | for (let i = 0; i < iterable.length; i++) { 15 | if (iterable[i + 1] !== iterable[i]) { 16 | answerArray.push(iterable[i]); 17 | } 18 | } 19 | return answerArray; 20 | } 21 | 22 | console.log(uniqueInOrder('AAAABBBCCDAABBB')); // ['A','B','C','D','A','B'] 23 | console.log(uniqueInOrder('AAAABBBCCDAABBB')); // ['A', 'B', 'C', 'D', 'A', 'B'] 24 | console.log(uniqueInOrder('ABBCcAD')); // ['A', 'B', 'C', 'c', 'A', 'D'] 25 | console.log(uniqueInOrder([1,2,2,3,3])); // [1,2,3] -------------------------------------------------------------------------------- /codewars-factorial/index.js: -------------------------------------------------------------------------------- 1 | // Factorial 2 | // https://www.codewars.com/kata/54ff0d1f355cfd20e60001fc/train/javascript 3 | // In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example: 5! = 5 * 4 * 3 * 2 * 1 = 120. By convention the value of 0! is 1. 4 | 5 | // Write a function to calculate factorial for a given input. If input is below 0 or above 12 throw an exception of type ArgumentOutOfRangeException (C#) or IllegalArgumentException (Java) or RangeException (PHP) or throw a RangeError (JavaScript) or ValueError (Python) or return -1 (C). 6 | 7 | // More details about factorial can be found here: https://www.wikiwand.com/en/Factorial 8 | 9 | const factorial = (num) => { 10 | if (num < 0 || num > 12) throw new RangeError("Num must be greater than 0 and less than 12.") 11 | // I think 0! has to be hard coded in, its not a calculated value 12 | if (num === 0) return 1; 13 | 14 | // Calculate the factorial here 15 | // ternary syntax 16 | return (num === 1 ? num : num * factorial(num - 1)); 17 | // // base case 18 | // if (num === 1) return num; 19 | // // recursive case 20 | // return num * factorial(num - 1); 21 | } 22 | 23 | console.log(factorial(0)); // 1 24 | console.log(factorial(1)); // 1 25 | console.log(factorial(2)); // 2 26 | console.log(factorial(3)); // 6 27 | // console.log(factorial(-1)); // 1 28 | console.log(factorial(13)); // RangeError "Num must be greater than 0 and less than 12." -------------------------------------------------------------------------------- /codewars-find-the-capitals/find-the-capitals.js: -------------------------------------------------------------------------------- 1 | // Write a function that takes a single string (word) as argument. The function must return an ordered list containing the indexes of all capital letters in the string. 2 | 3 | const capitals = (word) => { 4 | const answer = []; 5 | const wordArray = word.split(''); 6 | const capitalFinder = (s) => { 7 | if (s === s.toUpperCase()) return true; 8 | } 9 | 10 | wordArray.forEach((element, index) => { 11 | if (capitalFinder(element) === true) answer.push(index); 12 | }); 13 | 14 | return answer; 15 | } 16 | 17 | //Tests 18 | console.log( capitals('CodEWaRs')); // [0,3,4,6] -------------------------------------------------------------------------------- /codewars-plus1-Array/index.js: -------------------------------------------------------------------------------- 1 | // Codewars: +1 Array 2 | // https://www.codewars.com/kata/5514e5b77e6b2f38e0000ca9/train/javascript 3 | 4 | // Given an array of integers of any length, return an array that has 1 added to the value represented by the array. 5 | 6 | // the array can't be empty 7 | // only non-negative, single digit integers are allowed 8 | 9 | // Return nil (or your language's equivalent) for invalid inputs. 10 | 11 | // Examples 12 | // For example the array [2, 3, 9] equals 239, adding one would return the array [2, 4, 0]. 13 | // [4, 3, 2, 5] would return [4, 3, 2, 6] 14 | 15 | const upArray = arr => { 16 | // if any number in the array is less than 0, greater than 9, or an empty array then return null 17 | if (arr.some(element => element < 0) || arr.some(element => element > 9) || arr.length === 0) return null; 18 | 19 | // **REFACTOR: redo the above to not use array methods, shouldn't be too hard 20 | 21 | 22 | for (let i = arr.length - 1; i >= 0; i--) { 23 | // loop from the end going backwards 24 | // if the number ends in anything other than 9, we just increment that last value by mutating it in place and then return so the loop doesn't increment every other non-9 number 25 | if (arr[i] < 9 || i === 0) { 26 | arr[i]++; 27 | // if you need to make a new numbers place if your initial array is all 9s 28 | if (arr[0] === 10) { 29 | arr[0] = 0; 30 | arr.unshift(1); 31 | } 32 | return arr; 33 | } 34 | 35 | // if a value does equal 9, make it zero and go to the above if-statement and increment that; 36 | if (arr[i] >= 9 && i !== 0) { 37 | arr[i] = 0; 38 | } 39 | } 40 | } 41 | 42 | // console.log(upArray([])); // null 43 | // console.log(upArray([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,])); 44 | // console.log(upArray([9,9,9,9])); // [1,0,0,0,0] 45 | // console.log(upArray([8,9,9,9])); // [9,0,0,0] 46 | // console.log(upArray([2,3,9])); // [2,4,0] 47 | // console.log(upArray([4,3,2,5])); // [4,3,2,6]) 48 | // console.log(upArray([1,-9])); // null 49 | // console.log(upArray([9, 2, 2, 3, 3, 7, 2, 0, 3, 6, 8, 5, 4, 7, 7, 5, 8, 0, 7])); // [9, 2, 2, 3, 3, 7, 2, 0, 3, 6, 8, 5, 4, 7, 7, 5, 8, 0, 8] 50 | // console.log(upArray([9, 2, 2, 3, 3, 7, 2, 0, 3, 6, 8, 5, 4, 7, 7, 5, 8, 0, 7, 5, 3, 2, 6, 7, 8, 4, 2, 4, 2, 6, 7, 8, 7, 4, 5, 2, 1])); // [9, 2, 2, 3, 3, 7, 2, 0, 3, 6, 8, 5, 4, 7, 7, 5, 8, 0, 7, 5, 3, 2, 6, 7, 8, 4, 2, 4, 2, 6, 7, 8, 7, 4, 5, 2, 2] -------------------------------------------------------------------------------- /codewars-round-up-to-the-next-multiple-of-5/index.js: -------------------------------------------------------------------------------- 1 | // Given an integer as input, can you round it to the next (meaning, "higher") 5? 2 | 3 | // Input may be any positive or negative integer (including 0). 4 | 5 | // You can assume that all inputs are valid integers. 6 | 7 | const roundToNext5 = (num) => 8 | { 9 | for (let i = num; i < num + 5; i++) 10 | { 11 | if (i % 5 === 0) 12 | { 13 | return i; 14 | } 15 | } 16 | } 17 | 18 | // Tests: 19 | console.log(roundToNext5(0)); // 0 -> 0 20 | console.log(roundToNext5(2)); // 2 -> 5 21 | console.log(roundToNext5(3)); // 3 -> 5 22 | console.log(roundToNext5(12)); // 12 -> 15 23 | console.log(roundToNext5(21)); // 21 -> 25 24 | console.log(roundToNext5(30)); // 30 -> 30 25 | console.log(roundToNext5(-2)); // -2 -> 0 26 | console.log(roundToNext5(-5)); // -5 -> -5 -------------------------------------------------------------------------------- /codewars-titlecase/README.md: -------------------------------------------------------------------------------- 1 | # codewars-titlecase 2 | 3 | -------------------------------------------------------------------------------- /codewars-titlecase/codewars-titlecase.js: -------------------------------------------------------------------------------- 1 | function titleCase(title, minorWords) { 2 | const capitalizedArray = []; 3 | let answer; 4 | let minorSplit; 5 | let upperMinor = []; 6 | let lowercaseMinor; 7 | const wordsSplit = title.split(' '); 8 | const lowercaseWords = wordsSplit.map(item => item.toLowerCase()); 9 | const capitalize = (s) => { 10 | // found this snippet from flavio 11 | return s.charAt(0).toUpperCase() + s.slice(1) 12 | } 13 | 14 | // make uppercase all the title words 15 | for (let i = 0; i < lowercaseWords.length; i++) { 16 | capitalizedArray.push(lowercaseWords[i].charAt(0).toUpperCase() + lowercaseWords[i].slice(1)); 17 | } 18 | 19 | //if no parameter is passed, just return the newly capitalized array 20 | if (minorWords === undefined) { 21 | return capitalizedArray.join(" "); 22 | //if there is a minorWords argument passed then we continue on 23 | } else { 24 | minorSplit = minorWords.split(' '); 25 | //sanitize the minorWords by making them all lowercase 26 | lowercaseMinor = minorSplit.map(item => item.toLowerCase()); 27 | 28 | //then capitalize all the minor words 29 | for (let i = 0; i < lowercaseMinor.length; i++) { 30 | upperMinor.push(capitalize(lowercaseMinor[i])); 31 | } 32 | 33 | for (let i = 1; i < capitalizedArray.length; i++) { 34 | for (let j = 0; j < upperMinor.length; j++) { 35 | if (capitalizedArray[i] === upperMinor[j]) { 36 | // this took forever to figure out. why?? 37 | // Why did it take me so long to just replace it as I found it. 38 | capitalizedArray[i] = capitalizedArray[i].toLowerCase(); 39 | } 40 | } 41 | } 42 | answer = capitalizedArray.join(" "); 43 | } 44 | return answer; 45 | } 46 | 47 | // console.log(titleCase('')); // '' 48 | // console.log(titleCase('a clash of KINGS', 'a an the of')); // 'A Clash of Kings' 49 | // console.log(titleCase('THE WIND IN THE WILLOWS', 'The In')); // 'The Wind in the Willows' 50 | // console.log(titleCase('the quick brown fox')); // 'The Quick Brown Fox' 51 | // console.log(titleCase('a bc', 'BC')); // 'A bc' 52 | // console.log(titleCase('a clash of KINGS', "a an the OF")) // 'A Clash of Kings' -------------------------------------------------------------------------------- /codewars-valid-braces.js: -------------------------------------------------------------------------------- 1 | function validBraces(braces){ 2 | //TODO 3 | } 4 | 5 | // Test.assertEquals(validBraces( "()" ), true); 6 | // Test.assertEquals(validBraces( "[(])" ), false); 7 | // "(){}[]" => True 8 | // "([{}])" => True 9 | // "(}" => False 10 | // "[(])" => False 11 | // "[({})](]" => False -------------------------------------------------------------------------------- /divisors.js: -------------------------------------------------------------------------------- 1 | function divisors(integer) { 2 | const answerArray = []; 3 | for (let i = 2; i <= integer; i += 1) { 4 | if (integer % i === 0) { 5 | if (integer === i) { 6 | if (answerArray.length === 0) { 7 | return `${integer} is prime`; 8 | } 9 | return answerArray; 10 | } 11 | answerArray.push(i); 12 | } 13 | } 14 | return answerArray; 15 | }; 16 | 17 | console.log(divisors(12)); // should return [2,3,4,6] 18 | console.log(divisors(25)); // should return [5] 19 | console.log(divisors(13)); // should return "13 is prime" -------------------------------------------------------------------------------- /duplicate-encoder.js: -------------------------------------------------------------------------------- 1 | function duplicateEncode(word){ 2 | //case doesn't matter so make everything lowercase 3 | const wordLowerCase = word.toLowerCase(); 4 | const lettersArray = wordLowerCase.split(''); 5 | const translatedArray = []; 6 | 7 | function checkForDuplicates(array) { 8 | const uniqueValues = []; 9 | const translatorObj = {}; 10 | 11 | // Translate each char to ( or ) // 12 | array.forEach(function (item, index, currArray) { 13 | //set every letter in the object to '(' to start 14 | translatorObj[currArray[index]] = '('; 15 | console.log(uniqueValues.indexOf(item)) 16 | //change only the duplicates to ')' 17 | if (uniqueValues.indexOf(item) !== -1) { 18 | 19 | translatorObj[currArray[index]] = ')'; 20 | } 21 | uniqueValues.push(item); 22 | }); 23 | 24 | // Write the desired outcome // 25 | //iterate through the letters and then iterate for the key-value pair 26 | //in translatorObj for the given letter 27 | array.forEach(function (item, index, currArray) { 28 | for (const key in translatorObj) { 29 | if (item == key) { 30 | translatedArray.push(translatorObj[key]); 31 | } 32 | } 33 | }) 34 | }; 35 | 36 | checkForDuplicates(lettersArray); 37 | let printableAnswer = translatedArray.toString(); 38 | return printableAnswer.replace(/,/gi, ''); 39 | } 40 | 41 | console.log(duplicateEncode('aabcdd')) -------------------------------------------------------------------------------- /findFriends.js: -------------------------------------------------------------------------------- 1 | const findFriend = foundFriend => foundFriend.length === 4; 2 | 3 | function friend(friends){ 4 | const friendAnswer = friends.filter(findFriend); 5 | return friendAnswer; 6 | } 7 | 8 | console.log(friend(["Ryan", "Kieran", "Mark"])); 9 | console.log(friend(["Ryan", "Jimmy", "123", "4", "Cool Man"])); 10 | console.log(friend(["Jimm", "Cari", "aret", "truehdnviegkwgvke", "sixtyiscooooool"])); 11 | console.log(friend(["Love", "Your", "Face", "1"])); 12 | 13 | // Test.assertSimilar(friend(["Ryan", "Kieran", "Mark"]), ["Ryan", "Mark"]); 14 | // Test.assertSimilar(friend(["Ryan", "Jimmy", "123", "4", "Cool Man"]), ["Ryan"]); 15 | // Test.assertSimilar(friend(["Jimm", "Cari", "aret", "truehdnviegkwgvke", "sixtyiscooooool"]), ["Jimm", "Cari", "aret"]); 16 | // Test.assertSimilar(friend(["Love", "Your", "Face", "1"]), ["Love", "Your", "Face"]); -------------------------------------------------------------------------------- /is-isogram.js: -------------------------------------------------------------------------------- 1 | function isIsogram(str){ 2 | const wordLowerCase = str.toLowerCase(); 3 | const lettersArray = wordLowerCase.split(''); 4 | const uniqueValues = []; 5 | let check = true; 6 | 7 | if (str == '') { 8 | return true; 9 | } 10 | 11 | for (let i = 0; i < lettersArray.length; i += 1) { 12 | console.log(uniqueValues.indexOf(lettersArray[i])); 13 | if (uniqueValues.indexOf(lettersArray[i]) >= 0) { 14 | check = false; 15 | } 16 | uniqueValues.push(lettersArray[i]); 17 | } 18 | return check; 19 | } 20 | 21 | console.log(isIsogram('Dermatoglyphics')); 22 | console.log(isIsogram('isogram')); 23 | console.log(isIsogram('aba')); 24 | console.log(isIsogram('moOse')); 25 | console.log(isIsogram('isIsogram')); 26 | console.log(isIsogram('')); -------------------------------------------------------------------------------- /isValidWalk.js: -------------------------------------------------------------------------------- 1 | function isValidWalk(walk) { 2 | //the starting coordinates and the position I want to return to 3 | const currentWalk = [0, 0,]; 4 | let isAWalk = false; 5 | //the walk has to be exactly ten minutes 6 | //not longer, not shorter 7 | if (walk.length === 10) { 8 | for (let i = 0; i < 10; i += 1) { 9 | //n & s = y-coordinates, w & e = x-coordinates 10 | if (walk[i] === 'n') { 11 | currentWalk[1]++; 12 | } else if (walk[i] === 's') { 13 | currentWalk[1]--; 14 | } else if (walk[i] === 'w') { 15 | currentWalk[0]--; 16 | } else if (walk[i] === 'e') { 17 | currentWalk[0]++; 18 | } 19 | } 20 | if (currentWalk[0] === 0 && currentWalk[1] === 0) { 21 | isAWalk = true; 22 | } 23 | } 24 | return isAWalk; 25 | }; 26 | 27 | // console.log(isValidWalk(['w','e','w','e','w','e','w','e','w','e',])); 28 | console.log(isValidWalk(['n','s','n','s','n','s','n','s','n','s'])); //'should return true'); 29 | // console.log(isValidWalk(['w','e','w','e','w','e','w','e','w','e','w','e'])); //'should return false'); 30 | // console.log(isValidWalk(['w'])); //'should return false'); 31 | // console.log(isValidWalk(['n','n','n','s','n','s','n','s','n','s'])); //'should return false'); -------------------------------------------------------------------------------- /openOrSenior.js: -------------------------------------------------------------------------------- 1 | function openOrSenior(data){ 2 | const memberStatus = []; 3 | data.forEach(function (item) { 4 | (item[0] >= 55 && item[1] > 7) ? 5 | memberStatus.push("Senior") : 6 | memberStatus.push("Open"); 7 | }); 8 | return memberStatus 9 | } -------------------------------------------------------------------------------- /range-extension/index.js: -------------------------------------------------------------------------------- 1 | // A format for expressing an ordered list of integers is to use a comma separated list of either 2 | 3 | // individual integers 4 | // or a range of integers denoted by the starting integer separated from the end integer in the range by a dash, '-'. The range includes all integers in the interval including both endpoints. It is not considered a range unless it spans at least 3 numbers. For example "12,13,15-17" 5 | // Complete the solution so that it takes a list of integers in increasing order and returns a correctly formatted string in the range format. 6 | 7 | // Example: 8 | // solution([-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]); 9 | // // returns "-6,-3-1,3-5,7-11,14,15,17-20" 10 | 11 | function solution(list){ 12 | // TODO: complete solution 13 | // declare an empty string to hold the answer 14 | let answerStr = []; 15 | let rangeStartEnd = []; 16 | let rangeToBePushed = ''; 17 | // make a recursive function to check every n + item in the array 18 | const numChecker = (arr) => { 19 | console.log(arr) 20 | for (let i = 0, len = list.length; i < len; i += 1) { 21 | console.log(arr[i]); 22 | if (arr[i + 1] === arr[i] + 1) { 23 | console.log('here') 24 | rangeStartEnd.push(arr[i]); 25 | numChecker(arr.slice(i + 1)); 26 | } else if (arr[i + 1] !== arr[i] + 1 && rangeStartEnd.length >= 3) { 27 | rangeToBePushed = `${Math.min(...rangeStartEnd)}-${Math.max(...rangeStartEnd)}`; 28 | answerStr.push(rangeToBePushed); 29 | console.log(answerStr); 30 | rangeToBePushed = ''; 31 | rangeStartEnd = []; 32 | } else if (arr[i + 1] !== arr[i] + 1 && rangeStartEnd.length < 3) { 33 | answerStr.push(arr[i]); 34 | console.log(answerStr); 35 | console.log(arr[i]) 36 | numChecker(arr.slice(i + 1)); 37 | } 38 | } 39 | } 40 | 41 | // iterate thru the array arg and ask if n + 1 is exactly +1 of n 42 | // for (let i = 0, len = list.length; i < len; i += 1) { 43 | 44 | // } 45 | // if it is exactly n + 1, check n + 2 and so on 46 | // when the n checks are no longer linear, take n and the furthest n-plus and put them in the neat little format 47 | // and push to the answer string 48 | // if the n + 1 is not exactly plus one, push n 49 | // return the answer string 50 | numChecker(list); 51 | return answerStr.join(''); 52 | }; 53 | 54 | console.log(solution([-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20])); // returns "-6,-3-1,3-5,7-11,14,15,17-20" --------------------------------------------------------------------------------