Skip to content

Instantly share code, notes, and snippets.

@rgsoto
Created December 5, 2019 03:07
Show Gist options
  • Save rgsoto/430c8283f90a878434768fa1942547a7 to your computer and use it in GitHub Desktop.
Save rgsoto/430c8283f90a878434768fa1942547a7 to your computer and use it in GitHub Desktop.
Node stuff
palindrome detected: A butt tuba
palindrome detected: A man, a plan, a canal—Panama!
palindrome detected: A man, a plan, a canoe, pasta, heros, rajahs, a coloratura, maps, snipe, percale, macaroni, a gag, a banana bag, a tan, a tag, a banana bag again (or a camel), a crepe, pins, Spam, a rut, a Rolo, cash, a jar, sore hats, a peon, a canal–Panama!
palindrome detected: A Toyota's a Toyota
palindrome detected: Able was I ere I saw Elba.
palindrome detected: Ah, Satan sees Natasha
palindrome detected: deified
palindrome detected: Dennis sinned.
palindrome detected: Dennis and Edna sinned.
palindrome detected: Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol, Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny, Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, Eva, Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, Cecil, Aaron, Flora, Tina, Arden, Noel, and Ellen sinned.
palindrome detected: Go hang a salami, I'm a lasagna hog.
palindrome detected: level
palindrome detected: Madam, I’m Adam.
palindrome detected: No "x" in "Nixon"
palindrome detected: No devil lived on
palindrome detected: Race fast, safe car
palindrome detected: racecar
palindrome detected: radar
palindrome detected: Was it a bar or a bat I saw?
palindrome detected: Was it a car or a cat I saw?
palindrome detected: Was it a cat I saw?
palindrome detected: Yo, banana boy!
#!/usr/local/bin/node
let fs = require("fs");
let Phrase = require("mhartl-palindrome");
let text = fs.readFileSync("phrases.txt", "utf-8");
text.split("\n").forEach(function(line){
let phrase = new Phrase(line);
if (phrase.palindrome()) {
console.log("palindrome detected:", line);
fs.writeFileSync("palindromes.txt", line, (err)=> {
if (err) throw err;
})
}
});
@rgsoto
Copy link
Author

rgsoto commented Dec 5, 2019

fs.writeFileSync("palindromes.txt", line, (err)=> { if (err) throw err; }) - This is the part i'm struggling with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment