JavaScript interview questions (Count Boomerangs In Array )
HTML-код
- Опубликовано: 2 окт 2024
- JavaScript interview questions 🔥 Count Boomerangs In Array #reactinterviewquestions #javascriptinterviewquestions #reactjs #programming #coding
Please checkout below playlists:-
1. DAILY ONE REACT INTERVIEW QUESTION
• Daily React Interview ...
2. MNC INTERVIEW EXPERIENCES
• MNC Interview Experiences
3. TRICKY CSS QUESTIONS/DESIGNS
• Tricky CSS
4. MERN PROJECTS FROM SCRATCH
• MERN Projects
5. REACT IMPORTANT/RANDOM TOPICS
• React Topics
ReactJs Interview
React/Redux Coding Interview
Frontend Interview
javascript interview questions
reactjs interview questions and answers for experienced
advanced reactjs interview questions.
Please subscribe to my channel. Like, share and subscription = 100% MOTIVATION
I hope you enjoy my channel videos!
Coffee:- www.buymeacoff...
Follow On Twitter:- @itscodingdoctor
Instagram:- / itscodingdoctor
Very nice explanation bro it's really awesome ....waiting for regular videos to get uploaded in this interview series of JS
Thanks 😊
Started learning JS recently.
loved to watch this video, I literally want more of these!!
Great. You can find 23 more questions in this series
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]
Sure. Will create a video
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.
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);
@@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
@@nittasreenivas4043 You're welcome and there was always room for improvement in my code. I'm looking forward how codingDoctor solves the given problem.
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.
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.
I'll keep on increasing the difficultly level
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.
Thanks
I couldn't understand this properly
Can you give me the input and expected output? I'll try to solve and create a video too