DEV Community

loading...

Discussion on: Daily Challenge #1 - String Peeler

Collapse
taillogs profile image
Ryland G • Edited

JavaScript

(someString) => someString.length > 2 ? someString.slice(1, -1) : undefined;
Enter fullscreen mode Exit fullscreen mode

Python

someString[1:-1] if len(someString) > 2 else None
Enter fullscreen mode Exit fullscreen mode

C++

someString.size() > 2 ? someString.substr(1, someString.size() - 1) : null;
Enter fullscreen mode Exit fullscreen mode

C

int trimString(char someString[])
{
  if (strlen(someString) > 2) {
    char *copy = malloc((strlen(someString) - 2) * sizeof(char));
    memmove (copy, someString + 1, strlen(someString) - 2);
    printf("%s", copy);
    free(copy);
    return 0;
  }
  return 1;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
jeromedeleon profile image
Jerome De Leon

HAHAHA damn. Let me finish my code LOL.

Collapse
rafaacioly profile image
Rafael Acioly

Let people do something 😂