Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <textarea placeholder="paste your text in for a read out, sorted by most frequent, of the characters used" cols='60' rows='10' id="textarea"></textarea>

<label>Don't count Alpha, space, and newline characters
<input type="checkbox" name="alpha" id="alpha"/>
</label>

<div id='output'></div>
              
            
!

CSS

              
                body {
	font-size: 2em;
	font-family: monospace;
	display: grid;
}

table {
	border-collapse: collapse;
}

label {
	font-size: 1rem;
	margin: 1em;
}

th,
td {
	border: 1px solid #333;
	padding: .3em;
}

              
            
!

JS

              
                const TEXTAREA = document.getElementById("textarea");
const OUT = document.getElementById("output");
// ignore alphas, spaces, and new line characters
const ALPHAS = "abcdefghijklmnopqrstuvwxyz \n";
const isAlphaIgnored = document.getElementById("alpha");

let counter = (str) => {
	return str
		.toLowerCase()
		.split("")
		.reduce((total, letter) => {
			if (isAlphaIgnored.checked) {
				if (!ALPHAS.includes(letter)) {
					total[letter] ? total[letter]++ : (total[letter] = 1);
				}
			} else {
				total[letter] ? total[letter]++ : (total[letter] = 1);
			}
			return total;
		}, {});
};

function sort(obj) {
	return Object.entries(obj).sort((a, b) => b[1] - a[1]);
}

TEXTAREA.addEventListener("input", (e) => {
	let sorted = sort(counter(e.target.value));
	// OUT.textContent = JSON.stringify(sorted);
	console.log(isAlphaIgnored.checked);
	createTable(sorted);
});

// Function to create and fill the table
function createTable(data) {
	// Create table and thead elements
	const table = document.createElement("table");
	const thead = document.createElement("thead");
	const tbody = document.createElement("tbody");
	const headerRow = document.createElement("tr");

	// Define headers
	const headers = ["Character", "Frequency"];
	headers.forEach((headerText) => {
		const header = document.createElement("th");
		header.textContent = headerText;
		headerRow.appendChild(header);
	});

	thead.appendChild(headerRow);
	table.appendChild(thead);

	// Fill the table body with data
	data.forEach((rowData) => {
		const row = document.createElement("tr");
		rowData.forEach((cellData) => {
			const cell = document.createElement("td");
			cell.textContent = cellData;
			row.appendChild(cell);
		});
		tbody.appendChild(row);
	});

	table.appendChild(tbody);

	// Append the table to the container
	document.getElementById("output").innerHTML = table.outerHTML;
}

              
            
!
999px

Console