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:
@ -0,0 +1,3 @@
|
||||
# camel-case/javascript/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 6 June 2021.
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
import readline from 'readline'
|
||||
|
||||
const input = []
|
||||
const readlineInterface = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
})
|
||||
readlineInterface.on('line', (value) => {
|
||||
input.push(value)
|
||||
})
|
||||
readlineInterface.on('close', solution)
|
||||
|
||||
function solution() {
|
||||
const string = input[0]
|
||||
const output = string
|
||||
.trim()
|
||||
.split(' ')
|
||||
.map((word, index) => {
|
||||
const isFirstElement = index === 0
|
||||
if (isFirstElement) {
|
||||
return word
|
||||
}
|
||||
return word[0].toUpperCase() + word.slice(1)
|
||||
})
|
||||
.join('')
|
||||
console.log(output)
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
# typescript-camelcase - camel-case
|
||||
|
||||
Programming language : TypeScript
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 5 July 2020.
|
@ -1,14 +0,0 @@
|
||||
function solution (string: string) {
|
||||
return string.length === 0
|
||||
? ''
|
||||
: string
|
||||
.trim()
|
||||
.split(' ')
|
||||
.map((word, index) => {
|
||||
if (index === 0) return word
|
||||
return word[0].toUpperCase() + word.slice(1)
|
||||
})
|
||||
.join('')
|
||||
}
|
||||
|
||||
export default solution
|
Reference in New Issue
Block a user