/    Sign up×
Community /Pin to ProfileBookmark

Javascript Palindrom

Hi,
I want to know how many of the same letters are at the end of the string as from the beginning of the string.
for example:
const string = “abcertcba”;
result = 3;

But I got stuck, where is what I have so far

`const string = “abcertcba”;
const counter = 0;

const reversString = string.split(“”).reverse().join(“”);

while(index != string.length / 2 + 1) {

forEach(index) {

}
}`

I don’t know how to compare them.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KeverMay 01.2020 — This should do the trick.var string = "abcertcba";
var i=0;

while(string[i] == string[string.length + ~i]
&& i < string.length / 2
) {
i++;
}

console.log(i)
Copy linkTweet thisAlerts:
@codyhillauthorMay 01.2020 — @Kever#1618020 it sais i is not defind
Copy linkTweet thisAlerts:
@KeverMay 01.2020 — When I copy paste those lines, they work fine. Did you combine it with other code, which may cause a problem?
Copy linkTweet thisAlerts:
@NasarhayatMay 01.2020 — @Kever#1618020

Yes it should
Copy linkTweet thisAlerts:
@codyhillauthorMay 01.2020 — @Kever#1618026 i did not
×

Success!

Help @codyhill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...