function avgGradeCalc(array) {
var grade = 0;
var count = 0;
jQuery.each(array, function(index, value) {
grade += value;
count++;
});
return grade / count;
}
var arry = [84, 83, 97, 93];
var averageGrade = avgGradeCalc(arry);
console.log("Your average grade is " + averageGrade + "%");
def palindrome_homework(word):
return word == word[::-1]
user_input = input("Enter a word with only lowercase and 0 spaces: ")
if palindrome_homework(user_input):
print("Palindrome!")
else:
print("This is not a palindrome")
Summary:
String Operations:
Length function finds the string length. String concatenation combines strings. Substringing extracts a range of characters.
String Algorithm - Palindrome:
Converts input string to a palindrome. Optionally duplicates the last character.
Popcorn Hack - Finding Index:
An algorithm to find the index of a character in a string.
Homework Hack for Strings:
Challenge to detect palindromes in strings.
Math Algorithm - Fibonacci Sequence:
Generates the first n Fibonacci numbers. Requires n > 1.
Popcorn Hack - Fixing Fibonacci:
Requests input to fix Fibonacci sequence code.
Sorting Algorithm - Bubble Sort:
Sorts an integer array with bubble sort.