Remove duplicates from array in Javascript | Algorithm Interview Question

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

Комментарии • 365

  • @razt3757
    @razt3757 5 лет назад +71

    Quick note:
    Instead of declaring the length outside the for loop you can declare and initialize it at the beginning of the loop like this:
    for(let i=0,length=a.length;i

    •  5 лет назад +21

      Believe it or not, for (let i = 0; i < a.length; i++) is actually faster.
      Test it yourself using jsperf. There is no need to store the length of an array in a separate variable, the JS engine does it for you automatically. On Firefox, I get about 0.69% decrease in performance when I store the length in a a separate variable. Insignificant, but illustrates that there is no point in doing it.

    • @armanrozika
      @armanrozika 4 года назад +5

      @ Good point if you are working in a browser environment, but I don't know if it's applicable in a nodejs environment tho

  • @tonycarbetta1497
    @tonycarbetta1497 6 лет назад +83

    I failed this question on an interview and didn’t get the job because of it. Thank you for breaking it down so effectively.

    • @javascript_developer
      @javascript_developer 4 года назад +9

      I got the job for the same question. I had watched this video already. and same question came to me.

    • @fitsumseyoum8611
      @fitsumseyoum8611 4 года назад +3

      me too

    • @THWUFAILUZAMAN
      @THWUFAILUZAMAN 3 года назад +1

      For me also asked the same question but I just converted array to a set and got the offer 😁

    • @abhishekbaghel1809
      @abhishekbaghel1809 2 года назад

      I think we've all been there🥲

    • @archlinux8390
      @archlinux8390 2 года назад

      Me too 🤣 2 times lost ,

  • @pratikpurohit3008
    @pratikpurohit3008 4 года назад +5

    At 9:50 the Value inside are String Types. Object.keys(obj).map(Number) can be helpful. Thanks for your awesome videos and work!

  • @jacobc5655
    @jacobc5655 3 года назад +2

    Great tutorial showing not just the "how" but also the so important "why"!

  • @Sephiga
    @Sephiga Год назад

    DUDE you are a magician. I was stuck on TheOdinProject exercise 4, removeFromArray. I spent 3 days reading up on documentation understanding rest parameters, spread syntax, numerous array methods, making sure I was looping correctly and just was not understanding in the slightest why my solution wasn't working.
    Thanks for helping me understand better, i never would have thought of using indexOf with a strict equality to -1. That's a pretty neat trick. I'm so excited to learn more!
    Edit: Just checked their problem solution... wow i feel dumb 🤦

  • @gopalzalke2729
    @gopalzalke2729 4 года назад +1

    This was first question in an interview and I didn't knew the best solution at that time. After coming back I learned about Object method.

  • @catscoffeecode
    @catscoffeecode 6 лет назад +6

    cool video... I noticed two things... First sort: if in the array we have numbers that have more than one digit, in js, sort will be messed up. sort fn should be: sort(a, b) {return a < b} Second when you want to use obj to dedup, the deduped array will be array of strings not array of numbers.

    • @JBuchmann
      @JBuchmann 6 лет назад

      That's what I thought initially, but I think it'll work anyway because the sort will group the duplicates together, even if they're not overall in the right order. I believe the algorithm will still remove the duplicates.

  • @thydevdom
    @thydevdom 3 года назад

    This channel is Lowkey a gold mine. I’m glad I found it. Really simplifies things in such a great way.

    • @InterviewNest
      @InterviewNest  3 года назад

      Glad you enjoy it! Thanks for watching buddy

  • @nlburnr1
    @nlburnr1 6 лет назад +4

    Man I would like to thank you for this channel. I'm really enjoy javascript but I don't feel confident enough to go to a job interview ... I know fpr sure that this and you other channel will boost my confidence thnx you in advance sir

    • @joshwood9503
      @joshwood9503 5 лет назад +1

      No one ever feels confident enough for an interview, even after years of experience. Just go do it!

  • @javascript_developer
    @javascript_developer 4 года назад

    Way back I had watch this video to learn to remove duplicate items and now in the interview I got this same question. Initially I show him by using indexOf method and again he was not satisfied with this method saying I will have to push the item to the array everytime so this will consume more time. So I again show him the object property method like you have explain in this video and return the Object.keys(obj) . he was very happy. More couple of question and now I got selected in technical round. Thank you @techshit @interviewnest
    Somehow this channel was not subscribed. I was so unlucky. I subscribed it now.

  • @amberlum9166
    @amberlum9166 6 лет назад +4

    I was just asked this question in the interview recently!! Thank you so much for this awesome tutorial!!

    • @InterviewNest
      @InterviewNest  6 лет назад

      I am glad it helped. Thanks for watching!

  • @yashwantkaki5072
    @yashwantkaki5072 4 года назад +2

    Man....that was so clean and neat.... understood all of em

  • @imsheldlocked3386
    @imsheldlocked3386 6 лет назад +17

    Can you please cover some Javascript design patterns like Module, Factory and Prototype?

  • @roslanhristov391
    @roslanhristov391 5 лет назад +23

    Using the Object.keys(obj) way returns string values and you begin with numbers, so shouldn't the interviewer want the values back in the same data type ?

    • @zakachou
      @zakachou 4 года назад +5

      I had the same remark while watching the video 😁 and I think that it's not going to be faster because you'll need to do another loop to convert them into numbers

    • @javascript_developer
      @javascript_developer 4 года назад

      @@zakachou its fine until we use === operator. otherwise yes its true that is slow again.

    • @nnavu99
      @nnavu99 4 года назад +8

      he could've done obj[i] = i, then use Object.values()

    • @elernen9619
      @elernen9619 4 года назад +2

      let b = Object.keys(obj).map(x => x * 1);

    • @MsRitika1990
      @MsRitika1990 3 года назад +1

      You can add Number before the element

  •  5 лет назад +2

    Actually, using
    let len = a.length;
    for (let i = 0; i < len; i++) { }
    is **slower** than simply writing
    for (let i = 0; i < a.length; i++) { }
    Test it yourself using jsperf. The runtime engine already allocates a variable for length, so doing the same thing manually is only adding to the performance cost.

  • @visithrab2010
    @visithrab2010 3 года назад

    You are explaining the concept in a very good manner.... thank you so much :)

  • @wasnmurks
    @wasnmurks 6 лет назад

    Your Style of showing several solutions is super helpful. Thanks for that and keep up.

  • @joshseipel9891
    @joshseipel9891 3 года назад

    Great variations with explanations. This is a very common interview question and has always frustrated me! Thanks!

  • @not_enoughmana
    @not_enoughmana 6 лет назад

    Dude. Never spread a Set before. Friggin' awesome!!

  • @afterthetech4757
    @afterthetech4757 6 лет назад +1

    that thing you did at 9:18 is f****** amazing!

  • @saskirakosyan5268
    @saskirakosyan5268 5 лет назад +6

    your videos are always greate, you are a good theacher. respect!!!

  • @santunu23
    @santunu23 6 лет назад +2

    I love your videos, thank you for your time and effort. Removing a duplicate element from an array is a tricky thing.By using collection(in Javascript it is Set) it can be done easily.

  • @thamindujanaka6771
    @thamindujanaka6771 4 года назад

    instead of creating variable for length of the array outside we can do like this, inside for loop
    for (let i=0,j=a.length;i

  • @kamalkant1753
    @kamalkant1753 6 лет назад

    Its real helpful for the script developer thanks for such a nice explanation

  • @hamidrezaakbarnezhad2018
    @hamidrezaakbarnezhad2018 4 года назад +1

    Very Tnks... Good solutions and get best solution step by step👍thats grate

  • @mukut5ul
    @mukut5ul 4 года назад

    Good explanation with different approach.

  • @lineasdessertdiary
    @lineasdessertdiary 2 года назад

    Your explanation is amazing.

  • @passiveBhai
    @passiveBhai 4 года назад

    What a tricky question and answer. I become a fan of yours.

  • @purvasawant6169
    @purvasawant6169 6 лет назад +2

    Hey, I love your tutorials and the way you explain everything line by line. Liked, Subscribed and already shared your tutorials with my colleagues. Looking forward for your upcoming videos.
    Just noticed,
    Object.keys method provided all the string values in the array.

  • @moy2010
    @moy2010 6 лет назад +1

    Your videos are awesome, techsith. I always use them as reference when I encounter a new problem in code.

  • @tanvirhasanmonir1627
    @tanvirhasanmonir1627 2 года назад

    Wow! wonderfully explained, Thanks a lot.

  • @amandathompson9697
    @amandathompson9697 4 года назад

    Your videos explain things SO WELL. Thank you so much!

  • @MrYOUTUB1982
    @MrYOUTUB1982 5 лет назад +10

    NIce explanation but the issue with Object approach is that you get strings as an array element back.

    • @sethk7645
      @sethk7645 5 лет назад +1

      Good catch.
      The only way I see of fixing that is to loop through "b[ ]" and parseInt( ) each member of the array. It's a shame that you can't include type conversion as an argument in the Object.keys( ) method.
      In which case, you're better off just looping through the object and pushing each key to a new array while using parseInt, rather than using Object.keys and looping through it again to change the strings to integers.

    • @sethk7645
      @sethk7645 5 лет назад +1

      let b = [ ];
      for( key in obj ){
      b.push( parseInt( key ) );
      }

    • @sethk7645
      @sethk7645 5 лет назад +1

      ​@@ajasen You can still use the object pattern, it's just a bit messier. At the least, you need an extra conditional or two. And the more edge cases, the messier the code gets. This isn't to say that you would actually want to use this approach, but it can be done for what you're asking. I'll put the code for the cases you provided below. I added a couple of extra cases for "false" or "undefined", vs false or undefined (string value vs boolean or undefined data type in these cases).
      P.S. For a Function or Object or BigInt, etc... type as a member of the original array, I would need more logic in my convertToType( ) function, but you get the idea here...

    • @sethk7645
      @sethk7645 5 лет назад

      const a = [1, 2, "52634", 1.2, "false" ,"1", "dog", false, false, 4.5, 5.5, 1.2, 5, "cat", "cat", true, null, undefined, undefined, 2, true, null, "null", false, null, 1, 8];
      function eliminateDups(theArray) {
      let obj = {};
      // I threw in a statement for distinguishing edge cases of strings that could be defined as other types such as "undefined" the string vs undefined the data type or "4" vs 4.
      for (const key of theArray) {
      if(typeof key === "string"){
      obj["%String%"+key] = true;
      } else {
      obj[key] = false;
      }
      }
      let b = [ ];
      //assignment of the temp tests for a string then for a number then converts otherwise;
      for( key in obj ){
      let temp = (obj[key] === true ? key.slice(8) : ( parseFloat(key) || convertToType(key) ));
      b.push( temp );
      }
      console.log("b: ")
      console.log(b);
      return b;
      }
      function convertToType (theKey) {
      switch(theKey){
      case "null":
      return null;
      break;
      case "undefined":
      return undefined;
      break;
      case "false":
      case "true":
      return theKey === "true";
      break;
      default:
      return theKey;
      }
      }
      console.log(eliminateDups(a));

  • @abinetsolomon6076
    @abinetsolomon6076 5 лет назад

    Keep posting more tutorials.the way u explain things r easy to understand.so Am expecting moreeee videos

    • @InterviewNest
      @InterviewNest  5 лет назад

      Abhinet, I also have another channel where I post more videos on JS , React, HTML , CSS ect. its called techsithtube

  • @chriscarey4618
    @chriscarey4618 2 года назад

    A concise explaination, really appreciate your content - subscribed!

  • @ankithprabhu09
    @ankithprabhu09 6 лет назад

    Using the Set and spread operator is a cool solution

  • @tusharbhalerao3935
    @tusharbhalerao3935 3 года назад

    It's an very helpful for me.Thank you so much sir...

  • @Oswee
    @Oswee 6 лет назад +1

    Really neat thing!!! Please do more such a practical puzzle pieces.

  • @lucastperez
    @lucastperez 3 года назад

    Another one liner could be
    let arr = [ 1, 2, 5, 2, 1, 8 ];
    arr.filter( (num, index) => !ar.slice(0, index).includes(num) );
    Maybe not performatic chaining filter, slice and includes, but at least it is pretty (:
    Also it is worth noticing that the third solution (the one that converts array to object and then get the keys) will make the numbers get converted to string. in the final array In other words, we are getting [ "1", "2", "5", "8" ] as the result.
    We could use the numbers as values instead of "true" and use Object.values(obj) to get them back in array form:
    let arr = [ 1, 2, 5, 2, 1, 8 ];
    let obj = {}
    arr.forEach( num => obj[num] = num )
    Object.values(obj) // this returns [ 1, 2, 5, 8 ]

  • @chamanarts1746
    @chamanarts1746 Год назад

    Nice video thx for making this video plz make more videos like this. Very informative and easy to understand for the biggners ❤👌plz make more videos on interview questions so that people who do not gave interviews yet and this is the first time going for the interview these questions are very helpful for them ❤❤

  • @isaacb5814
    @isaacb5814 3 года назад +1

    Subscribed straight away!! This is great stuff! Thank you so much

  • @TheOfficialIH4xx3R
    @TheOfficialIH4xx3R 6 лет назад +16

    The Complexity of quicksort is O(n * log n) not O(log n)

    • @johnkeck
      @johnkeck 5 лет назад +1

      And that's the BEST-case scenario

    • @k.alipardhan6957
      @k.alipardhan6957 5 лет назад

      @@johnkeck big-O is worst case. best and avg to big-omega and big-?

    • @usmaness
      @usmaness 5 лет назад

      is the complexity mean how bad/good the code is ? nd these O nd omegas are like the degree of how bad/good is it ?
      ps : I have no idea, just wanted a quickflash clue

    • @minghaoliang4311
      @minghaoliang4311 4 года назад +1

      @@usmaness It's a way to evaluate how much the time will scale with n for a given algorithm.

  • @AAmorim1989
    @AAmorim1989 4 года назад

    Indeed gotta pay attention: remove duplicates from array !== create an array of unique values.

  • @Rafa-my3vr
    @Rafa-my3vr 5 лет назад

    you could simplify your loop and just do `for (let i=0, len=a.length; i < len; i++)...

  • @adamgordon862
    @adamgordon862 5 лет назад +2

    Awesome video as always, thanks for the multiple explanations!

    • @InterviewNest
      @InterviewNest  5 лет назад +1

      Thanks for watching Adam. Keep on learning!

  • @ghulam-mahyuddinansari2786
    @ghulam-mahyuddinansari2786 Год назад +1

    Hey a small correction, the complexity for quick sort is nlogn and regarding the a length it doesn't calculates the length every time but is stored and whenever you update values js does it automatically.

  • @simonbachmann2120
    @simonbachmann2120 5 лет назад +19

    7:42 quicksort has n*log(n)

  • @dancewithzinnia
    @dancewithzinnia 4 года назад +3

    You explain concepts so well always! and thank you for mentioning the complexity difference. Very informative! and I saw your closures video but it was somewhat confusing. It would be great if you can explain in more depth with different example

  • @chharsha231
    @chharsha231 5 лет назад

    Bro you are really making sense.. love all your videos.. Big Thanks...

  • @atchetna92
    @atchetna92 6 лет назад +3

    Thanks for the wonderful concepts. Everytime I watch your video, I always learn something new.
    Do you have an elaborate video on sets and it's work around?

    • @InterviewNest
      @InterviewNest  6 лет назад

      On monday i will release a video n maps and weakmap data structures.
      this would be on my techsithtube channel . I will cover sets and weaksets in next. video.

  • @nameymcnameson1903
    @nameymcnameson1903 11 месяцев назад

    neat i figured you had to convert to a set, then do the spread but i like that i kind of came up with something similar to the one line

  • @markdobbins1622
    @markdobbins1622 5 лет назад +8

    remove duplicates from array in Ruby:
    array.uniq

    • @arthurl7139
      @arthurl7139 5 лет назад +1

      I was there to comment something like "You now there is a problem with js when you see a 12 minutes video explaining how to remove duplicates elements from an array".
      But your comment do the job well enough ^^

    •  5 лет назад

      Sure, but this is even slower than doing it in Python (and I thought nothing could be slower than Python, before I heard about Ruby). Ruby is utter rubbish.

    • @arthurl7139
      @arthurl7139 5 лет назад

      @ remove duplicates from array in Rust :
      array.into_iter().dedup() // if array is sorted
      array.into_iter().unique() // if not

    •  5 лет назад

      ​@@arthurl7139 Rust is nice, I approve.

  • @hekskey
    @hekskey 3 года назад

    An alternate way to use an object is like this:
    const a = [1, 2, 5, 2, 1, 8];
    const b = [];
    const arrValMap = {};
    for (const i of a) {
    if (!arrValMap[i]) {
    b.push(i);
    arrValMap[i] = true;
    }
    }
    With this approach, the array values remain numbers rather than being converted to strings.... And I just noticed this video is several years old. Oh well.

  •  6 лет назад

    In the first algorithm, you have the variable len defined globally, which is unnecessary (the same reason why we put let i = 0). It's better to write the for loop as this:
    for(let i = 0, len = a.length; i < len; i++)
    This way, a.length is accessed only once, which is good, but len is cleared from memory the moment the loop finishes.

  • @LJ-lw8qd
    @LJ-lw8qd 2 года назад

    Great video, liked and subscribed....very clear, precise and the explanations are great. Thanks. Going to look at more of your work now 👍

  • @gosinP
    @gosinP 4 года назад

    Please, make more videos like this one. Thank you.

    • @InterviewNest
      @InterviewNest  4 года назад +1

      More to come!

    • @gosinP
      @gosinP 4 года назад

      @@InterviewNest if you are interested to do JS interview with me for your channel, my email is milanpjevic@gmail.com

  • @santoshpasupunuri
    @santoshpasupunuri 6 лет назад +3

    Awesome! can you do a video on best practices? In this video you mentioned that create a separate variable for a.lenght instead of using in the for loop. Similar to that, can you make a separate video on best practices in javascript or any other programming languages?

  • @prathprath265
    @prathprath265 6 лет назад +6

    var array = [1, 1, 2, 3, 4, 4, 5];
    var filtered = [];
    for (var i = 0; i < array.length; i++) {
    if (!filtered.includes(array[i])) {
    filtered.push(array[i])
    }
    }
    console.log(filtered)

    • @danialmalik80
      @danialmalik80 5 лет назад

      still N^2 complexity

    • @CknSalad
      @CknSalad 5 лет назад +3

      @@danialmalik80 yup, because 'includes' or 'indexOf' is essentially a for-loop that checks for the existence of an item (number in this case). Therefore, there is an outer loop (for-loop) and an inner loop ('includes) -> N^2

  • @alinamarasca2
    @alinamarasca2 3 года назад

    Thank you very much! very good tempo and explanations.

  • @nickvledder
    @nickvledder 5 лет назад

    Very constructive and good to follow tutorial! (From great teacher.)

  • @chrismaxwell8347
    @chrismaxwell8347 3 года назад +1

    Using the JavaScript Objects method doesn't return an array of NUMBERS. It's actually an array of strings. example: ["1", "3", "5", "8"]

  • @mrmatt8998
    @mrmatt8998 6 лет назад

    i like your approach with different methods :)

  • @emreavci3740
    @emreavci3740 3 года назад

    nice video. instructive and simple.

  • @vin_v
    @vin_v 4 года назад

    Thanks for the answer sir... marking this question as i have seen it ...also really great how you explained the different ways i which we can achieve the answer...and what's best... my immediate approach though was similar to the brute force method...sat down with the problem and thought of other JS specific way i could solve it... been preparing myself for upcoming interviews and your videos are a great help for it ..thank you

  • @cancanjaker1620
    @cancanjaker1620 4 года назад

    It shd be noted that the keys of an object are going to be strings. So by using JS objects, there is going to be a type change unintentionally

  • @robertsullivan6246
    @robertsullivan6246 Год назад

    Great for arrays of primitive types. What about arrays of objects when you want to exclude objects that are equal by content?

  • @balognerjohnerjohnson6258
    @balognerjohnerjohnson6258 5 лет назад

    damn wish i found you sooner and that i should've studied more. Gonna watch more of your videos and hopefully i'll get better at coding. Thank you so much for these.

  • @mdshoaibAlamgcetts
    @mdshoaibAlamgcetts 6 лет назад +1

    Sir this is awesome . thank you so much sir for covering this important question.

    • @InterviewNest
      @InterviewNest  6 лет назад +1

      md, keep up the good work and keep practicing!

  • @onlineeslcanada
    @onlineeslcanada 3 года назад

    very good content! learning a lot.

  • @SatishRMopur
    @SatishRMopur 5 лет назад

    Thank you so much for explaining it so well with all possible solutions and the best one.

  • @rahulsarath8680
    @rahulsarath8680 6 лет назад +1

    sir please make more interview programming question ,this helps me confident in the interview

    • @bijaykurra9989
      @bijaykurra9989 5 лет назад

      please share your interview question.i doing struggle for getting job

  • @benatakaan613
    @benatakaan613 2 года назад

    Amazing content! 👏🏻👏🏻👏🏻

  • @FargoLargo
    @FargoLargo 5 лет назад +1

    You are genius man! Ofc i subscribe on you. Keep going shoot you tutorial. Thank you for you programmers community service!

  • @bhrugudesai
    @bhrugudesai 5 лет назад +2

    Great content as always. Just one thing, Can you specify going forward which complexity are you talking about (time complexity or space complexity) because, it sounded like space complexity when you said 2 arrays, and n square, but we only had 1 loop so the time complexity should be only O(n) and not O(n^2) for brute force

    • @ts8960
      @ts8960 3 года назад

      it also had .includes which loops over the array

  • @initiala2375
    @initiala2375 4 года назад

    Very good explanation

  • @Cloud9er
    @Cloud9er 3 года назад

    I need more of these videos

  • @teresitaambrosio4503
    @teresitaambrosio4503 6 лет назад

    Thank you so much for your explanation, it was SO clear!! It's difficult to find this type of explanations so THANK YOU :)

  • @akalrove4834
    @akalrove4834 3 года назад

    Only the last method (Set) works for falsy values like null and undefined. So that should be the correct and most complete answer here.

  • @hebrux
    @hebrux 6 лет назад

    The first example is my favorite because I had already tried to solve this algorithm using a similar method but failed. the problem with my original attempt was that it only looked at the number previous to current selection. So there were still duplicates in the array.

  • @saikrishna8899
    @saikrishna8899 4 года назад

    3rd solution converts numbers to string that might trigger more questions in the interview

  • @AyanBhadury
    @AyanBhadury 4 года назад

    when we are using Object.keys approach, it returns the string values as the elements, hence we again need to convert this to an integer using the array.map, which in turns increases the complexity
    let a = Object.keys(obj).map((value)=>{
    return parseInt(value, 10);
    })

  • @rickvian
    @rickvian 4 года назад

    Cool trick! you earned my subscribe sir! looking forward for more knowledge and tricks!

  • @thehonestabe
    @thehonestabe 4 года назад

    Nice tutorial! It has a lot of information!!!

  • @MuhammadIshmaell
    @MuhammadIshmaell 5 лет назад

    Any idea why I'm getting any empty array because I'm trying to convert the array elements to integers each using the parseInt method?
    let a = [8,7,7,8,1,2,3,4,3,5,6,1,2,1,2,3];
    let obj = {};
    for(let i of a) {
    obj[ i ] = true;
    }
    let b = Object.keys(obj);
    console.log(Array.from(parseInt(b))); // this returns an empty array `[ ]`

  • @micowata
    @micowata 5 лет назад

    excellent pedagogy, thank you sir ! :)

  • @samitdigitalart
    @samitdigitalart 5 лет назад

    Thanks. Learnt new things and got new ideas.

  • @saifalikhanize
    @saifalikhanize 3 года назад

    how will you achieve the same using for loop without any other variables??

  • @SmartProgramming
    @SmartProgramming 6 лет назад

    nicely explained, keep it up sir, thank you 👍👍👍👍🙂🙂🙂🙂

  • @godsonraizen
    @godsonraizen 3 года назад +1

    Wouldn't the complexity of the brute force method be just O(N) seeing as you're looping through the array just once and there are no nested loops?

    • @InterviewNest
      @InterviewNest  3 года назад

      Depending on which approach you take. If you sort it before looping through than it s O(nlogn) because best sorting algo takes that complexity

  • @designxperts9815
    @designxperts9815 3 года назад

    instead of above concept we can use console.log([...new Set(nums)]) will return the unique value. for ascending and descending we can use reverse and sort can use.. your comment required here Sir

    • @InterviewNest
      @InterviewNest  3 года назад +1

      Santosh, yes that is also a simplest way to remove duplicate values from an array.

  • @MrB_eastt
    @MrB_eastt 5 лет назад

    Sort() function sometimes does work good with number you need to write comparison function like a.sort(function (a,b)=> a-b)
    Thank you

    • @CknSalad
      @CknSalad 5 лет назад

      yup, it will not work for something like [1, 11, 2, 3, 33, 4].

    • @sethk7645
      @sethk7645 5 лет назад

      For this purpose, it doesn't matter, so long as all identical elements are next to each other. [1,1,1,11,11,2,23,23,3,3,3,33,4] would work because we're only pushing a new item to the resulting array "b", if the previous item wasn't the same as the current one.

  • @smyk1975
    @smyk1975 3 года назад

    The complexity of a quick sort is n*log(n). Also I’m not sure if JS objects can have say, millions of elements?

  • @davidlee588
    @davidlee588 2 года назад

    The LeetCode specified that "Do not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory."

  • @manishmaithani398
    @manishmaithani398 6 лет назад +2

    Great work man. One request, can you please add videos on datatypes fromJS, Map, List, Set (import { fromJS, Map, List, Set } from 'immutable' )

    • @InterviewNest
      @InterviewNest  6 лет назад +2

      On monday i will release a video n maps and weakmap data structures. this would be on my techsithtube channel . I will cover sets next.

    • @thegreatcheater7154
      @thegreatcheater7154 6 лет назад

      InterviewNest thx

  • @santoshpasupunuri
    @santoshpasupunuri 6 лет назад

    Last solution also respects the order!

  • @Under1Umbrella
    @Under1Umbrella 5 лет назад +1

    In my interview I was asked to sort alphanumeric array [5,8,az,bt,68,gy,15]

    • @InterviewNest
      @InterviewNest  5 лет назад

      I am assuming i was [5,8,"az","bt",68,"gy",15]

    • @danialmalik80
      @danialmalik80 5 лет назад

      [5,8,"az","bt",68,"gy",15].sort()

  • @ToddsDiscGolf
    @ToddsDiscGolf 3 года назад

    Awesome tutorial thank you so much!

  • @meghanareddy9535
    @meghanareddy9535 4 года назад

    Great explanation!! Can you please upload a video on lazy loading using plain javascript

  • @sumitdixit57
    @sumitdixit57 3 года назад

    nice sir pls one question any array [1,2,3,[a,b,c,[1,2,3]]] to change a nested array to flat array please give a video

  • @dragonore2009
    @dragonore2009 5 лет назад

    Of course there is filter you can use as well.
    let b = a.filter( val, idx, arr) => arr.indexOf(val) === idx;