Last active
March 13, 2018 09:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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