Created
May 31, 2022 01:36
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
/* | |
From Cassidy Williams' weekly newsletter (https://click.pstmrk.it/2sm/buttondown.email%2Fcassidoo%2Fsubscribers%2F4d5ba807-3668-4d77-9db5-4e3303c0f3a9%2Farchive%2Fkeep-your-face-always-toward-the-sunshine-and/WPtx8C0N/bP1H/IfMBgFIdr5/OGIyZDRjMjctMTAzMy00Y2Y2LWI2YWMtZjVlNTRiOWFmNDA1) | |
Write a function that determines if all the characters in a given string are unique. Can you do this without making any new variables? You choose if you want to include capitalization in your consideration for this one, as a fun challenge. | |
Example: | |
> allUnique('Cassidy') | |
> false | |
> allUnique('cat & dog') | |
> false | |
> allUnique('cat+dog') | |
> true | |
*/ | |
export const allUnique = (chars, ignoreCase) => !RegExp(/([\s\S])[\s\S]*(?=\1)/, ignoreCase ? ['i'] : []).test(chars); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment