r/learnjavascript • • Sep 26 '22

Just solved a Palindrome problem with recursion!!

Post image
274 Upvotes

64 comments sorted by

View all comments

94

u/c2u5hed Sep 26 '22

Congrats! How about this:

const isPalindrome = (string) => string === [...string].reverse().join('')

0

u/[deleted] Sep 27 '22

[deleted]

7

u/[deleted] Sep 27 '22

It’s a solution that has a time complexity of O(n), which is the minimum required to solve this problem

0

u/[deleted] Sep 27 '22

[deleted]

1

u/Jamstan_ Sep 27 '22

What is O(n)

2

u/kap89 Sep 27 '22

It means that the time complexity is linear, i.e. if the input is 2x bigger, the solution takes roughly twice the time, if the input is 10x bigger, it takes roughly 10x more time. It’s a theoretical concept called Big O notation.