1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-05-18 12:02:53 +02:00

feat: rewrite programming-challenges CLI (#3)

This commit is contained in:
Divlo
2021-06-09 20:31:45 +02:00
committed by GitHub
parent 7aa12f313e
commit 677a55a9d8
256 changed files with 16829 additions and 1881 deletions

View File

@@ -8,4 +8,4 @@ You are given an array (which will have a length of at least 3, but could be ver
## Examples
See the `input-output.json` file for examples of input/output.
See the `test` folder for examples of input/output.

View File

@@ -1,26 +0,0 @@
[
{
"input": [[2, 4, 0, 100, 4, 11, 2602, 36]],
"output": 11
},
{
"input": [[160, 3, 1719, 19, 11, 13, -21]],
"output": 160
},
{
"input": [[0, 1, 2]],
"output": 1
},
{
"input": [[1, 2, 3]],
"output": 2
},
{
"input": [[2, 6, 8, 10, 3]],
"output": 3
},
{
"input": [[1, 1, 0, 1, 1]],
"output": 0
}
]

View File

@@ -1,5 +0,0 @@
# typescript-outlier - find-outlier-number
Programming language : TypeScript
Created by [@Divlo](https://github.com/Divlo) on 5 July 2020.

View File

@@ -0,0 +1,3 @@
# find-outlier-number/typescript/function
Created by [@Divlo](https://github.com/Divlo) on 6 June 2021.

View File

@@ -1,26 +1,35 @@
import readline from 'readline'
const input: string[] = []
const readlineInterface = readline.createInterface({
input: process.stdin,
output: process.stdout
})
readlineInterface.on('line', (value) => {
input.push(value)
})
readlineInterface.on('close', solution)
interface NumberObject {
value: number
index: number
}
function isOdd (number: number): boolean {
const isOdd = (number: number): boolean => {
return number % 2 !== 0
}
function solution (numbers: number[]): number {
function solution() {
const numbers = input.map((value) => Number(value))
const oddNumbers: NumberObject[] = []
const evenNumbers: NumberObject[] = []
numbers.forEach((number, index) => {
const numberObject: NumberObject = { value: number, index }
return isOdd(number)
? oddNumbers.push(numberObject)
: evenNumbers.push(numberObject)
})
const isValueThatDiffersFromOthers =
oddNumbers.length === 1 ? oddNumbers[0] : evenNumbers[0]
return isValueThatDiffersFromOthers.value
console.log(isValueThatDiffersFromOthers.value)
}
export default solution

View File

@@ -0,0 +1,8 @@
2
4
0
100
4
11
2602
36

View File

@@ -0,0 +1 @@
11

View File

@@ -0,0 +1,7 @@
160
3
1719
19
11
13
-21

View File

@@ -0,0 +1 @@
160

View File

@@ -0,0 +1,3 @@
0
1
2

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,3 @@
1
2
3

View File

@@ -0,0 +1 @@
2

View File

@@ -0,0 +1,5 @@
2
6
8
10
3

View File

@@ -0,0 +1 @@
3

View File

@@ -0,0 +1,5 @@
1
1
0
1
1

View File

@@ -0,0 +1 @@
0