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:
@ -1,5 +0,0 @@
|
||||
# javascript-non-repeating - first-non-repeating-character
|
||||
|
||||
Programming language : JavaScript
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 15 November 2020.
|
@ -0,0 +1,3 @@
|
||||
# first-non-repeating-character/javascript/function
|
||||
|
||||
Created by [@Divlo](https://github.com/Divlo) on 6 June 2021.
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
@ -1,7 +1,16 @@
|
||||
/**
|
||||
* @param {string} string
|
||||
*/
|
||||
function solution (string) {
|
||||
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)
|
||||
|
||||
const firstNonRepeatingCharacter = (string) => {
|
||||
const lettersCount = {}
|
||||
for (let index = 0; index < string.length; index++) {
|
||||
const character = string[index]
|
||||
@ -15,7 +24,6 @@ function solution (string) {
|
||||
lettersCount[character].total += 1
|
||||
}
|
||||
}
|
||||
|
||||
let result = null
|
||||
for (const character in lettersCount) {
|
||||
const characterObject = lettersCount[character]
|
||||
@ -27,11 +35,12 @@ function solution (string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
return ''
|
||||
}
|
||||
return result.value
|
||||
}
|
||||
|
||||
module.exports = solution
|
||||
function solution() {
|
||||
console.log(firstNonRepeatingCharacter(input[0]))
|
||||
}
|
Reference in New Issue
Block a user