Want to learn JavaScript? Then this is the channel for you! I will be going over Algorithms, Computer Science, whiteboard interview questions, JavaScript syntax, and MORE~!!
@chucksresume7203 The way you explain is pretty clean. I still had some issues with the logic. I was debugging and noticed the pop was activated after the function got called. For example, once it completes the combinations for "a," it will activate three times to delete all the values, and if there are still combinations for a, it will activate two times. That is kind of complex to understand. I will create my own function tomorrow based on your code to see if I can get it better. Thanks
That sounds like a good strategy. Remember there's 'more than one way to skin a cat'. Use my code as a guide if you need to, but your solution might be better!
Let's say we have an array [1,1,1,2,3,4] and set i=0 and increment i each iteration of the for loop. When i=1 we find that we have duplicates on nums[i] and nums[i-1] therefore we perform splice(i,1). Now our array looks like this: [1,1,2,3,4]. i is now 2. Because i=2 we will never find the duplicate 1's that still remain at index 0 and index 1. Technically, you could probably iterate through the for loop and use a negative splice index, but that's confusing so I preferred starting at the end and working down. Thus, i=nums.length-1 initially. That way splice won't mess with my variable i.
@bairunagarajuindian8509 Noted. It felt a little redundant, so I didn't want to be too slow. I will keep that in mind next time. Thanks for the feedback!
Do you have any insight on how to make this work with any number of functions? I'm thinking of converting the arguments object to an array of functions, and then looping through them starting from the last one, getting its return value, and then passing it down the chain along with the next output.
2 becomes our comparison value when i=4. We compare 2 to 5 and determine a swap needs to be made. Therefore, we change array[4] to 5, while holding on to the value of 2 in our variable 'current'. Then we look through our array because j>=0, and see that 4 is also less than 2 so another swap needs to be made. Our array now looks like this: [4,1,5,3,5] Notice how the value of 2 has disappeared, yet we retain it's value by storing it in a variable called 'current'. We now update the array for the swap comparing 2 and 4. Our array now looks like this: [4,1,4,3,5]. Our loop is now finished doing comparisons and we are 'kicked out'. We have one more swap to perform on the outside of our loop: arr[j] = current. Now our array looks like this: [2,1,4,3,5] If this seems confusing that's normal. Make sure you get a good understanding of Insertion Sort and this will be easier to understand. Shell Sort is like Insertion Sort on steroids.
Another solution since the range is given. 1. Calculate sum from 1 to n, call this total_sum 2. Calculate xor sum of array (xor of same num is 0), xor_sum 3. Dup_Num = Total_sum-xor_sum
nice vid though i wonder why you didnt use a object oriented way using: function Tile(x,y,width,height){ this.x = x; this.y = y; this.width = width; this.height = height; this.arr = [...]; this.draw = function(){ loopThroughtArr(this.arr); } }
You could declare variables with names like fizzCount, BuzzCount, fizzBuzzCount. Use an if else conditional statement to track the occurrence of each within the for loop. For example: let fizzCount = 0, BuzzCount = 0, fizzBuzzCount = 0; if(i % 3 === 0 && i % 5 === 0) { console.log("fizzBuzz"); fizzBuzzCount = fizzBuzzCount + 1; } else if (i % 5 === 0) { console.log('Buzz'); BuzzCount = BuzzCount + 1; } else if (i % 3 === 0) { console.log('fizz'); fizzCount = fizzCount + 1; } Hope this helps!
question: using your tutorials plus my knowledge of coding and old game design, I devised a means of having multiple canvases in a single Div (that way I could create several smaller maps instead of one giant one). Then, having each canvas element in an array, used a For Loop so that each would fill in with the correct sprites which worked swimmingly! However, the same did not work for collision detection; for the record, it created the collision for each canvas but overlaid them all on the first canvas instead of each one individually. so I was wondering if you had any idea how I could get the collision drawn on each individual canvas? I realize that ctx is set to the first canvas but don't know how to apply it to all 3 canvases. If you had any ideas, I would be grateful!
Wow that's awesome!! Unfortunately the answer is you need to make ctx for each canvas. Frank's Laboratory does a great Frogger video that utilizes this logic. Check out this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-GXvNEwu9cgM.html @8:00 Frank works with multiple ctx and canvas elements. Hope this helps!!
@@chucksresume7203 I've figured out that instead of using multiple canvases in a grid, I can just use one giant canvas and combiner multiple smaller map arrays into a larger one; in this case, I created 2D arrays for each map square, then organized each map into one 2D array called overworld. however, each map array is just getting drawn over each other instead of side by side as organized in the overworld array. Do you know of any means to move to a different point of a larger canvas to draw each map array? (IE: MapA1 is in the top left corner, MapA4 is in the top right). thank you for your time
I followed both of your tutorials and now I've made my first tile map! Your tutorial really helped because I ran into problems with other ones I tried.
Great video! Although I would like to see more advance concepts/terms throw into the mix. Such as functional/OOL style programming, elaborating on methods you used (e.g you used anonymous functions), if the "window.requestAnimationFrame" is asynchronous or not... Another tip when you were copy/pasting the map rows, instead use "Alt"+"Shift"+Down ... Keep the vids coming, chuck!
There's an old DOS game called "Castle of the Winds" that was pretty cool. It was a tile based Rogue RPG without audio lol, but it still played well! Would love to make something like that.