Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
when you use //, it basically rounds to the smaller number, if you have 1.3 it becomes 1, if you have 79.8, it becomes 79,
so it always round to the smaller, but what happens when the number is negative, -79.8, the smaller number is -80, and that's
the way to do ceil and floor without using any of the method, number // divisor to get the floor, and -(-number//divisor),
to have the ceil, pretty neat :D
thanks for that lesson! ;)
Wow, reading about why it works was educative :D
Rounding towards negative infinity. https://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html
How does this even work?
Hi, Actually i had same thoughts about if else heirarchy(still i have same).
Before writing this comment i executed following code in C in Code Blocks 16.01
int x=1;
if(x==1)
printf("1");
else if(x>0)
printf("2");
else if(x<3);
printf("3");
and i got 13 as answer(in C) so based on this fact that if else is same for every programming language i commented on this.
but but i also tested this in differnet language after reading ur comment i got answer as 1 only.
That's not how
else if
s work. Once oneif
is satisfied, it breaks out of theelse if
chain. By your logic, 15 would actually be added thrice:15 % 3 == 0
and15 % 5 == 0
so that will trigger the first one, then the secondelse if
will trigger and so will the third.The test case implies there is an array being passed, yet you say that
number
is not an array.Edit: Also, you are simply
console.log(abc)
rather thanreturn abc
, might that be the issue?If a number such as 15 has encountered in your case it will be added twice
1st in first if case and 2ndly in 3rd else if case so just put your 1st if statement having '||' instead of '&&' so it will take care of every case.