Skip to content

Instantly share code, notes, and snippets.

@forrest-akin
Created September 24, 2020 15:20
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 forrest-akin/17786f2a1f54c7d75edb822b4bb1c6cc to your computer and use it in GitHub Desktop.
Save forrest-akin/17786f2a1f54c7d75edb822b4bb1c6cc to your computer and use it in GitHub Desktop.
const findTheDifference =
( s , t ) =>
String.fromCharCode(
foldMap( Sum , toCharCode , t )
- foldMap( Sum , toCharCode , s ) )
const toCharCode = char => char.charCodeAt()
const foldMap =
( M , f , xs ) => {
let y = M.empty
for ( const x of xs )
y = M.concat( y , f( x ) )
return y
}
const Sum =
{ concat : ( x , y ) => x + y
, empty : 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment