Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
containsPalindrome
//JavaScript-C24.2.0 (SpiderMonkey) containsPalindrome('abcabc'); containsPalindrome('abcabcd'); containsPalindrome('abcabd'); // checks if any permutations of str are a palindrome function containsPalindrome(str) { let map = new Object(); for (let i = 0; i < str.length; i++){ if (map.hasOwnProperty(str[i])) { map[str[i]]++; } else { // here can check if it is alphanumeric map[str[i]] = 1; } } let hasOdd = false; for (var prop in map) { if (map.hasOwnProperty(prop)) { if (map[prop] %2 == 0) { continue } else if (hasOdd) { print('not a palindrome'); return false; } else { hasOdd = true; } } } print('has palindrome'); }
run
|
edit
|
history
|
help
0
strCompression
LazyListJS
Change format Numbers
LearningJavaScript
Iterator()-function
zeroMatrix
Animal category
rr
LazyListJS
p