This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Sort array in asc order using merge-sort | |
| * @example | |
| * sort([3, 2, 1]) => [1, 2, 3] | |
| * sort([3]) => [3] | |
| * sort([3, 2]) => [2, 3] | |
| * @param {array} array | |
| */ | |
| function sort(array = []) { | |
| const size = array.length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function indexOf(array, element, offset = 0) { | |
| // split array in half | |
| const half = parseInt(array.length / 2); | |
| const current = array[half]; | |
| if(current === element) { | |
| return offset + half; | |
| } else if(element > current) { | |
| const right = array.slice(half); | |
| return indexOf(right, element, offset + half); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findXYZ(n) { | |
| const solutions = []; | |
| for(let x = 0; x < n; x++) { | |
| for(let y = 0; y < n; y++) { | |
| for(let z = 0; z < n; z++) { | |
| if( 3*x + 9*y + 8*z === 79 ) { | |
| solutions.push({x, y, z}); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sort(n) { | |
| for (let outer = 0; outer < n.length; outer++) { | |
| let outerElement = n[outer]; | |
| for (let inner = outer + 1; inner < n.length; inner++) { | |
| let innerElement = n[inner]; | |
| if(outerElement > innerElement) { | |
| // swap | |
| n[outer] = innerElement; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function hasDuplicates(n) { | |
| const duplicates = []; | |
| for (let outter = 0; outter < n.length; outter++) { | |
| for (let inner = 0; inner < n.length; inner++) { | |
| if(outter === inner) continue; | |
| if(n[outter] === n[inner]) { | |
| return true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findMax(n) { | |
| let max; | |
| let counter = 0; | |
| for (let i = 0; i < n.length; i++) { | |
| counter++; | |
| if(max === undefined || max < n[i]) { | |
| max = n[i]; | |
| } | |
| } | |
| return max; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const dictionary = {the: 22038615, be: 12545825, and: 10741073, of: 10343885, a: 10144200, in: 6996437, to: 6332195 /* ... */}; | |
| function getWordFrequency(dictionary, word) { | |
| return dictionary[word]; | |
| } | |
| console.log(getWordFrequency(dictionary, 'the')); | |
| console.log(getWordFrequency(dictionary, 'in')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isEvenOrOdd(n) { | |
| return n % 2 ? 'Odd' : 'Even'; | |
| } | |
| console.log(isEvenOrOdd(10)); // => Even | |
| console.log(isEvenOrOdd(10001)); // => Odd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '3.7' | |
| services: | |
| # http://localhost:8187/ | |
| nginx: | |
| # build: . | |
| image: nginx | |
| # container_name: nginx | |
| ports: | |
| - "8187:80" | |
| networks: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://github.com/elastic/stack-docker/blob/06db66617b7c6935df097b59c94a6085bad3de6a/docker-compose.yml | |
| version: '3.6' | |
| services: | |
| # http://localhost:8187/ | |
| nginx: | |
| # build: . | |
| image: nginx | |
| # container_name: nginx | |
| ports: |