Last active
March 19, 2024 11:51
-
-
Save mrandrewmills/c9eecb3074562ca6f3a74cf76166d137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Updated to use createElement/strong instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.