├── .gitignore ├── .gitpod.yml ├── .vscode └── settings.json ├── README.md ├── assets ├── run-tests.gif ├── running-tests-on-change.gif └── watch-changed-files.gif ├── package-lock.json ├── package.json ├── src ├── 00-acronym │ ├── index.ts │ └── test.ts ├── 01-fizz-buzz │ ├── index.ts │ └── test.ts ├── 02-capitalize │ ├── index.ts │ └── test.ts ├── 03-is-even │ ├── index.ts │ └── test.ts ├── 04-longest-word │ ├── index.ts │ └── test.ts ├── 05-reverse-string │ ├── index.ts │ └── test.ts ├── 06-palindrome │ ├── index.ts │ └── test.ts ├── 07-reverse-integer │ ├── index.ts │ └── test.ts ├── 08-vowels │ ├── index.ts │ └── test.ts ├── 09-anagrams │ ├── index.ts │ └── test.ts ├── 10-armstrong-numbers │ ├── index.ts │ └── test.ts ├── 11-collatz-conjecture │ ├── index.ts │ └── test.ts ├── 12-queue │ ├── index.ts │ └── test.ts ├── 13-high-scores │ ├── index.ts │ └── test.ts ├── 14-stack │ ├── index.ts │ └── test.ts ├── 15-phone-numbers │ ├── index.ts │ └── test.ts ├── 16-second-largest │ ├── index.ts │ └── test.ts ├── 17-max-char │ ├── index.ts │ └── test.ts ├── 18-pyramid │ ├── index.ts │ └── test.ts ├── 19-word-count │ ├── index.ts │ └── test.ts ├── 20-steps │ ├── index.ts │ └── test.ts └── 21-matrix │ ├── index.ts │ └── test.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | vscode: 2 | extensions: 3 | - esbenp.prettier-vscode 4 | - dracula-theme.theme-dracula 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "[javascript]": { 4 | "editor.defaultFormatter": "esbenp.prettier-vscode" 5 | }, 6 | "editor.formatOnSave": true 7 | } 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Easy Exercises 2 | 3 | Probably most of the _Warm Up_ exercises are finished if you have managed to get this far. 4 | 5 | Have you noticed that it is pretty cumbersome to check output all the time? If the same approach would be used in real life, development speed would suffer. 6 | 7 | Luckily there is a better way - tests! 8 | 9 | > No one else should write tests for your code!!! Your code - your responsibility! 10 | 11 | But only this time - tests are written by us, using a highly popular library - [Jest](https://jestjs.io). 12 | 13 | Your goal for this part is to have all of the tests green. 14 | 15 | ## Getting Ready 16 | 17 | [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/codelex-io/prep-course-day-two) 18 | 19 | As before, download all the dependencies by executing `npm install` 20 | 21 | **PRO TIP:** you can save 3ms by executing `npm i` which does the same thing 22 | 23 | ## Executing Tests 24 | 25 | `src` directory includes multiple subdirectories. Each of them contains two files, one contains the code that you are going to modify and the second one is a test file which you are not allowed to modify. 26 | 27 | Start in the ascending order, by looking at the **code and test** (it is very important to read the test also) try to figure out what you need to do. 28 | 29 | Execute all tests with command `npm test` 30 | 31 | !["Run Tests"](./assets/run-tests.gif) 32 | 33 | You will see that there are a lot of tests being run and most of them are failing (red). 34 | 35 | Afterwards, the process will stay running and you will be presented with a few options, choose `o` to run only the tests related to changed files. 36 | 37 | !["Watch Changed Files"](./assets/watch-changed-files.gif) 38 | 39 | Now when you change any file, tests related to that file will be run (it will happen automatically, if you have autosave enabled). 40 | 41 | !["Running Tests on Change"](./assets/running-tests-on-change.gif) 42 | 43 | If you want to exit from currently running process press `ctrl + c`. 44 | -------------------------------------------------------------------------------- /assets/run-tests.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codelex-io/prep-course-part-two/4653968b85f05aa6d4a97d342801d81dfb4b0640/assets/run-tests.gif -------------------------------------------------------------------------------- /assets/running-tests-on-change.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codelex-io/prep-course-part-two/4653968b85f05aa6d4a97d342801d81dfb4b0640/assets/running-tests-on-change.gif -------------------------------------------------------------------------------- /assets/watch-changed-files.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codelex-io/prep-course-part-two/4653968b85f05aa6d4a97d342801d81dfb4b0640/assets/watch-changed-files.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codelex-easy-exercises", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest --env=node --colors test --watch", 8 | "prettier": "prettier --write src/**/*.ts" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@types/jest": "^28.1.6", 14 | "cross-env": "^7.0.3", 15 | "jest": "^28.1.3", 16 | "ts-jest": "^28.0.7", 17 | "typescript": "^4.7.4" 18 | }, 19 | "jest": { 20 | "testEnvironment": "node", 21 | "roots": [ 22 | "/src" 23 | ], 24 | "transform": { 25 | "^.+\\.ts?$": "ts-jest" 26 | }, 27 | "testRegex": "(\\.|/)(test)\\.(ts|tsx?)$", 28 | "moduleFileExtensions": [ 29 | "ts", 30 | "js", 31 | "json", 32 | "node" 33 | ] 34 | }, 35 | "devDependencies": { 36 | "prettier": "2.7.1" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/00-acronym/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Convert a phrase to its acronym. 3 | * 4 | * Techies love their TLA (Three Letter Acronyms)! 5 | * 6 | * Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG). 7 | */ 8 | 9 | function parse(input: string) {} 10 | 11 | export { parse }; 12 | -------------------------------------------------------------------------------- /src/00-acronym/test.ts: -------------------------------------------------------------------------------- 1 | import { parse } from "./index"; 2 | 3 | describe("Acronyms are produced from", () => { 4 | test("title cased phrases", () => { 5 | expect(parse("Portable Network Graphics")).toEqual("PNG"); 6 | }); 7 | 8 | test("other title cased phrases", () => { 9 | expect(parse("Ruby on Rails")).toEqual("ROR"); 10 | }); 11 | 12 | test("phrases with punctuation", () => { 13 | expect(parse("First In, First Out")).toEqual("FIFO"); 14 | }); 15 | 16 | test("phrases with all uppercase words", () => { 17 | expect(parse("GNU Image Manipulation Program")).toEqual("GIMP"); 18 | }); 19 | 20 | test("phrases with punctuation without whitespace", () => { 21 | expect(parse("Complementary metal-oxide semiconductor")).toEqual("CMOS"); 22 | }); 23 | 24 | test("long phrases", () => { 25 | expect( 26 | parse( 27 | "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me" 28 | ) 29 | ).toEqual("ROTFLSHTMDCOALM"); 30 | }); 31 | 32 | test("phrases with consecutive delimiters", () => { 33 | expect(parse("Something - I made up from thin air")).toEqual("SIMUFTA"); 34 | }); 35 | 36 | test("phrases with apostrophes", () => { 37 | expect(parse("Halley's Comet")).toEqual("HC"); 38 | }); 39 | 40 | test("phrases with underscore emphasis", () => { 41 | expect(parse("The Road _Not_ Taken")).toEqual("TRNT"); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /src/01-fizz-buzz/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Fizz Buzz 3 | * 4 | * Write a program that console logs the numbers 5 | * from 1 to n. But for multiples of three print 6 | * “fizz” instead of the number and for the multiples 7 | * of five prints “buzz”. For numbers which are multiples 8 | * of both three and five print “fizzbuzz”. 9 | * 10 | * Example: 11 | * fizzBuzz(5); 12 | * console.log(1) 13 | * console.log(2) 14 | * console.log('fizz') 15 | * console.log(4) 16 | * console.log('buzz') 17 | */ 18 | 19 | function fizzBuzz(n: number) {} 20 | 21 | export { fizzBuzz }; 22 | -------------------------------------------------------------------------------- /src/01-fizz-buzz/test.ts: -------------------------------------------------------------------------------- 1 | import { fizzBuzz } from "./index"; 2 | 3 | describe("FizzBuzz function", () => { 4 | let spy: jest.SpyInstance; 5 | beforeEach(() => { 6 | spy = jest.spyOn(console, "log"); 7 | }); 8 | 9 | afterEach(() => { 10 | spy.mockRestore(); 11 | }); 12 | 13 | test("should print out 5 statements when called with 5", () => { 14 | fizzBuzz(5); 15 | 16 | expect(spy.mock.calls.length).toEqual(5); 17 | }); 18 | 19 | test("should prints out the correct values", () => { 20 | fizzBuzz(15); 21 | 22 | expect(spy.mock.calls[0][0]).toEqual(1); 23 | expect(spy.mock.calls[1][0]).toEqual(2); 24 | expect(spy.mock.calls[2][0]).toEqual("fizz"); 25 | expect(spy.mock.calls[3][0]).toEqual(4); 26 | expect(spy.mock.calls[4][0]).toEqual("buzz"); 27 | expect(spy.mock.calls[5][0]).toEqual("fizz"); 28 | expect(spy.mock.calls[6][0]).toEqual(7); 29 | expect(spy.mock.calls[7][0]).toEqual(8); 30 | expect(spy.mock.calls[8][0]).toEqual("fizz"); 31 | expect(spy.mock.calls[9][0]).toEqual("buzz"); 32 | expect(spy.mock.calls[10][0]).toEqual(11); 33 | expect(spy.mock.calls[11][0]).toEqual("fizz"); 34 | expect(spy.mock.calls[12][0]).toEqual(13); 35 | expect(spy.mock.calls[13][0]).toEqual(14); 36 | expect(spy.mock.calls[14][0]).toEqual("fizzbuzz"); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /src/02-capitalize/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Capitalize 3 | * 4 | * Write a function that accepts a string. The function should 5 | * capitalize the first letter of each word in the string then 6 | * return the capitalized string. 7 | * 8 | * Examples: 9 | * capitalize('a short sentence') === 'A Short Sentence' 10 | * capitalize('a lazy fox') === 'A Lazy Fox' 11 | * capitalize('look, it is working!') === 'Look, It Is Working!' 12 | */ 13 | 14 | function capitalize(str: string) {} 15 | 16 | export { capitalize }; 17 | -------------------------------------------------------------------------------- /src/02-capitalize/test.ts: -------------------------------------------------------------------------------- 1 | import { capitalize } from "./index"; 2 | 3 | describe("Capitalize function", () => { 4 | test("should capitalize the first letter of every word", () => { 5 | expect(capitalize("hi there, how is it going?")).toEqual( 6 | "Hi There, How Is It Going?" 7 | ); 8 | expect(capitalize("i love breakfast at bill miller bbq")).toEqual( 9 | "I Love Breakfast At Bill Miller Bbq" 10 | ); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/03-is-even/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Is Even 3 | * 4 | * Determine if given number is even 5 | * without using any mathematic operators ( +, -, %, /, Math, ParseInt etc.) 6 | * 7 | * Examples: 8 | * isEven(4) === true 9 | * isEven(3) === false 10 | */ 11 | 12 | function isEven(n: number) {} 13 | 14 | export { isEven }; 15 | -------------------------------------------------------------------------------- /src/03-is-even/test.ts: -------------------------------------------------------------------------------- 1 | import { isEven } from "./index"; 2 | 3 | describe("IsEven function", () => { 4 | test("should return true if passed number is even and false if is not", () => { 5 | expect(isEven(234)).toBeTruthy(); 6 | expect(isEven(33)).toBeFalsy(); 7 | expect(isEven(-2)).toBeTruthy(); 8 | expect(isEven(0.15)).toBeTruthy(); 9 | expect(isEven(3092348903.28409238409)).toBeFalsy(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/04-longest-word/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Longest Word 3 | * 4 | * Write a function that returns the longest word in the passed sentence. 5 | * If there are two or more words that are the same length, return 6 | * the first word from the string with that length. Ignore punctuation 7 | * and assume sentence will not be empty. 8 | * 9 | * Examples: 10 | * longestWord("Hello there") === "Hello" 11 | * longestWord("My name is Adam") === "name" 12 | * longestWord("fun&!! time") === "time" 13 | */ 14 | 15 | function longestWord(sen: string) {} 16 | 17 | export { longestWord }; 18 | -------------------------------------------------------------------------------- /src/04-longest-word/test.ts: -------------------------------------------------------------------------------- 1 | import { longestWord } from "./index"; 2 | 3 | describe("LongestWord function", () => { 4 | test("should return first, longest word in passed string", () => { 5 | expect(longestWord("Hello there")).toEqual("Hello"); 6 | expect(longestWord("My name is Adam")).toEqual("name"); 7 | expect(longestWord("fun&!! time")).toEqual("time"); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/05-reverse-string/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Reverse String 3 | * 4 | * For given string return a new string 5 | * with the reversed order of characters. 6 | * 7 | * Examples: 8 | * reverse('apple') === 'elppa' 9 | * reverse('hello') === 'olleh' 10 | * reverse('Greetings!') === '!sgniteerG' 11 | */ 12 | 13 | function reverse(str: string) {} 14 | 15 | export { reverse }; 16 | -------------------------------------------------------------------------------- /src/05-reverse-string/test.ts: -------------------------------------------------------------------------------- 1 | import { reverse } from "./index"; 2 | 3 | describe("Reverse function", () => { 4 | test("should return passed string with the reversed order of characters", () => { 5 | expect(reverse("abcd")).toEqual("dcba"); 6 | expect(reverse(" abcd")).toEqual("dcba "); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /src/06-palindrome/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Palindrome 3 | * 4 | * For given string return true if the string is a palindrome 5 | * or false if it is not. 6 | * 7 | * Palindromes are strings that form the same word if it is reversed. 8 | * Include spaces and punctuation in determining if the string 9 | * is a palindrome. 10 | * 11 | * Examples: 12 | * palindrome("abba") === true 13 | * palindrome("abcdefg") === false 14 | */ 15 | 16 | function palindrome(str: string) {} 17 | 18 | export { palindrome }; 19 | -------------------------------------------------------------------------------- /src/06-palindrome/test.ts: -------------------------------------------------------------------------------- 1 | import { palindrome } from "./index"; 2 | 3 | describe("Palindrome function", () => { 4 | test("should return true if passed string is a palindrome", () => { 5 | expect(palindrome("aba")).toBeTruthy(); 6 | expect(palindrome("1000000001")).toBeTruthy(); 7 | expect(palindrome("pennep")).toBeTruthy(); 8 | }); 9 | 10 | test("should return false if passed string is not a palindrome", () => { 11 | expect(palindrome(" aba")).toBeFalsy(); 12 | expect(palindrome("aba ")).toBeFalsy(); 13 | expect(palindrome("Fish hsif")).toBeFalsy(); 14 | expect(palindrome("greetings")).toBeFalsy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/07-reverse-integer/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Reverse Integer 3 | * 4 | * For given integer return an integer that is the reverse 5 | * ordering of numbers. 6 | * 7 | * Examples: 8 | * reverseInt(15) === 51 9 | * reverseInt(981) === 189 10 | * reverseInt(500) === 5 11 | * reverseInt(-15) === -51 12 | * reverseInt(-90) === -9 13 | */ 14 | 15 | function reverse(int: number) {} 16 | 17 | export { reverse }; 18 | -------------------------------------------------------------------------------- /src/07-reverse-integer/test.ts: -------------------------------------------------------------------------------- 1 | import { reverse } from "./index"; 2 | 3 | describe("Reverse function", () => { 4 | test("should return integer that is the reverse ordering of numbers", () => { 5 | expect(reverse(500)).toEqual(5); 6 | expect(reverse(2394)).toEqual(4932); 7 | expect(reverse(-200)).toEqual(-2); 8 | expect(reverse(-324)).toEqual(-423); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /src/08-vowels/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Vowels 3 | * 4 | * Write a function which returns number of vowels in given string. 5 | * 6 | * Examples: 7 | * vowels('aeiou') === 5 8 | * vowels('Adam') === 2 9 | * vowels('Hello there!') === 4 10 | */ 11 | 12 | function vowels(s: string) {} 13 | 14 | export { vowels }; 15 | -------------------------------------------------------------------------------- /src/08-vowels/test.ts: -------------------------------------------------------------------------------- 1 | import { vowels } from "./index"; 2 | 3 | describe("Vowels function", () => { 4 | test("should return correct number of vowels in given string", () => { 5 | expect(vowels("aeiou")).toEqual(5); 6 | expect(vowels("Adam")).toEqual(2); 7 | expect(vowels("Hello there!")).toEqual(4); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /src/09-anagrams/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Anagrams 3 | * 4 | * Return true of false depends on provided strings are anagrams of eachother. 5 | * One string is an anagram of another if it uses the same characters 6 | * in the same quantity. Only consider characters, not spaces 7 | * or punctuation. Consider capital letters to be the same as lower case. 8 | * 9 | * Examples: 10 | * anagrams('rail safety', 'fairy tales') === true 11 | * anagrams('RAIL! SAFETY!', 'fairy tales') === true 12 | * anagrams('Hi there', 'Bye there') === false 13 | */ 14 | 15 | function anagrams(stringA: string, stringB: string) {} 16 | 17 | export { anagrams }; 18 | -------------------------------------------------------------------------------- /src/09-anagrams/test.ts: -------------------------------------------------------------------------------- 1 | import { anagrams } from "./index"; 2 | 3 | describe("Anagrams function", () => { 4 | test("should return true if passed string is an anagram", () => { 5 | expect(anagrams("hello", "llohe")).toBeTruthy(); 6 | expect(anagrams("Whoa! Hi!", "Hi! Whoa!")).toBeTruthy(); 7 | expect(anagrams("RAIL! SAFETY!", "fairy tales")).toBeTruthy(); 8 | }); 9 | 10 | test("should return false if passed string is not an anagram", () => { 11 | expect(anagrams("One One", "Two two two")).toBeFalsy(); 12 | expect(anagrams("One one", "One one c")).toBeFalsy(); 13 | expect( 14 | anagrams("A tree, a life, a bench", "A tree, a fence, a yard") 15 | ).toBeFalsy(); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/10-armstrong-numbers/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. 3 | * 4 | * For example: 5 | * 6 | * 9 is an Armstrong number, because 9 = 9^1 = 9 7 | * 10 is not an Armstrong number, because 10 != 1^2 + 0^2 = 1 8 | * 153 is an Armstrong number, because: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 9 | * 154 is not an Armstrong number, because: 154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190 10 | * 11 | * Write some code to determine whether a number is an Armstrong number. 12 | */ 13 | 14 | function validate(n: number) {} 15 | 16 | export { validate }; 17 | -------------------------------------------------------------------------------- /src/10-armstrong-numbers/test.ts: -------------------------------------------------------------------------------- 1 | import { validate } from "./index"; 2 | 3 | describe("ArmstrongNumber", () => { 4 | test("Single digit numbers are Armstrong numbers", () => { 5 | const input = 5; 6 | expect(validate(input)).toBe(true); 7 | }); 8 | 9 | test("There are no 2 digit Armstrong numbers", () => { 10 | const input = 10; 11 | expect(validate(input)).toBe(false); 12 | }); 13 | 14 | test("Three digit number that is an Armstrong number", () => { 15 | const input = 153; 16 | expect(validate(input)).toBe(true); 17 | }); 18 | 19 | test("Three digit number that is not an Armstrong number", () => { 20 | const input = 100; 21 | expect(validate(input)).toBe(false); 22 | }); 23 | 24 | test("Four digit number that is an Armstrong number", () => { 25 | const input = 9474; 26 | expect(validate(input)).toBe(true); 27 | }); 28 | 29 | test("Four digit number that is not an Armstrong number", () => { 30 | const input = 9475; 31 | expect(validate(input)).toBe(false); 32 | }); 33 | 34 | test("Seven digit number that is an Armstrong number", () => { 35 | const input = 9926315; 36 | expect(validate(input)).toBe(true); 37 | }); 38 | 39 | test("Seven digit number that is not an Armstrong number", () => { 40 | const input = 9926314; 41 | expect(validate(input)).toBe(false); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /src/11-collatz-conjecture/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The Collatz Conjecture or 3x+1 problem can be summarized as follows: 3 | * 4 | * Take any positive integer n. If n is even, divide n by 2 to get n / 2. If n is odd, multiply n by 3 and add 1 to get 3n + 1. Repeat the process indefinitely. The conjecture states that no matter which number you start with, you will always reach 1 eventually. 5 | * 6 | * Given a number n, return the number of steps required to reach 1. 7 | * 8 | * Examples: 9 | * Starting with n = 12, the steps would be as follows: 10 | * 11 | * 0. 12 12 | * 1. 6 13 | * 2. 3 14 | * 3. 10 15 | * 4. 5 16 | * 5. 16 17 | * 6. 8 18 | * 7. 4 19 | * 8. 2 20 | * 9. 1 21 | * 22 | * Resulting in 9 steps. So for input n = 12, the return value would be 9. 23 | */ 24 | 25 | function steps(n: number) {} 26 | 27 | export { steps }; 28 | -------------------------------------------------------------------------------- /src/11-collatz-conjecture/test.ts: -------------------------------------------------------------------------------- 1 | import { steps } from "./index"; 2 | 3 | describe("steps()", () => { 4 | test("zero steps for one", () => { 5 | expect(steps(1)).toEqual(0); 6 | }); 7 | 8 | test("divide if even", () => { 9 | expect(steps(16)).toEqual(4); 10 | }); 11 | 12 | test("even and odd steps", () => { 13 | expect(steps(12)).toEqual(9); 14 | }); 15 | 16 | test("Large number of even and odd steps", () => { 17 | expect(steps(1000000)).toEqual(152); 18 | }); 19 | 20 | test("zero is an error", () => { 21 | expect(() => { 22 | steps(0); 23 | }).toThrow(new Error("Only positive numbers are allowed")); 24 | }); 25 | 26 | test("negative value is an error", () => { 27 | expect(() => { 28 | steps(-15); 29 | }).toThrow(new Error("Only positive numbers are allowed")); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /src/12-queue/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Queue 3 | * 4 | * Create a queue data structure. The queue 5 | * should be a class with methods 'add' and 'remove'. 6 | * Adding to the queue should store an element until 7 | * it is removed. 8 | * 9 | * Examples: 10 | * const q = new Queue(); 11 | * q.add(1); 12 | * q.remove(); // returns 1 13 | */ 14 | 15 | class Queue { 16 | add(n: number) {} 17 | 18 | remove() {} 19 | } 20 | 21 | export { Queue }; 22 | -------------------------------------------------------------------------------- /src/12-queue/test.ts: -------------------------------------------------------------------------------- 1 | import { Queue } from "./index"; 2 | 3 | describe("Queue class", () => { 4 | test("should be able to add elements to a queue", () => { 5 | const q = new Queue(); 6 | expect(() => { 7 | q.add(1); 8 | }).not.toThrow(); 9 | }); 10 | 11 | test("should be able to remove elements from a queue", () => { 12 | const q = new Queue(); 13 | expect(() => { 14 | q.add(1); 15 | q.remove(); 16 | }).not.toThrow(); 17 | }); 18 | 19 | test("should have maintained order of its elements", () => { 20 | const q = new Queue(); 21 | q.add(1); 22 | q.add(2); 23 | q.add(3); 24 | expect(q.remove()).toEqual(1); 25 | expect(q.remove()).toEqual(2); 26 | expect(q.remove()).toEqual(3); 27 | expect(q.remove()).toEqual(undefined); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /src/13-high-scores/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Manage a game player's High Score list. 3 | * 4 | * Your task is to build a high-score component of the classic Frogger game, one of the highest selling and addictive games of all time, and a classic of the arcade era. Your task is to write methods that return the highest score from the list, the last added score and the three highest scores. 5 | */ 6 | 7 | class HighScores { 8 | scores: number[]; 9 | constructor(scores: number[]) { 10 | this.scores = scores; 11 | } 12 | 13 | get latest() { 14 | return 0; 15 | } 16 | 17 | get personalBest() { 18 | return 0; 19 | } 20 | 21 | get personalTopThree() { 22 | return 0; 23 | } 24 | } 25 | 26 | export { HighScores }; 27 | -------------------------------------------------------------------------------- /src/13-high-scores/test.ts: -------------------------------------------------------------------------------- 1 | import { HighScores } from "./index"; 2 | 3 | describe("High Scores Test Suite", () => { 4 | test("List of scores", () => { 5 | const input = [30, 50, 20, 70]; 6 | expect(new HighScores(input).scores).toEqual([30, 50, 20, 70]); 7 | }); 8 | 9 | test("Latest score", () => { 10 | const input = [100, 0, 90, 30]; 11 | expect(new HighScores(input).latest).toEqual(30); 12 | }); 13 | 14 | test("Personal best", () => { 15 | const input = [40, 100, 70]; 16 | expect(new HighScores(input).personalBest).toEqual(100); 17 | }); 18 | 19 | test("Personal top three from a list of scores", () => { 20 | const input = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]; 21 | expect(new HighScores(input).personalTopThree).toEqual([100, 90, 70]); 22 | }); 23 | 24 | test("Personal top highest to lowest", () => { 25 | const input = [20, 10, 30]; 26 | expect(new HighScores(input).personalTopThree).toEqual([30, 20, 10]); 27 | }); 28 | 29 | test("Personal top when there is a tie", () => { 30 | const input = [40, 20, 40, 30]; 31 | expect(new HighScores(input).personalTopThree).toEqual([40, 40, 30]); 32 | }); 33 | 34 | test("Personal top when there are less than 3", () => { 35 | const input = [30, 70]; 36 | expect(new HighScores(input).personalTopThree).toEqual([70, 30]); 37 | }); 38 | 39 | test("Personal top when there is only one", () => { 40 | const input = [40]; 41 | expect(new HighScores(input).personalTopThree).toEqual([40]); 42 | }); 43 | 44 | test("The order of scores is kept", () => { 45 | const input = [10, 100, 20, 10, 0, 30, 40, 70, 50]; 46 | const scores = new HighScores(input); 47 | expect(scores.personalTopThree).toEqual([100, 70, 50]); 48 | expect(scores.latest).toEqual(50); 49 | expect(scores.personalBest).toEqual(100); 50 | expect(scores.latest).toEqual(50); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /src/14-stack/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Stack 3 | * 4 | * Create a stack data structure. The stack 5 | * should be a class with methods 'push', 'pop', and 6 | * 'peek'. Adding an element to the stack should 7 | * store it until it is removed. 8 | * 9 | * Examples: 10 | * const s = new Stack(); 11 | * s.push(1); 12 | * s.push(2); 13 | * s.pop(); // returns 2 14 | * s.pop(); // returns 1 15 | */ 16 | 17 | class Stack { 18 | push(n: number) {} 19 | 20 | pop() {} 21 | 22 | peek() {} 23 | } 24 | 25 | export { Stack }; 26 | -------------------------------------------------------------------------------- /src/14-stack/test.ts: -------------------------------------------------------------------------------- 1 | import { Stack } from "./index"; 2 | 3 | describe("Stack class", () => { 4 | test("should be able to add and remove items", () => { 5 | const s = new Stack(); 6 | s.push(1); 7 | expect(s.pop()).toEqual(1); 8 | s.push(2); 9 | expect(s.pop()).toEqual(2); 10 | }); 11 | 12 | test("should follow `first in, last out` principle", () => { 13 | const s = new Stack(); 14 | s.push(1); 15 | s.push(2); 16 | s.push(3); 17 | expect(s.pop()).toEqual(3); 18 | expect(s.pop()).toEqual(2); 19 | expect(s.pop()).toEqual(1); 20 | }); 21 | 22 | test("should have a peek method which returns the last element but doesn't remove it", () => { 23 | const s = new Stack(); 24 | s.push(1); 25 | s.push(2); 26 | s.push(3); 27 | expect(s.peek()).toEqual(3); 28 | expect(s.pop()).toEqual(3); 29 | expect(s.peek()).toEqual(2); 30 | expect(s.pop()).toEqual(2); 31 | expect(s.peek()).toEqual(1); 32 | expect(s.pop()).toEqual(1); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /src/15-phone-numbers/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Clean up user-entered phone numbers so that they can be sent SMS messages. 3 | * 4 | * The North American Numbering Plan (NANP) is a telephone numbering system used by many countries in North America like the United States, Canada or Bermuda. All NANP-countries share the same international country code: 1. 5 | * 6 | * NANP numbers are ten-digit numbers consisting of a three-digit Numbering Plan Area code, commonly known as area code, followed by a seven-digit local number. The first three digits of the local number represent the exchange code, followed by the unique four-digit number which is the subscriber number. 7 | * 8 | * The format is usually represented as: 9 | * 10 | * (NXX)-NXX-XXXX 11 | * 12 | * where N is any digit from 2 through 9 and X is any digit from 0 through 9. 13 | * 14 | * Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code (1) if present. 15 | * 16 | * For example, the inputs: 17 | * 18 | * +1 (613)-995-0253 19 | * 613-995-0253 20 | * 1 613 995 0253 21 | * 613.995.0253 22 | * 23 | * should all produce the output: 24 | * 25 | * 6139950253 26 | * 27 | * Note: As this exercise only deals with telephone numbers used in NANP-countries, only 1 is considered a valid country code. 28 | */ 29 | 30 | class PhoneNumber { 31 | constructor(input: string) {} 32 | 33 | number() { 34 | return ""; 35 | } 36 | } 37 | 38 | export { PhoneNumber }; 39 | -------------------------------------------------------------------------------- /src/15-phone-numbers/test.ts: -------------------------------------------------------------------------------- 1 | import { PhoneNumber } from "./index"; 2 | 3 | describe("PhoneNumber()", () => { 4 | test("cleans the number", () => { 5 | const phone = new PhoneNumber("(223) 456-7890"); 6 | expect(phone.number()).toEqual("2234567890"); 7 | }); 8 | 9 | test("cleans numbers with dots", () => { 10 | const phone = new PhoneNumber("223.456.7890"); 11 | expect(phone.number()).toEqual("2234567890"); 12 | }); 13 | 14 | test("cleans numbers with multiple spaces", () => { 15 | const phone = new PhoneNumber("223 456 7890 "); 16 | expect(phone.number()).toEqual("2234567890"); 17 | }); 18 | 19 | test("invalid when 9 digits", () => { 20 | const phone = new PhoneNumber("223456789"); 21 | expect(phone.number()).toEqual(null); 22 | }); 23 | 24 | test("invalid when 11 digits does not start with a 1", () => { 25 | const phone = new PhoneNumber("22234567890"); 26 | expect(phone.number()).toEqual(null); 27 | }); 28 | 29 | test("valid when 11 digits and starting with 1", () => { 30 | const phone = new PhoneNumber("12234567890"); 31 | expect(phone.number()).toEqual("2234567890"); 32 | }); 33 | 34 | test("valid when 11 digits and starting with 1 even with punctuation", () => { 35 | const phone = new PhoneNumber("+1 (223) 456-7890"); 36 | expect(phone.number()).toEqual("2234567890"); 37 | }); 38 | 39 | test("invalid when 12 digits", () => { 40 | const phone = new PhoneNumber("322234567890"); 41 | expect(phone.number()).toEqual(null); 42 | }); 43 | 44 | test("invalid with letters", () => { 45 | const phone = new PhoneNumber("223-abc-7890"); 46 | expect(phone.number()).toEqual(null); 47 | }); 48 | 49 | test("invalid with punctuations", () => { 50 | const phone = new PhoneNumber("223-@:!-7890"); 51 | expect(phone.number()).toEqual(null); 52 | }); 53 | 54 | test("invalid if area code starts with 0 or 1", () => { 55 | const phone1 = new PhoneNumber("(023) 456-7890"); 56 | const phone2 = new PhoneNumber("(123) 456-7890"); 57 | expect(phone1.number()).toEqual(null); 58 | expect(phone2.number()).toEqual(null); 59 | }); 60 | 61 | test("invalid if exchange code starts with 0 or 1", () => { 62 | const phone1 = new PhoneNumber("(223) 056-7890"); 63 | const phone2 = new PhoneNumber("(223) 156-7890"); 64 | expect(phone1.number()).toEqual(null); 65 | expect(phone2.number()).toEqual(null); 66 | }); 67 | 68 | test( 69 | "invalid when 11 digits starting with 1, " + 70 | "but invalid area/exchange code first digits", 71 | () => { 72 | const phone1 = new PhoneNumber("1 (023) 456-7890"); 73 | const phone2 = new PhoneNumber("1 (123) 456-7890"); 74 | const phone3 = new PhoneNumber("1 (223) 056-7890"); 75 | const phone4 = new PhoneNumber("1 (223) 156-7890"); 76 | expect(phone1.number()).toEqual(null); 77 | expect(phone2.number()).toEqual(null); 78 | expect(phone3.number()).toEqual(null); 79 | expect(phone4.number()).toEqual(null); 80 | } 81 | ); 82 | }); 83 | -------------------------------------------------------------------------------- /src/16-second-largest/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Second Largest 3 | * 4 | * Array of numbers are passed in the function, your task is to find the second largest number. 5 | */ 6 | 7 | function secondLargest(array: number[]) {} 8 | 9 | export { secondLargest }; 10 | -------------------------------------------------------------------------------- /src/16-second-largest/test.ts: -------------------------------------------------------------------------------- 1 | import { secondLargest } from "./index"; 2 | 3 | test("secondLargest()", function() { 4 | const numbers = [2, 0, 23, 0, 57, 1, 230]; 5 | 6 | const output = secondLargest(numbers); 7 | 8 | expect(output).toEqual(57); 9 | }); 10 | -------------------------------------------------------------------------------- /src/17-max-char/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Max Char 3 | * 4 | * For given string return the character that is most 5 | * commonly used in the string. 6 | * 7 | * Examples: 8 | * maxChar("abcccccccd") === "c" 9 | * maxChar("apple 1231111") === "1" 10 | */ 11 | 12 | function maxChar(str: string) {} 13 | 14 | export { maxChar }; 15 | -------------------------------------------------------------------------------- /src/17-max-char/test.ts: -------------------------------------------------------------------------------- 1 | import { maxChar } from "./index"; 2 | 3 | describe("MaxChar function", () => { 4 | test("should find the most commonly used char in passed string", () => { 5 | expect(maxChar("a")).toEqual("a"); 6 | expect(maxChar("abcdefghijklmnaaaaa")).toEqual("a"); 7 | expect(maxChar("ab1c1d1e1f1g1")).toEqual("1"); 8 | expect(maxChar("ascxzsdlk29999999999")).toEqual("9"); 9 | expect(maxChar("ascxxc..xcsd.......we12..")).toEqual("."); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /src/18-pyramid/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Pyramid 3 | * 4 | * Write a function that accepts a positive number N. 5 | * The function should print a pyramid shape 6 | * with N levels using the # character. 7 | * 8 | * Examples: 9 | * pyramid(1) = '#' 10 | * 11 | * pyramid(2) = ' # ' 12 | * '###' 13 | * 14 | * pyramid(3) = ' # ' 15 | * ' ### ' 16 | * '#####' 17 | */ 18 | 19 | function pyramid(n: number) {} 20 | 21 | export { pyramid }; 22 | -------------------------------------------------------------------------------- /src/18-pyramid/test.ts: -------------------------------------------------------------------------------- 1 | import { pyramid } from "./index"; 2 | 3 | describe("Pyramin function", () => { 4 | let spy: jest.SpyInstance; 5 | beforeEach(() => { 6 | spy = jest.spyOn(console, "log"); 7 | }); 8 | 9 | afterEach(() => { 10 | spy.mockRestore(); 11 | }); 12 | 13 | test("should prints a pryamid when called with 2", () => { 14 | pyramid(2); 15 | expect(spy.mock.calls[0][0]).toEqual(" # "); 16 | expect(spy.mock.calls[1][0]).toEqual("###"); 17 | expect(spy.mock.calls.length).toEqual(2); 18 | }); 19 | 20 | test("should prints a pryamid when called with 3", () => { 21 | pyramid(3); 22 | expect(spy.mock.calls[0][0]).toEqual(" # "); 23 | expect(spy.mock.calls[1][0]).toEqual(" ### "); 24 | expect(spy.mock.calls[2][0]).toEqual("#####"); 25 | expect(spy.mock.calls.length).toEqual(3); 26 | }); 27 | 28 | test("should prints a pryamid when called with 4", () => { 29 | pyramid(4); 30 | expect(spy.mock.calls[0][0]).toEqual(" # "); 31 | expect(spy.mock.calls[1][0]).toEqual(" ### "); 32 | expect(spy.mock.calls[2][0]).toEqual(" ##### "); 33 | expect(spy.mock.calls[3][0]).toEqual("#######"); 34 | expect(spy.mock.calls.length).toEqual(4); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /src/19-word-count/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Given a phrase, count the occurrences of each word in that phrase. 3 | * 4 | * For example for the input "olly olly in come free" 5 | * 6 | * olly: 2 7 | * in: 1 8 | * come: 1 9 | * free: 1 10 | */ 11 | 12 | class Words { 13 | count(str: string) {} 14 | } 15 | 16 | export { Words }; 17 | -------------------------------------------------------------------------------- /src/19-word-count/test.ts: -------------------------------------------------------------------------------- 1 | import { Words } from "./index"; 2 | 3 | describe("words()", () => { 4 | const words = new Words(); 5 | 6 | test("counts one word", () => { 7 | const expectedCounts = { word: 1 }; 8 | expect(words.count("word")).toEqual(expectedCounts); 9 | }); 10 | 11 | test("counts one of each", () => { 12 | const expectedCounts = { one: 1, of: 1, each: 1 }; 13 | expect(words.count("one of each")).toEqual(expectedCounts); 14 | }); 15 | 16 | test("counts multiple occurrences", () => { 17 | const expectedCounts = { 18 | one: 1, 19 | fish: 4, 20 | two: 1, 21 | red: 1, 22 | blue: 1 23 | }; 24 | expect(words.count("one fish two fish red fish blue fish")).toEqual( 25 | expectedCounts 26 | ); 27 | }); 28 | 29 | test("includes punctuation", () => { 30 | const expectedCounts = { 31 | car: 1, 32 | ":": 2, 33 | carpet: 1, 34 | as: 1, 35 | java: 1, 36 | "javascript!!&@$%^&": 1 37 | }; 38 | expect(words.count("car : carpet as java : javascript!!&@$%^&")).toEqual( 39 | expectedCounts 40 | ); 41 | }); 42 | 43 | test("includes numbers", () => { 44 | const expectedCounts = { testing: 2, 1: 1, 2: 1 }; 45 | expect(words.count("testing 1 2 testing")).toEqual(expectedCounts); 46 | }); 47 | 48 | test("normalizes to lower case", () => { 49 | const expectedCounts = { go: 3 }; 50 | expect(words.count("go Go GO")).toEqual(expectedCounts); 51 | }); 52 | 53 | test("counts properly international characters", () => { 54 | const expectedCounts = { 55 | "¡hola!": 1, 56 | "¿qué": 1, 57 | "tal?": 1, 58 | "привет!": 1 59 | }; 60 | expect(words.count("¡Hola! ¿Qué tal? Привет!")).toEqual(expectedCounts); 61 | }); 62 | 63 | test("counts multiline", () => { 64 | const expectedCounts = { hello: 1, world: 1 }; 65 | expect(words.count("hello\nworld")).toEqual(expectedCounts); 66 | }); 67 | 68 | test("counts tabs", () => { 69 | const expectedCounts = { hello: 1, world: 1 }; 70 | expect(words.count("hello\tworld")).toEqual(expectedCounts); 71 | }); 72 | 73 | test("counts multiple spaces as one", () => { 74 | const expectedCounts = { hello: 1, world: 1 }; 75 | expect(words.count("hello world")).toEqual(expectedCounts); 76 | }); 77 | 78 | test("does not count leading or trailing whitespace", () => { 79 | const expectedCounts = { introductory: 1, course: 1 }; 80 | expect(words.count("\t\tIntroductory Course ")).toEqual( 81 | expectedCounts 82 | ); 83 | }); 84 | 85 | test("handles properties that exist on Object’s prototype", () => { 86 | const expectedCounts = { 87 | reserved: 1, 88 | words: 1, 89 | like: 1, 90 | constructor: 1, 91 | and: 1, 92 | tostring: 1, 93 | "ok?": 1 94 | }; 95 | expect( 96 | words.count("reserved words like constructor and toString ok?") 97 | ).toEqual(expectedCounts); 98 | }); 99 | }); 100 | -------------------------------------------------------------------------------- /src/20-steps/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Steps 3 | * 4 | * Write a function that accepts a positive number N. 5 | * The function should prints a step shape 6 | * with N levels using the '#' character. 7 | * 8 | * Examples: 9 | * steps(2) = '# ' 10 | * '##' 11 | * 12 | * steps(3) = '# ' 13 | * '## ' 14 | * '###' 15 | * 16 | * steps(4) = '# ' 17 | * '## ' 18 | * '### ' 19 | * '####' 20 | */ 21 | 22 | function steps(n: number) {} 23 | 24 | export { steps }; 25 | -------------------------------------------------------------------------------- /src/20-steps/test.ts: -------------------------------------------------------------------------------- 1 | import { steps } from "./index"; 2 | 3 | describe("Steps function", () => { 4 | let spy: jest.SpyInstance; 5 | beforeEach(() => { 6 | spy = jest.spyOn(console, "log"); 7 | }); 8 | 9 | afterEach(() => { 10 | spy.mockRestore(); 11 | }); 12 | 13 | test("should prints steps when called with 1", () => { 14 | steps(1); 15 | expect(spy.mock.calls[0][0]).toEqual("#"); 16 | expect(spy.mock.calls.length).toEqual(1); 17 | }); 18 | 19 | test("should prints steps when called with 2", () => { 20 | steps(2); 21 | expect(spy.mock.calls[0][0]).toEqual("# "); 22 | expect(spy.mock.calls[1][0]).toEqual("##"); 23 | expect(spy.mock.calls.length).toEqual(2); 24 | }); 25 | 26 | test("should prints steps when called with 3", () => { 27 | steps(3); 28 | expect(spy.mock.calls[0][0]).toEqual("# "); 29 | expect(spy.mock.calls[1][0]).toEqual("## "); 30 | expect(spy.mock.calls[2][0]).toEqual("###"); 31 | expect(spy.mock.calls.length).toEqual(3); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /src/21-matrix/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Matrix 3 | * Given a string representing a matrix of numbers, return the rows and columns of that matrix. 4 | * 5 | * So given a string with embedded newlines like: 6 | * 7 | * 9 8 7 8 | * 5 3 2 9 | * 6 6 7 10 | * 11 | * representing this matrix: 12 | * 13 | * 1 2 3 14 | * |--------- 15 | * 1 | 9 8 7 16 | * 2 | 5 3 2 17 | * 3 | 6 6 7 18 | * 19 | * your code should be able to spit out: 20 | * 21 | * A list of the rows, reading each row left-to-right while moving top-to-bottom across the rows, 22 | * A list of the columns, reading each column top-to-bottom while moving from left-to-right. 23 | * 24 | * The rows for our example matrix: 25 | * 26 | * 9, 8, 7 27 | * 5, 3, 2 28 | * 6, 6, 7 29 | * 30 | * And its columns: 31 | * 32 | * 9, 5, 6 33 | * 8, 3, 6 34 | * 7, 2, 7 35 | */ 36 | 37 | class Matrix { 38 | constructor(private matrix: string) {} 39 | 40 | get rows() { 41 | return []; 42 | } 43 | 44 | get columns() { 45 | return []; 46 | } 47 | } 48 | 49 | export { Matrix }; 50 | -------------------------------------------------------------------------------- /src/21-matrix/test.ts: -------------------------------------------------------------------------------- 1 | import { Matrix } from "./index"; 2 | 3 | describe("Matrix", () => { 4 | test("extract row from one number matrix", () => { 5 | expect(new Matrix("1").rows[0]).toEqual([1]); 6 | }); 7 | 8 | test("can extract row", () => { 9 | expect(new Matrix("1 2\n3 4").rows[1]).toEqual([3, 4]); 10 | }); 11 | 12 | test("extract row where numbers have different widths", () => { 13 | expect(new Matrix("1 2\n10 20").rows[1]).toEqual([10, 20]); 14 | }); 15 | 16 | test("can extract row from non-square matrix", () => { 17 | expect(new Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6").rows[2]).toEqual([7, 8, 9]); 18 | }); 19 | 20 | test("extract column from one number matrix", () => { 21 | expect(new Matrix("1").columns[0]).toEqual([1]); 22 | }); 23 | 24 | test("can extract column", () => { 25 | expect(new Matrix("1 2 3\n4 5 6\n7 8 9").columns[2]).toEqual([3, 6, 9]); 26 | }); 27 | 28 | test("can extract column from non-square matrix", () => { 29 | expect(new Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6").columns[2]).toEqual([ 30 | 3, 31 | 6, 32 | 9, 33 | 6 34 | ]); 35 | }); 36 | 37 | test("extract column where numbers have different widths", () => { 38 | expect(new Matrix("89 1903 3\n18 3 1\n9 4 800").columns[1]).toEqual([ 39 | 1903, 40 | 3, 41 | 4 42 | ]); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "noImplicitAny": true, 10 | "strictNullChecks": true, 11 | "strictFunctionTypes": true, 12 | "strictPropertyInitialization": true, 13 | "noImplicitThis": true, 14 | "noImplicitReturns": true, 15 | "alwaysStrict": true, 16 | "allowJs": true, 17 | "skipLibCheck": true, 18 | "esModuleInterop": true, 19 | "allowSyntheticDefaultImports": true, 20 | "strict": true, 21 | "forceConsistentCasingInFileNames": true, 22 | "module": "esnext", 23 | "moduleResolution": "node", 24 | "resolveJsonModule": true, 25 | "isolatedModules": false, 26 | "noEmit": true, 27 | "jsx": "preserve" 28 | } 29 | } --------------------------------------------------------------------------------