Could someone explain me how this code works line to line? Thanks. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

Could someone explain me how this code works line to line? Thanks.

function func(str){ var len=str.length; for(var i=0;i<Math.floor(len/2);i++){ if (str[i]!==str[len-1-i]) return false; } return true; }

27th Apr 2018, 12:55 PM
Rastislav Romanec
Rastislav Romanec - avatar
3 ответов
+ 1
I am asking only if I can't understand how exactly the code works. I am still begginer in Javascript :-).
27th Apr 2018, 1:06 PM
Rastislav Romanec
Rastislav Romanec - avatar
+ 3
4th time you are asking approx samiler (Code changed) question.
27th Apr 2018, 1:02 PM
Bug Slayer
0
That function check if a string is palindrome (a string is palindrome if its equal if readed to contrary like "baninab") Now line by line: - get string length - for any n-th element (character) check if its equals to last nth element, while half string is checked - if they are different return false (string is not palidndrome) - if function has not returned from loop mean that string is palindrome then return true
27th Apr 2018, 1:18 PM
KrOW
KrOW - avatar