Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
containsPalindrome
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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'); }
[
+
]
Show input
Absolute running time: 0.18 sec, cpu time: 0.14 sec, memory peak: 6 Mb, absolute service time: 0,19 sec
edit mode
|
history
|
discussion
has palindrome has palindrome not a palindrome