meta: initial commit (archival)
This commit is contained in:
12
src/app.html
Normal file
12
src/app.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%svelte.head%
|
||||
</head>
|
||||
<body>
|
||||
<div id="svelte">%svelte.body%</div>
|
||||
</body>
|
||||
</html>
|
4
src/app.postcss
Normal file
4
src/app.postcss
Normal file
@@ -0,0 +1,4 @@
|
||||
@tailwind base;
|
||||
/* Write your global styles here, in PostCSS syntax */
|
||||
@tailwind components;
|
||||
@tailwind utilities
|
1
src/global.d.ts
vendored
Normal file
1
src/global.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="@sveltejs/kit" />
|
2
src/routes/__layout.svelte
Normal file
2
src/routes/__layout.svelte
Normal file
@@ -0,0 +1,2 @@
|
||||
<script>import "../app.postcss";</script>
|
||||
<slot></slot>
|
76
src/routes/index.svelte
Normal file
76
src/routes/index.svelte
Normal file
@@ -0,0 +1,76 @@
|
||||
<script>
|
||||
import {flip} from "svelte/animate";
|
||||
|
||||
let value = "Write input here";
|
||||
$: frequencyInfo = analyzeWords(value);
|
||||
|
||||
/** @param {string} text */
|
||||
const analyzeWords = (text) => {
|
||||
const frequencies = new Map();
|
||||
|
||||
const lines = text.trim().split(/\r?\n/);
|
||||
|
||||
for (const line of lines) {
|
||||
const words = line.trim().split(" ");
|
||||
|
||||
for (const word of words) {
|
||||
if (word === "") continue;
|
||||
const wordClean = word.toLowerCase();
|
||||
frequencies.set(wordClean, (frequencies.get(wordClean) ?? 0) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
const entries = Array.from(frequencies.entries());
|
||||
// Sort alphabetically
|
||||
entries.sort(([aKey, a], [bKey, b]) => aKey.localeCompare(bKey));
|
||||
// Sort by frequency
|
||||
entries.sort(([aKey, a], [bKey, b]) => b - a);
|
||||
|
||||
return entries;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex min-h-screen items-stretch justify-stretch">
|
||||
<textarea class="resize-none flex-1 p-4" bind:value></textarea>
|
||||
<div class="flex-1 bg-gray-100">
|
||||
<table class="w-full p-4">
|
||||
<thead>
|
||||
<tr class="bg-gray-200">
|
||||
<th class="text-right">#</th>
|
||||
<th>Word</th>
|
||||
<th>Frequency</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Array.from(frequencyInfo.entries()) as [index, [word, frequency]] (word)}
|
||||
<tr>
|
||||
<td class="text-right tabular-nums">{index+1}</td>
|
||||
<td class="px-4">{word}</td>
|
||||
<td class="text-right tabular-nums">{frequency}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 bg-gray-100">
|
||||
<table class="w-full p-4">
|
||||
<thead>
|
||||
<tr class="bg-gray-200">
|
||||
<th class="text-right">#</th>
|
||||
<th>Word</th>
|
||||
<th>Frequency</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Array.from(frequencyInfo.entries()) as [index, [word, frequency]] (word)}
|
||||
<tr>
|
||||
<td class="text-right tabular-nums">{index+1}</td>
|
||||
<td class="px-4">{word}</td>
|
||||
<td class="text-right tabular-nums">{frequency}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user