Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:05:50+00:00 2026-06-15T23:05:50+00:00

I am working on this function which basically takes two arguments. The first one

  • 0

I am working on this function which basically takes two arguments. The first one is
a number and the second is a list. I want to replace the first argument with 3 every single time I see it in my list. My function works fine. Here it is:

censorword _ [] = [] 
censorword b (x:xs) 
        |  b == x = 3:censorword b xs 
        | otherwise = x:censorword b xs

My question is, how do I make it work for Strings. In other words, i would like to do something like this: censorword “ab” [“cdZ”,ab”] = [“cdZ”,”hello”] . Here, I have replaced “ab” with hello.

Appreciate any ideas.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:05:51+00:00Added an answer on June 15, 2026 at 11:05 pm

    You only need to change the value being replaced (3 in your original code).

    censorword :: String -> [String] -> [String]
    censorword _ [] = []  
    censorword b (x:xs)
            |  b == x = "hello" : censorword b xs
            | otherwise = x : censorword b xs
    

    This function can be generalized and simplified with map:

    censorword' :: (Eq a) => a -> a -> [a] -> [a]
    censorword' a b = map (\x -> if x == a then b else x)
    
    censorword' "ab" "he" ["ab", "he", "ab"] -- => ["he", "he", "he"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a code which requires a function. This function gets a
the second function isnt working? $('.edit_hover').live('hover', function(e){ $(this).stop(); var half_width = ($(this).css('width').slice(0, -2))/2; var
I have an ajax function which looks like this (basically, it's simplified): function getPage(targetURL,
All, I'm working with this Ajax tutorial which basically pull some records from a
I have this code, which uses ob_start php function. Which basically puts the echoed
I have this function working <script type=text/javascript> $(window).scroll(function() { if ($(window).scrollTop() == $(document).height() -
Can anyone tell me why this function is not working ? for(var i=1;i<=12;i++) {
I am using this function but it is not working. I'm using StoryBoard and
I.ve been working all night to get this function to work, but i'm too
While working on this question , I noticed that GCC (v4.7)'s implementation of std::function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.