Giter Club home page Giter Club logo

arguments_and_closure_assignment's Introduction

Exercises

  1. Create two functions: double and square. double should take a number and return the number times two.

function double(num){ return (num * 2) }

square should take a number and return the number squared.

const square = (num) => { return (num * num) }

  • Create a third function doubleSquare that uses both of the functions to return a number that is first doubled and then squared.

function doubleSquare(num) { return square(double(num)) }

  1. Create a function classyGreeting that takes as input the strings firstName and lastName, and returns a string with a greeting using the two.

function classyGreeting(firstName, lastName) { return ("hello there " + firstName + lastName) }

  • Create a second function yell that takes string as input and returns the string in all capitalized letters.
  • Create a third function yellGreeting that will take the firstName and lastName as inputs and yell a greeting using the two.
  1. The concat array method is used to merge two (or more) arrays. Write a removeDupes function that takes an array as an argument and returns a copy without any duplicate elements. Then, write a function concatAndRemoveDupes that combines two arrays and removes any duplicates.

Hint: Use the array method includes, an object, or a Set. Or the spread operator instead of concat.

  1. Given a list of grades, we can get the median grade by sorting the list and taking the middle element, or the average of the two middle elements. Create the functions sort and middleElement, and then use them to create the functions median.

let grades = [91, 85, 100, 92, 88];

console.log(median(grades)); // Should log 91

  1. Write a function called repeat that takes in a string and numberOfTimes. The function should log to the screen the string however many times as numberOfTimes. If the user does not enter a numberOfTimes it should default to 2.

  2. Using the spread operator, write a function that can take any number of arguments and return the sum of all of them.

  3. Write a function called adder takes in one number and returns a function that will add that number with another number. Using adder create an add5 and an add9 function. Hint: Closures!

arguments_and_closure_assignment's People

Contributors

christiananselm avatar coreyladovsky avatar

Watchers

 avatar

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.