Steamroller: Intermediate Algorithm Scripting Free Code Camp

preview_player
Показать описание


Fan funding goes towards buying the equipment necessary to deliver 4k videos, 4k webcam, and a high quality microphone better audio. Any support is very appreciated!

My channel is here for aspiring programmers to learn easier and help debug any issues from the many great free resources available on the web.

Check out my other videos going over HTML, CSS, Ruby, Ruby on Rails, Java, JavaScript, Python, PHP, SQL, Command Line, BootStrap, jQuery, and WordPress from CodeCademy, CodeCombat, FreeCodecamp and more!

-~-~~-~~~-~~-~-
Please watch: "How I Became a Developer | My Developer Journey of the Last 3 Years | Ask a Dev"
-~-~~-~~~-~~-~-
Рекомендации по теме
Комментарии
Автор

Brilliant series Dylan. Thank you very much for going through this. I am currently working through project odin (full stack dev course) and also doing the freecodecamp javascript and data structures certification. I am really still getting to grips with concepts like recursion and this made things much clearer for me.Thanks to this series I am a step closer to understanding algorithms .

davidmclean
Автор

I suck at recursion, but your answer looks beautiful to me lol.

tomb
Автор

function steamrollArray(arr) {

while (arr.some(Array.isArray)) {

for (let i = 0; i < arr.length; i++) {

if (Array.isArray(arr[i])) {

for (let j = arr[i].length - 1; j >= 0; j--) {

arr.splice(i + 1, 0, arr[i][j])

}

arr.splice(i, 1);

break;

}

}

}

return arr;

}

// So convoluted but it works

JamesThomas-nrog
Автор

oh god thanks, i thought i was going crazy when my recursion solution wouldn't work.

iWouldWantSky
Автор

You can use your first solution with IIFE and Closure:

function steamrollArray(arr) {
var newArr = [];

(function removeArray(arr) {
for (var i = 0; i < arr.length; i++) {
if (!Array.isArray(arr[i])) {
newArr.push(arr[i]);
} else {
removeArray(arr[i]);
}
}
})(arr);

return newArr;
}

LuisForra
Автор

Here's what I went with: return [].concat.apply([], [].concat.apply([], [].concat.apply([], arr) ) ) ;

KatKaut
Автор

Sorry, can someone explain why we use arr2 and what is it?

mekanarazmedov
Автор

Did you get to know why your first solution didn't pass ? You said it passed eariler, and it looks the same as the wanted outcome. Hmmm.... (?)

sebastianhewelt
welcome to shbcf.ru