Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homework 1 Regrade #2

Open
rtoal opened this issue Sep 28, 2017 · 0 comments
Open

Homework 1 Regrade #2

rtoal opened this issue Sep 28, 2017 · 0 comments

Comments

@rtoal
Copy link
Collaborator

rtoal commented Sep 28, 2017

// Homework 1 Warmup to javascript
// Worked on by Cherrell Finister and Hayato Hori - github(// horihayato)
// +2 extra credit points

EXTRA CREDIT +2

const crypto = require('crypto');

function change(amount) {
  if (amount < 0) {
    throw new RangeError('amount cannot be negative');
  }
  const NO_COINS = [0, 0, 0, 0];
  if (amount === 0) {
    return NO_COINS;
  }

  const coin = [25, 10, 5, 1];
  let remaining = amount;
  const result = [];
  coin.forEach((x) => {

Use a name other than temp -1

    const temp = Math.floor(remaining / x);
    remaining -= (temp * x);
    result.push(temp);
  });

  return result;
}

function stripQuotes(text) {
  let string = text;
  string = string.replace(/['"]/g, '');
  return string;

Don't create a variable just to return it. This whole body should be a single return statement -1

}

function scramble(word) {
  let scrambled = '';
  const letters = word.split('');
  while (letters.length > 0) {
    scrambled += letters.splice(Math.floor(letters.length * Math.random()), 1);
  }
  return scrambled;
}

function powers(base, limit, callBack) {
  for (let i = 1; i <= limit; i *= base) {
    callBack(i);
  }
}

function* powersGenerator(base, limit) {
  for (let i = 1; i <= limit; i *= base) {
    yield i; // thanks to joey for helping with the yield
  }
}

function say(word) {
  if (word === undefined) {
    return '';
  }
  return function chain(nextWord) {

An arrow function would look better -1

    if (nextWord) {
      return say(`${word} ${nextWord}`);
    }
    return word;
  };
}

function interleave(x, ...y) {
  const combined = [];
  let combineX = 0;
  let combineY = 0;
  const comLength = x.length + y.length;

comLength is misleading. maxLength is better -1


  while (combineX + combineY < comLength) {
    if (x[combineX]) {
      combined.push(x[combineX]);
      combineX += 1;
    }
    if (y[combineY]) {
      combined.push(y[combineY]);
      combineY += 1;
    }
  }

  return combined;
}

function cylinder(spec) {
  let { radius = 1, height = 1 } = spec;
  const volume = () => Math.PI * radius * radius * height;
  const surfaceArea = () => (2 * Math.PI * radius * height) + (2 * Math.PI * radius * radius);
  const widen = (widenRadius) => { radius *= widenRadius; };
  const stretch = (stretchHeight) => { height *= stretchHeight; };
  const toString = () => `radius is ${radius} & height is ${height}`;
  return Object.freeze({
    volume,
    surfaceArea,
    widen,
    stretch,
    toString,
    get radius() { return radius; }, // thanks to hayley for helping understanding getters
    get height() { return height; },
  });
}

function makeCryptoFunctions(key, algorithm) {
  return [(data) => {
    const cipher = crypto.createCipher(algorithm, key);
    return cipher.update(data, 'utf-8', 'hex') + cipher.final('hex');
  },
  (data) => {
    const cipher = crypto.createDecipher(algorithm, key);
    return cipher.update(data, 'hex', 'utf-8') + cipher.final('utf-8');
  },
  ];
}

function randomName() {
  // code goes here
}

Missing -10


module.exports = {
  change,
  stripQuotes,
  scramble,
  powers,
  powersGenerator,
  say,
  interleave,
  cylinder,
  makeCryptoFunctions,
  randomName,
};

Score = 88/100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant