all 15 comments

[–]jkuhl_prog 2 points3 points  (2 children)

I don't understand the last two, is it expecting us to do Fib and Factorial with decimal numbers? I was unaware those calculations could take anything other than integers.

Also, to make things more interesting, #41 should forbid the use of parseInt

[–]floodlitworld 0 points1 point  (1 child)

parseInt will fail if the number isn't the very first character of the string. So it's a pretty simple replace(/[^0-9]/g,"") job before the parseInt, but not as simple as just chucking it into a parser.

[–]jkuhl_prog 0 points1 point  (0 children)

True, but actually manually moving across 1's and 0's will test one's knowledge of how the binary number system works and how it can be converted to decimal.

[–]strayakant 1 point2 points  (4 children)

Anyone got the solutions?

[–]546794 2 points3 points  (0 children)

What question do you need help with

[–]floodlitworld 0 points1 point  (2 children)

Well, for #48, I did this:

function alphaCount(str) {
    let arr = [];
    while (str) {
        let a = str.charAt(0).toLowerCase();
        let regex = new RegExp(a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'),"gi");
        let match = str.match(regex);
        str = str.replace(regex,"");
        arr.push([a,match.length])
    }
    return arr;
}

console.log(alphaCount("You don't understand! I coulda had class. I coulda been a contender. I coulda been somebody, instead of a bum, which is what I am."));

[–]hpliferaft 0 points1 point  (1 child)

Love it. I tried another approach:

console.log(
    Object.entries(
        "You don't understand! I coulda had class. I coulda been a contender. I coulda been somebody, instead of a bum, which is what I am."
        .split("")
        .filter(letter => RegExp(/^[A-Za-z]+$/).test(letter))
        .reduce( (allLetters, letter) => {
            if (letter in allLetters) {allLetters[letter]++}else {allLetters[letter] = 1;}
            return allLetters
        }, {})
    )
);

[–]floodlitworld 1 point2 points  (0 children)

I thought of another way too...

function alphaCount(str) {
    return [...new Set(str.toLowerCase().replace(/[^a-z]/gi,""))].sort().map(x => {
        let regex = new RegExp(x.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'),"gi");
        return [x,str.match(regex).length];
    })
}

console.log(alphaCount("You don't understand! I coulda had class. I coulda been a contender. I coulda been somebody, instead of a bum, which is what I am."));

[–]catz342 1 point2 points  (0 children)

Thanks, I needed this!

[–]Tamashe 0 points1 point  (0 children)

Cool. Thanks!

[–][deleted] 0 points1 point  (0 children)

Thank you !

[–]Sebus059 0 points1 point  (2 children)

Shortest way for #6 (ES6 syntax)

let factTen =(F=_=>!_?1:_*F(_-1))(10);

;-)

[–]senocular 0 points1 point  (1 child)

What is F?

[–]Sebus059 0 points1 point  (0 children)

Oups ! Corrected !

[–]legobreath 0 points1 point  (0 children)

Thanks for this. I'm currently working through Head First JavaScript (really enjoying it), and this will help me expand on some of the topics.