Skip to content

Instantly share code, notes, and snippets.

View Rosuav's full-sized avatar

Chris Angelico Rosuav

View GitHub Profile
//Given a sorted array of numbers, find how many elements are less than a given number
//Do not include any NaN in the array.
function how_many_less(arr, n) {
if (!arr.length || arr[0] >= n) return 0;
let low = 0, high = arr.length;
while (high > low) {
let mid = Math.floor((high + low) / 2);
if (arr[mid] >= n) high = mid;
else if (arr[mid + 1] < n) low = mid;
else return mid + 1;
Computer Information:
Manufacturer: Unknown
Model: Unknown
Form Factor: Desktop
No Touch Input Detected
Processor Information:
CPU Vendor: GenuineIntel
CPU Brand: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
CPU Family: 0x6