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

              
                <!-- 
TODO: 
Enhacne UI 
add explanation 
-->

<main>
	<div class="header">
		<h3>Random String Iterations</h3>
		<h5>Input a string and number of interations --> submit.</h5>
		<h5> I use this to generate anagrams of my full name for usenames.</h5>
	</div>
	<div class="app--container">
		<div class="input--container">

			<input class="input--text" id="input" type="text" autocomplete="off" placeholder="some string" autofocus name="sting" />
			<input id="permute" type="text" name="permut" size="3" value="5" />
			<button type="submit" id="submit" class="btn btn--submit">Submit</button>
			<button type="submit" id="clear" class="btn btn--clear">Clear</button>
		</div>
		<div class="output--container">
		</div>
	</div>
</main>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Open+Sans&display=swap");

html,
body {
	font-family: "Open Sans", sans-serif;
}

main {
	min-height: 80vh;
	margin: 2rem;
	border-radius: 10px;
	overflow: hidden;
	box-shadow: 2px 2px 20px #c4bdbc, -2px -2px 20px #c4bdbc;
}

h3 {
	font-size: 2rem;
	margin-bottom: 1.5rem;
}
h5 {
	color: #333333;
	margin-bottom: 0.5rem;
	font-size: 1.2rem;
}
.header {
	padding: 2rem;
	background-color: #f5f5f5;
	margin-bottom: 2rem;
	border-bottom-left-radius: 20px;
	border-bottom-right-radius: 20px;
}
input {
	height: 2rem;
	font-size: 1.5rem;
	padding: 0.3rem;
	border: transparent;
}

.app {
	&--container {
		padding: 2rem;
	}
}

.input {
	&--container {
		margin-bottom: 2rem;
		width: 100%;
		display: flex;
		& > * {
			flex-grow: 1;
		}
		.input {
			&--text {
				flex-basis: 60vw;
			}
		}
	}
}

.btn {
	font-weight: 700;
	letter-spacing: 0.2rem;
	text-transform: uppercase;
	border: none;
	padding: 0.5rem;
	padding-left: 1rem;
	padding-right: 1rem;
	border-radius: 10px;
	margin-left: 0.5rem;
	&--submit {
		background-color: #ffd275;
	}
}

.output {
	&--container {
		min-height: 100%;
		min-width: 100%;
	}
}
.item {
	margin-bottom: 1.5rem;
	display: flex;
	cursor: pointer;
	& > div {
		margin-left: 0.5rem;
		& > svg {
			cursor: pointer;
			color: #333333;
		}
	}
}

.icon {
	&--copy {
		transition: all ease-in-out 0.2s;
		&::after {
			margin-left: 0.2rem;
			content: "";
		}
		&:focus,
		&:active {
			&::after {
				content: "copied";
			}
		}
	}
}

              
            
!

JS

              
                const INPUT = document.querySelector("#input");
const SUBMIT = document.querySelector("#submit");
const CLEAR = document.querySelector("#clear");

const output = document.querySelector(".output--container");
const qty = document.querySelector("#permute");

INPUT.addEventListener("keyup", (e) => {});

SUBMIT.addEventListener("click", (e) => {
	e.preventDefault();

	renderResults(INPUT.value, parseInt(qty.value));
	INPUT.value = "";
});

CLEAR.addEventListener("click", (e) => {
	e.preventDefault();
	output.innerHTML = "";
});

function renderResults(str, qty) {
	if (str.length > 0) {
		let resultsArr = new Set();
		while (qty != Array.from(resultsArr).length) {
			let newStr = randomStrings(str);

			resultsArr.add(newStr.join(""));
		}
		addPremuteToDom(resultsArr);
	}
}

function randomStrings(str) {
	let results = [];
	let strArr = str.split("");

	while (strArr.length > 0) {
		let length = strArr.length - 1;

		// get random number within length
		let random = Math.floor(Math.random() * length);

		// get value at random index
		let el = strArr[random];

		// remove value from  original arr
		strArr.splice(random, 1);

		// add to new arr
		results.push(el);
	}
	return results;
}

function addPremuteToDom(arr) {
	if (output.ChildNode != null) {
		output.firstElementChild.remove();
		renderChildren(arr);
	} else {
		renderChildren(arr);
	}
}

function renderChildren(arr) {
	let out = document.createElement("div");
	arr.forEach((el) => {
		let copyIcon = document.createElement("div");
		copyIcon.setAttribute("class", "icon icon--copy");
		let newPermute = document.createElement("div");
		let perCon = document.createElement("p");
		newPermute.addEventListener("click", (e) => {
			let range = document.createRange();
			range.selectNode(e.target);
			window.getSelection().removeAllRanges();
			window.getSelection().addRange(range);
			// newPermute.setSelectionRange(0, 100);
			document.execCommand("copy");
			console.log("target", e.target);
			window.getSelection().removeAllRanges();
		});
		copyIcon.innerHTML = `<i class="fas fa-copy"></i>`;

		perCon.innerHTML = el;
		newPermute.appendChild(copyIcon);
		newPermute.appendChild(perCon);
		newPermute.setAttribute("class", "item");
		out.appendChild(newPermute);
	});
	output.appendChild(out);
}

function clear() {}

              
            
!
999px

Console