Skip to content

Instantly share code, notes, and snippets.

@ginotria
Last active August 29, 2015 14:05
Show Gist options
  • Save ginotria/3b4ffc772c8f6bfa92ed to your computer and use it in GitHub Desktop.
Save ginotria/3b4ffc772c8f6bfa92ed to your computer and use it in GitHub Desktop.

COE 2043 Seatwork 4

  1. (5 points) complete the drawTriangle function definition to get the desired output (5 points)
var drawTriangle = function(level) {

}

sample:

drawTriangle(7);

OUTPUT:
============
#
##
###
####
#####
######
#######
  1. (5 points) Write a function 'coe' that prints the numbers from 1 to 100. But for multiples of three print "Computer" instead of the number and for the multiples of five print "Engineering". For numbers which are multiples of both three and five print "ComputerEngineering"

  2. (5 points) Write a function min that takes two arguments and returns their minimum. (dont use Math.min)


console.log(min(0, 10));
// → 0
console.log(min(0, -10));
// → -10
  1. (10 points) Define a function countBs that takes a string as its only argument and returns a number that indicates how many uppercase “B” characters are in the string.

console.log(countBs("BBC"));
// → 2
  1. (10 points) Next, Define a function called countChar that behaves like countBs, except it takes a second argument that indicates the character that is to be counted (rather than counting only uppercase "B" characters). Rewrite countBs to make use of this new function.

console.log(countChar("kakkerlak", "k"));
// → 4
  1. (10 points) Write a function called reverseString that prints out the reversal of its string parameter.

reverseString('Bahay Kubo');
// oboK yahaB
  1. (10 points) Write a function called mostFrequent that prints out the most frequent item of its parameter array.

var arr1=[3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3];
mostFrequent(arr1);
// a ( 5 times )
  1. (10 points ) Write a function called joinArray(inputArray, seperator) that joins all elements of inputArray into a string using the seperator.

var myColor = ["Red", "Green", "White", "Black"];
joinArray(myColor, ',');  // "Red,Green,White,Black"
joinArray(myColor, '-');  // "Red-Green-White-Black"
joinArray(myColor, '+');  // "Red+Green+White+Black"
  1. (20 points) Write a function called isLeapYear(year) that tells if the year passed is leap year or not

isLeap(2014) // "2014 is not a leap year"
isLeap(2012) // "2012 is a leap year"
  1. (15 points) Write a function called convertFirstetter that accepts a string as a parameter and converts the first letter of each word of the string in upper case.

convertFirstLetter('bahay kubo kahit munti'); // 'Bahay Kubo Kahit Munti'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment