update
This commit is contained in:
parent
c296dce683
commit
6896d03214
|
@ -0,0 +1,67 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>How many Letters?</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<textarea id="input" name="input" id="" cols="30" rows="10"></textarea>
|
||||
<button id="submit" type="submit">Submit</button>
|
||||
<h3>Output</h3>
|
||||
<table id="output"></table>
|
||||
</body>
|
||||
|
||||
<style>
|
||||
table,
|
||||
th,
|
||||
td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<script>
|
||||
const btn = document.querySelector("#submit");
|
||||
const textarea = document.querySelector("#input");
|
||||
const table = document.querySelector("#output");
|
||||
|
||||
btn.addEventListener("click", () => {
|
||||
let frequency = getFrequency(textarea.value);
|
||||
output.innerHTML = mapToTableCells(frequency);
|
||||
});
|
||||
|
||||
|
||||
function mapToTableCells(map) {
|
||||
let str = "<tr><th>Character</th><th>Times Appeared</th></tr>";
|
||||
|
||||
for (const pair of map[Symbol.iterator]()) {
|
||||
str += `<tr><td>${pair[0]}</td><td>${pair[1]}</td></tr>`
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
function getFrequency(str) {
|
||||
const freq = new Map();
|
||||
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charAt(i);
|
||||
if (freq.has(char)) {
|
||||
let count = freq.get(char);
|
||||
freq.set(char, count + 1);
|
||||
} else {
|
||||
freq.set(char, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,27 @@
|
|||
# hey bro can I ask for a little help?
|
||||
# I want to figure out a script or sumn that can count and separate the characters in a string of text
|
||||
# like if I enter in dushdhaosbvdiebwb
|
||||
# it’ll tell me how many of which character is in it
|
||||
|
||||
|
||||
# key, value
|
||||
# string, integer
|
||||
# "a": 1
|
||||
#
|
||||
|
||||
|
||||
def main():
|
||||
freq = {}
|
||||
str = input("Enter Text: ")
|
||||
|
||||
for char in str:
|
||||
if char in freq:
|
||||
freq[char] += 1
|
||||
else:
|
||||
freq[char] = 1
|
||||
|
||||
print(freq)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "fizz_buzz"
|
||||
version = "0.1.0"
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "fizz_buzz"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -0,0 +1 @@
|
|||
fn main(){for n in 1..101{let mut m=String::new();if n%3==0{m+="Fizz";}if n%5==0{m+="Buzz";}println!("{}",if m.len()==0{n.to_string()}else{m});}}
|
Loading…
Reference in New Issue