Skip to content

Instantly share code, notes, and snippets.

@iendjinn
Forked from TobyEalden/codetest.js
Last active February 13, 2017 13:16
Show Gist options
  • Save iendjinn/02c1cb543cc3c7bbd658a2d2c9a0b9cb to your computer and use it in GitHub Desktop.
Save iendjinn/02c1cb543cc3c7bbd658a2d2c9a0b9cb to your computer and use it in GitHub Desktop.
/*
what are the performance issues with this code?
*/
let smallAreas = 0;
let largeAreas = 0;
for (let r = 0; r < 100; r++) {
const pi = calcPiOneMillionPlaces();
if (r < 50) {
smallAreas += pi * r * r;
} else {
largeAreas += pi * r * r;
}
}
/*
What is the value of output?
*/
let total = 0;
for (let i = 0; i < 100; i++) {
asynchronousFunction(i, (result) => {
total = total + 1;
});
}
let output = total < 1 ? 0 : 1;
/*
what is the output for this code?
*/
const getBinBounds = function(left, right, step) {
const arr = {low: [], upp: []};
if (step < 0)
return arr;
// Check if the left and rigth bounds are the same
if (left === right || (step === 0 && left <= right)) {
arr.low = [left];
arr.upp = [right];
return arr;
} else if (left > right)
return arr;
for (let i = left; i < right; i += step) {
arr.low.push(i);
if (i + step < right)
arr.upp.push(i + step);
else
arr.upp.push(right);
}
return arr;
};
console.log(getBinBounds(1, 3, 1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment