Skip to content

Instantly share code, notes, and snippets.

@vadimkorr
Last active March 13, 2018 09:01
Show Gist options
  • Select an option

  • Save vadimkorr/a2dfa2a6a2d651612d996442b596e5ad to your computer and use it in GitHub Desktop.

Select an option

Save vadimkorr/a2dfa2a6a2d651612d996442b596e5ad to your computer and use it in GitHub Desktop.
Given two arrays A and B for each item in A find how many items in B are less than this item
let a = [5, 7, 8, 10]
let b = [1, 2, 3, 4, 5, 6, 7]
for (let i=0; i<a.length; i++) {
let k=0;
for (let j=0; j<b.length; j++) {
if (b[j] < a[i]) k++;
}
console.log(a[i] + ': ' + k + ' items');
k = 0;
}
// 5: 4 items
// 7: 6 items
// 8: 7 items
// 10: 7 items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment