Skip to content

Instantly share code, notes, and snippets.

@mrandrewmills
Last active March 19, 2024 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrandrewmills/c9eecb3074562ca6f3a74cf76166d137 to your computer and use it in GitHub Desktop.
Save mrandrewmills/c9eecb3074562ca6f3a74cf76166d137 to your computer and use it in GitHub Desktop.
function bionicizeText(str) {
let phrase = str.split(" ");
let results = [];
results.push(phrase.map(word => bionicizeWord(word)));
return results.join(" ");
function bionicizeWord(w) {
let strong = document.createElement('strong');
strong.textContent = w.slice(0, Math.ceil(w.length / 2));
return strong.outerHTML + w.slice(Math.ceil(w.length / 2));
}
}
bionicizeText("This is a test");
@mrandrewmills
Copy link
Author

Saw one of those "bionic text" promotional posts on SM and thought it would make for an interesting distraction (i.e. coding challenge) to pass an otherwise stressful evening. Not meant to be taken seriously with .bold() etc obviously.

@mrandrewmills
Copy link
Author

Updated to use createElement/strong instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment