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:
@@ -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.
|
||||
|
@@ -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
|
||||
}
|
||||
]
|
@@ -1,5 +0,0 @@
|
||||
# typescript-outlier - find-outlier-number
|
||||
|
||||
Programming language : TypeScript
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 5 July 2020.
|
@@ -0,0 +1,3 @@
|
||||
# find-outlier-number/typescript/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 6 June 2021.
|
@@ -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
|
8
challenges/find-outlier-number/test/1/input.txt
Normal file
8
challenges/find-outlier-number/test/1/input.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
2
|
||||
4
|
||||
0
|
||||
100
|
||||
4
|
||||
11
|
||||
2602
|
||||
36
|
1
challenges/find-outlier-number/test/1/output.txt
Normal file
1
challenges/find-outlier-number/test/1/output.txt
Normal file
@@ -0,0 +1 @@
|
||||
11
|
7
challenges/find-outlier-number/test/2/input.txt
Normal file
7
challenges/find-outlier-number/test/2/input.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
160
|
||||
3
|
||||
1719
|
||||
19
|
||||
11
|
||||
13
|
||||
-21
|
1
challenges/find-outlier-number/test/2/output.txt
Normal file
1
challenges/find-outlier-number/test/2/output.txt
Normal file
@@ -0,0 +1 @@
|
||||
160
|
3
challenges/find-outlier-number/test/3/input.txt
Normal file
3
challenges/find-outlier-number/test/3/input.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
0
|
||||
1
|
||||
2
|
1
challenges/find-outlier-number/test/3/output.txt
Normal file
1
challenges/find-outlier-number/test/3/output.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
3
challenges/find-outlier-number/test/4/input.txt
Normal file
3
challenges/find-outlier-number/test/4/input.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
1
|
||||
2
|
||||
3
|
1
challenges/find-outlier-number/test/4/output.txt
Normal file
1
challenges/find-outlier-number/test/4/output.txt
Normal file
@@ -0,0 +1 @@
|
||||
2
|
5
challenges/find-outlier-number/test/5/input.txt
Normal file
5
challenges/find-outlier-number/test/5/input.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
2
|
||||
6
|
||||
8
|
||||
10
|
||||
3
|
1
challenges/find-outlier-number/test/5/output.txt
Normal file
1
challenges/find-outlier-number/test/5/output.txt
Normal file
@@ -0,0 +1 @@
|
||||
3
|
5
challenges/find-outlier-number/test/6/input.txt
Normal file
5
challenges/find-outlier-number/test/6/input.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
1
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
1
challenges/find-outlier-number/test/6/output.txt
Normal file
1
challenges/find-outlier-number/test/6/output.txt
Normal file
@@ -0,0 +1 @@
|
||||
0
|
Reference in New Issue
Block a user