Pair programming activity
This lab provides an opportunity to practice implementing some real-world functions.
Please write code that implements various functions, following the requirements in the list below:
- Define a function
maxOfTwoNumbers
that takes two numbers as arguments and returns the larger of them. Use the if-else construct available in Javascript. Do some Googling to figure this out if you forget how conditionals work. - Define a function
maxOfThree
that takes three numbers as arguments and returns the largest of them. - Write a function
isCharacterAVowel
that takes a character (i.e. a string of length 1) and returns true if it is a vowel, false otherwise. - Define a function
sumArray
and a functionmultiplyArray
that sums and multiplies (respectively) all the numbers in an array of numbers. For example,sumArray([1,2,3,4])
should return 10, andmultiplyArray([1,2,3,4])
should return 24. - Write a function that returns the number of arguments passed to the function when called.
- Define a function
reverseString
that computes the reversal of a string. For example, reverseString("jag testar") should return the string "ratset gaj". - Write a function
findLongestWord
that takes an array of words and returns the length of the longest one. - Write a function
filterLongWords
that takes an array of words and a numberi
and returns the array of words that are longer than i characters long.
Bonus
- Write a function that takes a string as an argument and returns an object where:
- the keys are the characters that occur in the string
- the values are the number of occurences for each letter, regardless of the case
For example, calling the function with the string "General Assembly" will return:
{
a: 2,
b: 1,
e: 3,
g: 1,
l: 2,
m: 1,
n: 1,
r: 1,
s: 2,
y: 1
}
Fork and clone this repo. You should do all your work inside the starter-code
folder.
Open the file functions.js
. All the function names are already inside the file, you just need to implement them by adding code inside each one.
Use the Chrome dev tools console to practice executing your code.
We will be "pair programming" for this lab, so you will need to pair up. Once you have your pair, decide which computer you want to work on. As you pair program, alternate roles as "driver" and "navigator" after each step.
Push completed work up to your fork of this repo.
All content is licensed under a CCBYNCSA 4.0 license. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.