These are chat archives for FreeCodeCamp/HelpJavaScript

19th
Aug 2018
YongweiWu
@YongweiWu
Aug 19 2018 03:31
image.png
Yogender
@yb1997
Aug 19 2018 09:14
function generateList(n = 100) {
    let list = [];

    function getUniqueNumber() {
        debugger;
        const newNum = Math.floor(Math.random()*n);
        return (list.includes(newNum))?getUniqueNumber():newNum;
    }

    for(let i = 0; i < n; i++) {
        list.push(getUniqueNumber());
    }
    return list;
}
why does getUniqueNumber is called again even after founding the unique number ?
I tested it in chrome
Jun Yada
@junyada100
Aug 19 2018 09:18
Do you mean this line?
return (list.includes(newNum))?getUniqueNumber():newNum;
Yogender
@yb1997
Aug 19 2018 09:18
yes
Jun Yada
@junyada100
Aug 19 2018 09:18
becuase list.includes(newNum) check the number is duplicate or not, if dup it re-gen
Yogender
@yb1997
Aug 19 2018 09:20
yea thats what I want but when it doesn't find any duplicate it returns false and newNum is returned
but now here the problem is, when newNum is returned by getUniqueNumber, it still gets called again
Jun Yada
@junyada100
Aug 19 2018 09:27
i cant find a problem on nodejs
Yogender
@yb1997
Aug 19 2018 09:27
oh ok i found it, its actually emptying the call stack
Jefferson
@jeffersonnnn
Aug 19 2018 10:40

Hi guys, i have a very simple problem. So i'm trying to cut up an array into chunks with a function that has two arguments like so

function chunk(array, size) {

}

and a test case like this chunk([1, 2, 3, 4], 2) --> [[ 1, 2], [3, 4]]

My problem is that i can't parse how i am meant to assign 2 to the size argument in function chunk

LOOL thanks, gosh i can be stupid sometimes.
Jefferson
@jeffersonnnn
Aug 19 2018 10:49
i've gotten
it
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:31
Help me, I'm JavaScript
宋少卿
@songshaoqing
Aug 19 2018 17:32
i need help
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:33
@songshaoqing call 911
宋少卿
@songshaoqing
Aug 19 2018 17:33
Don't make me laugh. @diomed
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:34
@songshaoqing maybe if you state your problem then...
宋少卿
@songshaoqing
Aug 19 2018 17:34
i need your help @diomed
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:34
how can :cat: help enlightened man such as yourself?
I am but an animal
宋少卿
@songshaoqing
Aug 19 2018 17:35
You're so funny
where are you come from @diomed
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:36
I are come from internets
宋少卿
@songshaoqing
Aug 19 2018 17:36
Why don't you go to heaven?
hh
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:39
you're right, I should leave this JS hellroom
ASAP
宋少卿
@songshaoqing
Aug 19 2018 17:39
i need your help plz
@diomed
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:40
with what?
宋少卿
@songshaoqing
Aug 19 2018 17:40
Is that OK?
js
@diomed
Are you still there @diomed
Aditya
@ezioda004
Aug 19 2018 17:44
@songshaoqing What do you need help with?
宋少卿
@songshaoqing
Aug 19 2018 17:45
Truncate a string
Aditya
@ezioda004
Aug 19 2018 17:46
Can you elaborate?
宋少卿
@songshaoqing
Aug 19 2018 17:46

function truncate(str, num) {
// 请把你的代码写在这里
var endStr="...";
if(num<=3){
return str+=endStr;
}

var arr=str.split('');

if(arr.length>num && num>3){
return str.slice(0,num+1).join('')+endStr;
}

}

truncate("A-tisket a-tasket A green and yellow basket", 11);

Where did it go wrong?
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:50
in China, I believe
宋少卿
@songshaoqing
Aug 19 2018 17:50
yep @diomed
May Kittens Devour Your Soul
@diomed
Aug 19 2018 17:51
you should have turned left in Albuquerkee then none of this would happen
宋少卿
@songshaoqing
Aug 19 2018 17:51
What do you mean
@diomed
Aditya
@ezioda004
Aug 19 2018 17:57
@songshaoqing Your cases are wrong, if num is greater than string length, then return string, otherwise, slice it and add ...
Also, .slice() works on strings too.
Now sure why you're splitting it to an array.
宋少卿
@songshaoqing
Aug 19 2018 18:01
Thank you. I'm thinking about it.
May Kittens Devour Your Soul
@diomed
Aug 19 2018 18:03
better use .chop()
Aditya
@ezioda004
Aug 19 2018 18:03
Close, there's .trim()
宋少卿
@songshaoqing
Aug 19 2018 18:04
.chop()?
Yogender
@yb1997
Aug 19 2018 18:07
has anyone tried react-native ?
Pagnito
@Pagnito
Aug 19 2018 21:03
anyone know how i can turn off prettier turning my emtpy div into <div/>
its so fckn annoying
JJ Megma
@megma_jj_twitter
Aug 19 2018 22:27
Hi