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:
parent
1dbe602f15
commit
b70b089702
@ -1,17 +1,16 @@
|
|||||||
import readline from 'readline'
|
import readline from 'readline'
|
||||||
|
|
||||||
const input = []
|
const numbers = []
|
||||||
const readlineInterface = readline.createInterface({
|
const readlineInterface = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
})
|
})
|
||||||
readlineInterface.on('line', (value) => {
|
readlineInterface.on('line', (value) => {
|
||||||
input.push(value)
|
numbers.push(Number(value))
|
||||||
})
|
})
|
||||||
readlineInterface.on('close', solution)
|
readlineInterface.on('close', solution)
|
||||||
|
|
||||||
function solution() {
|
function solution() {
|
||||||
const numbers = input.map((value) => Number(value))
|
|
||||||
const sortedNumbers = bubbleSort(numbers.slice(1))
|
const sortedNumbers = bubbleSort(numbers.slice(1))
|
||||||
sortedNumbers.forEach((number) => {
|
sortedNumbers.forEach((number) => {
|
||||||
console.log(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'
|
import readline from 'readline'
|
||||||
|
|
||||||
const input = []
|
const numbers = []
|
||||||
const readlineInterface = readline.createInterface({
|
const readlineInterface = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
})
|
})
|
||||||
readlineInterface.on('line', (value) => {
|
readlineInterface.on('line', (value) => {
|
||||||
input.push(value)
|
numbers.push(Number(value))
|
||||||
})
|
})
|
||||||
readlineInterface.on('close', solution)
|
readlineInterface.on('close', solution)
|
||||||
|
|
||||||
function solution() {
|
function solution() {
|
||||||
const numbers = input.map((value) => Number(value))
|
|
||||||
const sortedNumbers = insertionSort(numbers.slice(1))
|
const sortedNumbers = insertionSort(numbers.slice(1))
|
||||||
sortedNumbers.forEach((number) => {
|
sortedNumbers.forEach((number) => {
|
||||||
console.log(number)
|
console.log(number)
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
import readline from 'readline'
|
import readline from 'readline'
|
||||||
|
|
||||||
const input = []
|
const numbers = []
|
||||||
const readlineInterface = readline.createInterface({
|
const readlineInterface = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
})
|
})
|
||||||
readlineInterface.on('line', (value) => {
|
readlineInterface.on('line', (value) => {
|
||||||
input.push(value)
|
numbers.push(Number(value))
|
||||||
})
|
})
|
||||||
readlineInterface.on('close', solution)
|
readlineInterface.on('close', solution)
|
||||||
|
|
||||||
function solution() {
|
function solution() {
|
||||||
const numbers = input.map((value) => Number(value))
|
|
||||||
const sortedNumbers = mergeSort(numbers.slice(1))
|
const sortedNumbers = mergeSort(numbers.slice(1))
|
||||||
sortedNumbers.forEach((number) => {
|
sortedNumbers.forEach((number) => {
|
||||||
console.log(number)
|
console.log(number)
|
||||||
|
Loading…
Reference in New Issue
Block a user