Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    kirbyedy
    @kirbyedy
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    kirbyedy
    @kirbyedy
    bf sum all numbers
    CamperBot
    @camperbot

    :fire:Bonfire: Sum All Numbers in a Range :link:

    function sumAll(arr) {
      return(1);
    }
    
    sumAll([1, 4]);

    We'll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.

    more info:  bf details | bf links | hint

    kirbyedy
    @kirbyedy
    hint
    CamperBot
    @camperbot

    hint [1/7]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    kirbyedy
    @kirbyedy
    hint
    CamperBot
    @camperbot

    hint [2/7]

    # Problem Explanation:

    • This task requires us to look at each possible permutation of a string. This is best done using a recursion function. Being able to build a function which collects all permutations of a string is a common interview question, so there is no shortage of tutorials out there on how to do this, in many different code languages.
    • This task can still be daunting even after watching a tutorial. You will want to send each new use of the function 3 inputs: 1. a new string (or character array) that is being built, 2. a position in your new string that's going to be filled next, and 3. an idea of what characters (more specifically positions) from the original string have yet to be used. The pseudo code will look something like this:

      var str = ???;
      perm(current position in original string, what's been used in original string, current string build thus far){
      if(current string is finished) {
        print current string;
      }else{
        for(var i = 0; i < str.length; i++) {
          if(str[i] has not been used) {
            put str[i] into the current position;
            mark str[i] as used
            perm(current position in original string, what's been used in original string, current string build thus far)
            unmark str[i] as used because another branch in the tree for i + 1 will still likely use it;
          }
        }
      }
      }
      perm(0, nothing used yet, empty new string (or array the same size as str);
    • Another way to think about this problem is to start from an empty space. Introduce the first letter to the space. This space will now contain the first sub-permutation. Here's a diagram illustrating the idea:

    diagram

    // An approach to introduce a new character to a permutation
    var ch = '?';
    var source = ['?', '?', '?'];     // Current sub-permutation
    var temp, dest = [];
    
    for(var i = 0; i <= source.length; ++i) {
        temp = source.slice(0);    // Copy the array
        temp.splice(i, 0, ch);    // Insert the new character
        dest.push(temp);    // Store the new sub-permutation    
    }

    Finding each permutation could then be done non-recursively by including the above in a function taking a source array and returning a destination array. For each letter of the input string, pass that character, as well as the array returned from the previous call of the function.

    A way to visualize this is by considering a tree that starts with the first character of your string: Permutation Tree

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Cole Crawford
    @ColeDCrawford
    hint
    CamperBot
    @camperbot

    hint [1/7]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Marko Nikic
    @MarkoN95
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Marko Nikic
    @MarkoN95
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Marko Nikic
    @MarkoN95
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Marko Nikic
    @MarkoN95
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Marko Nikic
    @MarkoN95
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Marko Nikic
    @MarkoN95

    @/all Guys I need some serious help here. I have (technically) solved the "No repeats please" Bonfire with the following solution:

    function permAlone(str) {
      var input = str.split("");
      var permutations = [];
    
      function generate(n, arr) {
        if(n == 1) {
          permutations.push(arr.join(""));
          return;
        }
        for(var i = 0; i < n; i++) {
          generate(n - 1, arr);
    
          if(n % 2 === 0) {
            swap(arr, i, n - 1);
          }
          else {
            swap(arr, 0, n - 1);
          }
        }
      } 
    
      function swap(arr, a, b) {
        var tmp = arr[a];
        arr[a] = arr[b];
        arr[b] = tmp;
      }
    
      function filterDuplicates(arr) {
    
        var after = arr.filter(function(item, pos, self) {
          for(var i = 0; i < item.length; i++) {
            if(item.charAt(i) == item.charAt(i+1)) {
              return false;
            }
          }
          return true;
        });
        return after.length;
      }
    
      generate(input.length, input);
    
      return filterDuplicates(permutations);
    }
    
    // these are all the test cases that freecodecamp checks
    console.log(typeof permAlone('aab') == "number"); //prints: true
    console.log(permAlone('aab')); // prints: 2
    console.log(permAlone('aaa')); // prints: 0
    console.log(permAlone('aabb')); // prints: 8
    console.log(permAlone('abdcefa')); // prints: 3600
    console.log(permAlone('abfdefa')); // prints: 2640
    console.log(permAlone('zzzzzzzz')); // prints: 0

    The solution works fine in the firebug console. And I don't think that too much recursion is the problem since I can also run this code with a string of length 10 which yields more than 3.5 million permutations. It takes a couple of seconds though.

    But when I submit the code on the challenge FreeCodeCamp always crashes and I have to stop the script from executing. Why is that??? Its frustrating having a solution but beeing unable to submit it!

    EDIT: It suddenly worked and I was finally able to complete the challenge altough I havent changed my code?? what could have been the problem for that? FreeCodeCamp suddenly accepting my solution and not crashing?

    CamperBot
    @camperbot
    type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
    Perrin Clark
    @BlackGuyCoding
    help
    CamperBot
    @camperbot

    Hi, I'm CamperBot! I can help you in this chatroom :smile:

    Basic Commands:

    • find TOPIC find all entries about topic. ex: find js
    • wiki TOPIC show contents of topic page
    • thanks @username send brownie points to another user
    • about @username shows info on that user
    • Algorithm BONFIRENAME info on a Algorithm

    :speech_balloon: meet CamperBot in this room!

    :pencil: read more about camperbot on the FCC Wiki

    Bernard Doci
    @bernarddoci
    find js
    Bernard Doci
    @bernarddoci
    about @bernarddoci
    CamperBot
    @camperbot
    :star: 439 | @bernarddoci | http://www.freecodecamp.com/bernarddoci
    Bernard Doci
    @bernarddoci
    Algorithm NO REPEATS PLEASE
    find NO REPEATS PLEASE
    CamperBot
    @camperbot

    find no repeats please

    :zero: algorithm no repeats please

    Bernard Doci
    @bernarddoci
    wiki Friendly Date Ranges
    CamperBot
    @camperbot

    :point_right: algorithm friendly date ranges [wiki]

    Problem Explanation:

    • Create a program that will take two dates and convert them into a more easy to understand date such as January 1st, 2017. It will also check the difference between them, and handles cases with no difference, more than a day, more than a month, more than a year, and more than a month and less than a year respectively.
    :pencil: read more about algorithm friendly date ranges on the FCC Wiki
    Arshad Khan
    @ar5had
    var usedChars = [], permArr = [];
    function permute(input) {
      var i, ch;
      for (i = 0; i < input.length; i++) {
        ch = input.splice(i, 1)[0];
        usedChars.push(ch);
        if (input.length === 0) {
            permArr.push(usedChars.slice());
        }
        permute(input);
        input.splice(i, 0, ch);
        usedChars.pop();
      }
      return permArr;
    }
    function permAlone(str) {
      str = str.split("");
      permute(str);
      var regTest = /(.)\1/;
      permArr = permArr.filter(function(elem){
          elem = elem.join("");
        return (!regTest.test(elem));
      });
      return permArr.length;
    }
    
    permAlone('aab');
    I have written this code but it doesnt get accpeted ? I get all the correct results by this code. Any idea why this is happening?
    KatGeek
    @KatGeek
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    KatGeek
    @KatGeek
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Makarand
    @mparigi
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Makarand
    @mparigi
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Makarand
    @mparigi
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Chris Aronchick
    @cmaronchick
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Chris Aronchick
    @cmaronchick
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Juanfran
    @jfromero
    hint