Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

7 of 7
minor clarifications
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (Node.js), 131 bytes

s=>s.replace(/[a-z]/gi,c=>(s+g(i=B(c)[0]-1)?"":"ei")+(h=j=>g(i)^g(j=-~j%26)?h(j):B([j+1|i&96]))(i&31),B=Buffer,g=i=>s=1065233>>i&1)

Try it online!

Commented

s => s.replace( // replace in the input string s ...
 /[a-z]/gi, c => // ... each letter c (case insensitive)
 ( //
 s + // if the previous letter was a vowel (or this
 // is the 1st iteration and s is still a string)
 g( // or the current letter
 i = // whose ASCII code - 1 is loaded in i
 B(c)[0] - 1 // 
 ) ? // is a vowel:
 "" // append nothing
 : // else:
 "ei" // append "ei"
 ) + ( //
 h = j => // h is a recursive function looking for the
 // replacement letter
 g(i) ^ // if the type of the current letter
 g( // does not match the type of
 j = -~j % 26 // the next letter in the alphabet
 // obtained by incrementing j modulo 26
 ) ? // then:
 h(j) // keep advancing by doing a recursive call
 : // else:
 B([ // output the letter
 j + 1 | // whose ASCII code is j + 1
 i & 96 // with bits #5 and #6 taken from i
 ]) //
 )(i & 31), // initial call to h with j = i mod 32
 B = Buffer, // define B for Buffer
 g = i => // g is a helper function taking an integer
 s = 1065233 // representing an ASCII code minus 1,
 >> i & 1 // returning 0 for consonant / 1 for vowel,
 // and also saving the result in s
) // end of replace()
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

AltStyle によって変換されたページ (->オリジナル) /