Skip to content

Instantly share code, notes, and snippets.

@noelleleigh
Last active November 10, 2017 15:43
Show Gist options
  • Save noelleleigh/e5025210ba0ea9584a67754a63a1e282 to your computer and use it in GitHub Desktop.
Save noelleleigh/e5025210ba0ea9584a67754a63a1e282 to your computer and use it in GitHub Desktop.
function makeGraphBase(width, height) {
return Array(height).fill(undefined).map(row => Array(width).fill('⬜'));
};
function makeData() {
return [0, 1, 2, 4, 4, 3];
};
function diff(val, index, array) {
return array[index + 1] - val;
};
/** Return an array with one fewer elements */
function getSlopes(data) {
return data.map(diff).filter(val => !isNaN(val));
};
function normalizeSlopes(slopes) {
return slopes.map((slope) => {
if (slope > 0) {
return 1
} else if (slope < 0) {
return -1
} else {
return 0
};
});
};
function cleanupSlopes(slopes) {
const noZeroes = slopes.filter(val => val !== 0);
const bigSlopes = noZeroes.map(diff)
};
console.log('hey ⬜📈📉');
console.log(makeGraphBase(10, 5));
console.log(makeData());
console.log(getSlopes(makeData()));
console.log(normalizeSlopes(getSlopes(makeData())));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment