Created
March 6, 2023 17:11
-
-
Save ChrisDobby/88d66ab496bfef1f5522924a39f8c4e3 to your computer and use it in GitHub Desktop.
Write a function that takes an input sentence, and mixes up the insides of words (anything longer than 3 letters)
This file contains hidden or 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
const scrambleLetters = (letters: string) => | |
letters | |
.split('') | |
.sort(() => Math.random() - 0.5) | |
.join('') | |
const scramble = (str: string) => | |
str | |
.split(' ') | |
.map(word => (word.length > 3 ? `${word[0]}${scrambleLetters(word.slice(1, word.length - 1))}${word[word.length - 1]}` : word)) | |
.join(' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment