Giter VIP home page Giter VIP logo

Comments (3)

jrhorn424 avatar jrhorn424 commented on July 26, 2024

Here's a dump of some the code I used, reverse chronological:

'use strict';
let count = 0;
const counterFactory = function () {


  return function counter () {
    return count += 1;
  };
};

const isCentimeters = function (value) {
  if (value > 100) {
    return true;
  } else {
    return false;
  }
};

const fromCmToIn = function (value) {
  return value * 0.39;
};

// const fromInToCm = function (value) {
//   return value * 2.54;
// };

const transform = function (values, predicate, mutator) {
  // if the predicate is true, mutate the value, otherwise don't mutate it
  let result = [];

  for (let i = 0; i < values.length; i++) {
    let value = values[i];

    if (predicate(value)) {
      result.push(mutator(value));
    } else {
      result.push(value);
    }
  }

  return result;
};

const addProperty = function addProperty(obj, prop, val) {
  // this function takes an object and adds a property
  // to it

  // let prop = arguments[1];
  // let val = arguments[2];
  // let result = arguments[0];

  obj[prop] = val;
  return obj;
};


const arrayTimes2 = function arrayTimes2() {
  let result = [];

  for (let i = 0; i < arguments[0].length; i++) {
    result[i] = arguments[0][i] * 2;
  }

  return result;
};

//const max = function (arrayOfNumbers) {

const max = function () {
  // takes an arbitrary number of arguments (each arg
  // should be a number), finds the largest one, and
  // returns that member
  //
  // does it take negatives?
  // we need a starting point (maybe the first argument)

  let result = arguments[0][0];

  for (let i = 1; i < arguments[0].length; i++) {
    if (result < arguments[0][i]) {
      result = arguments[0][i];
    }
  }

  return result;

};

const product = function () {
  // multiply two numbers and return the result
  // return a * b;
  // return arguments[0] * arguments[1];
  // return arguments[0] * arguments[1] * arguments[2];
  let result = 1;

  for (let i = 0; i < arguments.length; i++) {
    //result = result * args...
    result = result * arguments[i];
  }

  return result;
};

from js-functions-ins-and-outs.

jrhorn424 avatar jrhorn424 commented on July 26, 2024

This should be included in the ins.js and outs.js. I missed these when prepping. Apologies.

from js-functions-ins-and-outs.

jrhorn424 avatar jrhorn424 commented on July 26, 2024

Leaving open for now. The solution branch needs updating, as noted in #35.

from js-functions-ins-and-outs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.