mirror of
				https://github.com/theoludwig/programming-challenges.git
				synced 2025-09-11 23:11:21 +02:00 
			
		
		
		
	feat(solutions): add sorting-algorithms/javascript/function
				
					
				
			This commit is contained in:
		| @@ -1,17 +1,16 @@ | ||||
| import readline from 'readline' | ||||
|  | ||||
| const input = [] | ||||
| const numbers = [] | ||||
| const readlineInterface = readline.createInterface({ | ||||
|   input: process.stdin, | ||||
|   output: process.stdout | ||||
| }) | ||||
| readlineInterface.on('line', (value) => { | ||||
|   input.push(value) | ||||
|   numbers.push(Number(value)) | ||||
| }) | ||||
| readlineInterface.on('close', solution) | ||||
|  | ||||
| function solution() { | ||||
|   const numbers = input.map((value) => Number(value)) | ||||
|   const sortedNumbers = bubbleSort(numbers.slice(1)) | ||||
|   sortedNumbers.forEach((number) => { | ||||
|     console.log(number) | ||||
|   | ||||
| @@ -0,0 +1,3 @@ | ||||
| # sorting-algorithms/javascript/function | ||||
|  | ||||
| Created by [@Divlo](https://github.com/Divlo) on 30 June 2021. | ||||
| @@ -0,0 +1,3 @@ | ||||
| { | ||||
|   "type": "module" | ||||
| } | ||||
| @@ -0,0 +1,22 @@ | ||||
| import readline from 'readline' | ||||
|  | ||||
| const numbers = [] | ||||
| const readlineInterface = readline.createInterface({ | ||||
|   input: process.stdin, | ||||
|   output: process.stdout | ||||
| }) | ||||
| readlineInterface.on('line', (value) => { | ||||
|   numbers.push(Number(value)) | ||||
| }) | ||||
| readlineInterface.on('close', solution) | ||||
|  | ||||
| function solution() { | ||||
|   const sortedNumbers = nativeSort(numbers.slice(1)) | ||||
|   sortedNumbers.forEach((number) => { | ||||
|     console.log(number) | ||||
|   }) | ||||
| } | ||||
|  | ||||
| function nativeSort (numbers) { | ||||
|   return numbers.sort((number1, number2) => number1 - number2) | ||||
| } | ||||
| @@ -1,17 +1,16 @@ | ||||
| import readline from 'readline' | ||||
|  | ||||
| const input = [] | ||||
| const numbers = [] | ||||
| const readlineInterface = readline.createInterface({ | ||||
|   input: process.stdin, | ||||
|   output: process.stdout | ||||
| }) | ||||
| readlineInterface.on('line', (value) => { | ||||
|   input.push(value) | ||||
|   numbers.push(Number(value)) | ||||
| }) | ||||
| readlineInterface.on('close', solution) | ||||
|  | ||||
| function solution() { | ||||
|   const numbers = input.map((value) => Number(value)) | ||||
|   const sortedNumbers = insertionSort(numbers.slice(1)) | ||||
|   sortedNumbers.forEach((number) => { | ||||
|     console.log(number) | ||||
|   | ||||
| @@ -1,17 +1,16 @@ | ||||
| import readline from 'readline' | ||||
|  | ||||
| const input = [] | ||||
| const numbers = [] | ||||
| const readlineInterface = readline.createInterface({ | ||||
|   input: process.stdin, | ||||
|   output: process.stdout | ||||
| }) | ||||
| readlineInterface.on('line', (value) => { | ||||
|   input.push(value) | ||||
|   numbers.push(Number(value)) | ||||
| }) | ||||
| readlineInterface.on('close', solution) | ||||
|  | ||||
| function solution() { | ||||
|   const numbers = input.map((value) => Number(value)) | ||||
|   const sortedNumbers = mergeSort(numbers.slice(1)) | ||||
|   sortedNumbers.forEach((number) => { | ||||
|     console.log(number) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user