Intermediate Algorithm Scripting - Sum All Numbers in a Range - Free Code Camp

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Math.min and Math.max did it! Thanks for the great content

lanremufu
Автор

Hey!, a great tip I am a Junior developer who is learning a lot from your video tutorials and I would like to learn how to use the 'Node' option, Thanks a lot brother

RelaxingMusic-dpnv
Автор

great explanation man, thanks for the great content.

cosmelvillalobos
Автор

Wonderful lesson Mr. Ian I thank you for going deeper into this lesson. I didn't use Atom I am using that which is called TypeScript, however, I will be getting and using Atom it won't hurt to use other applications as I see it.
function sumAll(arr) {
let minimumNumber = Math.min(arr[0], arr[1]);
let maximumNumber = Math.max(arr[0], arr[1]);
var result = 0;
for (var i = minimumNumber; i <= maximumNumber; i += 1) {
result += i;
}
return result;
}
console.log(sumAll([1, 4]));

zken
Автор

Thank you fantastic explanation, it would be great if you do a tutorial about install and use node.

mitovlz
Автор

thanks a lot for the atom explanation!

cleaningbad
Автор

How to calculate sum of the numbers up until the index point using recursion?

athidlambulo
Автор

Thank you for you explanations!! I just wanted to ask, how to do get those "code recommendations" in browser, because when you write code in freecodeacademy it looks the same as if you were writing in VScode?

lukamihelac
Автор

"a loop makes more sense 'cos recursion is annoying" 😂

scottldn
Автор

Thank you for the explanation. I have a question if you would be so kind to help me with.
If I understood correctly the arr[0] and arr[1] from Math.min(arr[0], arr[1]); are referring to the position in the arr first and second. But what If we would not know the length of the arr how would we find the min/max then?
Would we first have to find out the length of the arr and fill it to ...arr[x] or is there an easier way?
Thank you in advance!

madalinsion
Автор

Hello, i want to share my simple solution to this problem using a little bit knowledge about math:

function sumAll(arr) {
return
}

sumAll([1, 4]); //it will pass the test.

minhhieu
Автор

//MY SOLUTION WITHOUT BUILT IN

function sumAll(arr) {
let min = arr[0];
let max = arr[1];
let sum = 0;

if (max > min) {
for(let i = min; i <= max; i++) {
sum += i;
}
return sum;
} else if (min > max) {
for(let i = max; i <= min; i++) {
sum += i;
}
return sum;
}
}
sumAll([1, 4]);

icaruz
Автор

Thank you Ian for the excellent videos, been watching for a while now and your explanations are great! Are you on Twitter?

freecodecampdeveloper
Автор

function sumAll(arr) {

const minNum = Math.min(arr[0], arr[1]);
console.log(minNum);

const maxNum = Math.max(arr[0], arr[1]);
console.log(maxNum);

let endResult = 0;

for (var i = minNum; i <= maxNum; i++) {
endResult += i;
}

return endResult;
}

sumAll([1, 4]);

freecodecampdeveloper
join shbcf.ru