1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-12-08 00:45:29 +01:00

feat(solutions): add sorting-algorithms/javascript/function

This commit is contained in:
Divlo 2021-06-30 12:31:43 +02:00
parent 1dbe602f15
commit b70b089702
No known key found for this signature in database
GPG Key ID: 185ED2F15F104E52
6 changed files with 34 additions and 9 deletions

View File

@ -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)

View File

@ -0,0 +1,3 @@
# sorting-algorithms/javascript/function
Created by [@Divlo](https://github.com/Divlo) on 30 June 2021.

View File

@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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)