Skip to content

Instantly share code, notes, and snippets.

@ChrisDobby
Created March 6, 2023 17:11
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 ChrisDobby/88d66ab496bfef1f5522924a39f8c4e3 to your computer and use it in GitHub Desktop.
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)
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