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