Started learning JS recently. loved to watch this video, I literally want more of these!!
@itscodingdoctor2 жыл бұрын
Great. You can find 23 more questions in this series
@g.pavani52752 жыл бұрын
Very nice explanation bro it's really awesome ....waiting for regular videos to get uploaded in this interview series of JS
@itscodingdoctor2 жыл бұрын
Thanks 😊
@nittasreenivas40432 жыл бұрын
please solve this question alternating positive and negative number in js input:[9,4,-2,-1,5,0,-5,-3,2] output:[9,-2,4,-1,5,-5,0,-3,2]
@itscodingdoctor2 жыл бұрын
Sure. Will create a video
@nitinsoni99562 жыл бұрын
At first the solution seems very simple but when I tried it damn it was tricky. Solved it by first finding indices of negative and positive numbers than using simple loop and finding the lower bounds length and upper bounds of respected arrays assigned the indices to new array and lasted compared which array is bigger and assigned remaining indices from that array.
@nitinsoni99562 жыл бұрын
let arr = [9, 4, -2, -1, 5, 0, -5, -3, 2,-2,2,3,3]; // pArr => positive indices nArr=> negative indices let pArr = arr.map((el, i) => (el >= 0 ? i : " ")).filter((el) => el !== " "); let nArr = arr.map((el, i) => (el < 0 ? i : " ")).filter((el) => el !== " "); // to store the new alternate numbers let alArr = []; // bb & lb => higher bound & lower as one of two arrays can be bigger hence we have to loop till bigger array length let bb = pArr.length > nArr.length ? pArr.length : nArr.length; let lb = pArr.length < nArr.length ? pArr.length : nArr.length; let pi=0,ni=0; for (let i = 0; i < bb; i++) { // as till lower bound both positive and negative indices array would have same number of elements if(lb > i){ alArr.push(arr[pArr[pi]]); alArr.push(arr[nArr[ni]]); pi++;ni++; } else{ // as positive array is bigger remaing numbers would be added from this array if(pArr.length > lb){ alArr.push(arr[pArr[pi]]); pi++; } // as negative array is bigger remaing numbers would be added from this array else{ alArr.push(arr[nArr[ni]]); ni++; } } } console.log(alArr);
@nittasreenivas40432 жыл бұрын
@@nitinsoni9956 thankyou bro for helping out i just tried like this let arr = [9, 4, -2, -1, 5, 0, -5, -3, 2,-2,2,3,3] let positive = arr.filter((num) => { return num >= 0; }) let negative = arr.filter((num) => { return num < 0; }) let result = []; for(let i=0,j=0; i
@nitinsoni99562 жыл бұрын
@@nittasreenivas4043 You're welcome and there was always room for improvement in my code. I'm looking forward how codingDoctor solves the given problem.
@nitinsoni99562 жыл бұрын
I love this series but I guess the difficulty level was not hard as it was kind of easy question. I solved the question with the exact solution that was shown in the video.
@itscodingdoctor2 жыл бұрын
Happy to hear that you could solve it yourself. It's a hard question though. But anyone having good knowledge of javascript can solve this.
@itscodingdoctor2 жыл бұрын
I'll keep on increasing the difficultly level
@sakthiii7112 жыл бұрын
Nice video for new topic bro, Please can you make video for [1,2,3,4,5] this will come to X pattern cross method .this was my interview question i don't know how to solve this problem.
@itscodingdoctor2 жыл бұрын
Thanks
@itscodingdoctor2 жыл бұрын
I couldn't understand this properly
@itscodingdoctor2 жыл бұрын
Can you give me the input and expected output? I'll try to solve and create a video too