73
gitpush
6y

I have my doubts of being a good developer when my fingers type this thing

Just checking if a string contains itself

Comments
  • 16
    NEVER trust a f*cking String!
  • 6
    if( !( key==new string(key.ToCharArray()? key : null ) == new String(key.ToArray<char>()) )

    I had to open VS and read the string documentation in order to make sure it works.

    It works. Beat THAT!
  • 2
    Keyception
  • 3
    @Gregozor2121 This is another level.
  • 2
    Or checking if a string does not contain itself. 😂
  • 0
    @BeardedFists There is always a chance for that XD
  • 3
    @Gregozor2121 you could always be more verbose!

    boolean isEqual = true;

    for ( char c : key.toCharArray() )
    {
    for (char c1 : key.toCharArray() )
    {
    if( c != c1 )
    {
    isEqual = false;
    break;
    }
    }
    }

    I've seen something very similar in production code....
  • 3
    if (key

    && typeof key === 'string'

    && key.length

    && key.split('').reduce((eq, c, i) => eq && c === key[i], true)

    )
  • 0
    @loopback But... This code doesn't work... Or am I wrong?
  • 2
    Never trust a string. Never.

    let firstKey = key.toString();
    let secondKey = key.toString();

    if(typeof firstKey === typeof secondKey && firstKey === secondKey) {
    if(firstKey.contains(secondKey) {
    return (!(true !== false)) == false;
    }
    }
    return !true;
Add Comment