From 45216f5b262d083ed6f48eb7e23d36f0b7f07c5f Mon Sep 17 00:00:00 2001 From: tonezone108 Date: Sat, 19 Oct 2019 17:03:52 -0500 Subject: [PATCH] Hackathon --- 06week/hackAThonCountIt.js | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 06week/hackAThonCountIt.js diff --git a/06week/hackAThonCountIt.js b/06week/hackAThonCountIt.js new file mode 100644 index 000000000..f0a947ccb --- /dev/null +++ b/06week/hackAThonCountIt.js @@ -0,0 +1,40 @@ +"use strict"; + +const assert = require("assert"); +const readline = require("readline"); +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +function getPrompt() { + console.log("Type something to find out how many letters"); + rl.question("Word ", answer => { + console.log(CountIt(answer)); + getPrompt(); + }); +} + +function CountIt(word) { + // let string = word.replace(/[.,\/@^*#!$%\^&\*;:{}=\-_`~()]/g, ""); + let string = word.replace(/[^a-zA-Z0-9]/g, ""); + var results = {}; + + for (let i = 0; i < string.length; i++) { + let char = string.charAt(i); + // console.log(char); + if (!(char in results)) { + // console.log("I don't exist"); + // obj["key3"] = "value3"; + results[char] = 1; + } else { + results[char] = results[char] + 1; + // map[key] = (map[key]+1) + // console.log("I do exist"); + } + } + + console.log(results); +} + +getPrompt();