Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. /**
  2. We would like to hear what intrigues you about healthcare technology, and more specifically, why Robin interests you.
  3.  
  4. I like that Robin is relieving doctors of some of the administration work and allowing them to spend more time with
  5. patients. I'm really interested in how NLP technology can be used to facilitate doctor/patient visits.
  6.  
  7.  
  8.  
  9. * Write a function in JavaScript that accepts an array of integers and a number X as parameters,
  10. * when invoked, returns an array of unique indices of two numbers whose sum is equal to X.
  11.  
  12. For example: [1, 3, 4, 5, 6, 8, 10, 11, 13], Sum: 14
  13.  
  14. Pairs of indices: [0, 8], [1, 7], [2, 6], [4, 5]
  15.  
  16. */
  17.  
  18. let f = (arr, x) => {
  19. let uniqueIndices = [];
  20. for(let i=0; i<arr.length; i++){
  21. for(let j=i+1; j<arr.length; j++){
  22. if(arr[i] + arr[j] === x){
  23. uniqueIndices.push([i,j]);
  24. }
  25. }
  26. }
  27. console.log(uniqueIndices);
  28. return uniqueIndices;
  29. }
  30.  
  31. f([1, 3, 4, 5, 6, 8, 10, 11, 13], 14);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement