Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function extractPalindromes() {
- var str = "Write a program that extracts from a given text all palindromes, ABBA, lamal, exe.";
- var words = [];
- //words = str.split(/[ ,.]/); //there are empty entries
- words = str.match(/[^ .,]+/g); //ignore empty, comma and full stop
- console.log(words);
- var result = [];
- for (key in words) {
- if (words[key] == words[key].split("").reverse().join("") && words[key].length > 1) {
- result.push(words[key])
- }
- }
- cons.innerHTML = result.join(" ");
- }sult.join(" ");
Advertisement
Add Comment
Please, Sign In to add comment