vadimkorr
3/12/2018 - 9:47 AM

find-less-than-items

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