javascript sum of two numbers inside an array print index of numbers whoose sum = target

i have to find the index of two numbers whoose sum = target[number given as argument] i have tried to solve this through for loop but i am not getting the indexex correctly as if the first two numbers of array are 1,1 and target is set as two i am getting answer as [0,0] but i want [0,1]

let arr = [1,1,8,9,7,22,6]




var twoSum = function(nums, target) {
    for(i=0;i<nums.length;i++){
        for(j=i+1;j<nums.length;j++)
        if(nums[i] + nums[j]==target){
           
            return [nums.indexOf(nums[i]) , nums.indexOf(nums[j])]
        }

    }
};
console.log(twoSum(arr, 2))
i am expecting output as [0,1]
but i am getting output as [0,0]

rxjs interval will execute if another 2 observables are true

I’m writing an angular15 app with a youtube player component in it, i’m trying to work with rxjs but i think that i have one issue that i got wrong, the mergeMap. i’m really new to rxjs so sorry for any mistakes

I have 2 subscriptions, one for if youtube library as finished loading, and the other if the youtube player is ready.

first lets look just at the interval:

this.YTSubscription=interval(100).pipe(
      exhaustMap((x, y)=>{
        this.currentTimeSubject.next(this.player.getCurrentTime());
        this.isPlayingSubject.next(this.player.getPlayerState() === YT.PlayerState.PLAYING);
        this.isMutedSubject.next(this.player.isMuted());
        this.volumeSubject.next(this.player.getVolume());
        return of(true);
      }),
    ).subscribe({next: (data )=>{
      },
      error: (err)=> {
        this.YTSubscription?.unsubscribe();
      }
    });

this works fine, it runs in intervals on 100ms and i use exhaustMap to make sure that the next iteration will be executed only if the previous one completed in case when i’ll add more calculations it may take more than 100 ms.

next i want in the interval to check if youtube is loaded, for that i have the observable isYouTubeLoaded, so i tried using mergeMap for this.. i guess this is not the right way? but it still worked:

this.YTSubscription=interval(100).pipe(
      mergeMap(x => this.isYouTubeLoaded),
      exhaustMap((x, y)=>{
        if (!x) {
          return of(false);
        }
      ...

now x inside exahustMap contains the isYouTubeLoaded and this does the job.

now i have another observable that i want to check and only if both of them are true to run the interval, if not to wait for the next iteration, this is where i get lost because if i add another mergeMap i can’t see both values in exhaustMap.

so from reading some more i assume that i’m not supposed to use mergeMap at all, maybe filter ? but i still have no clue how to do that with 2 observables.

any ideas?