diff --git a/lib/setup.js b/lib/setup.js
index ffafed2..1121b52 100755
--- a/lib/setup.js
+++ b/lib/setup.js
@@ -45,167 +45,167 @@ setup.startHi = [
setup.hasTeen = [
"// We'll say that a number is 'teen' if it is in the range 13..19 inclusive.",
"// Given 3 int values, return true if 1 or more of them are teen.",
- "\nvar hasTeen=function(a, b, c){ \n\n}"
+ "\nvar hasTeen = function(a, b, c){ \n\n}"
].join("\n");
setup.mixStart = [
"// Return true if the given string begins with 'mix', except the 'm' can be anything,",
"//so 'pix', '9ix' .. all count.",
- "\nvar mixStart=function(str){ \n\n}"
+ "\nvar mixStart = function(str){ \n\n}"
].join('\n');
setup.close10 = [
"// Given 2 int values, return whichever value is nearest to the value 10,",
"// or return 0 in the event of a tie. Note that Math.abs(n) returns the absolute",
"// value of a number.",
- "\nvar close10=function(a, b){ \n\n}"
+ "\nvar close10 = function(a, b){ \n\n}"
].join("\n");
setup.stringE = [
"// Return true if the given string contains between 1 and 3 'e' chars.",
- "\nvar stringE=function(str){ \n\n}"
+ "\nvar stringE = function(str){ \n\n}"
].join("\n");
setup.everyNth = [
"// Given a non-empty string and an int N, return the string made starting with char 0,",
"// and then every Nth char of the string. So if N is 3, use char 0, 3, 6, ... and so on.",
"// N is 1 or more.",
- "\nvar everyNth=function(str, n){ \n\n}"
+ "\nvar everyNth = function(str, n){ \n\n}"
].join("\n");
setup.monkeyTrouble = [
- "// We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if",
- "// each is smiling. We are in trouble if they are both smiling or if neither of",
- "// them is smiling. Return true if we are in trouble.",
- "\nvar monkeyTrouble=function(aSmile, bSmile){ \n\n}"
+ "// We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if",
+ "// each is smiling. We are in trouble if they are both smiling or if neither of",
+ "// them is smiling. Return true if we are in trouble.",
+ "\nvar monkeyTrouble = function(aSmile, bSmile){ \n\n}"
].join("\n");
setup.parrotTrouble = [
"// We have a loud talking parrot. The 'hour' parameter is the current hour",
"// time in the range 0..23. We are in trouble if the parrot is talking and",
"// the hour is before 7 or after 20.",
"// Return True if we are in trouble.",
- "\nvar parrotTrouble=function(talking, hour) { \n\n}"
+ "\nvar parrotTrouble = function(talking, hour) { \n\n}"
].join("\n");
setup.posNeg = [
"// Given 2 int values, return True if one is negative and one is positive.",
"// Except if the parameter 'negative' is True, then return True only if",
"// both are negative.",
- "\nvar posNeg=function(a, b, negative) { \n\n}"
+ "\nvar posNeg = function(a, b, negative) { \n\n}"
].join("\n");
setup.frontBack = [
"// Given a string, return a new string where the first and last chars",
"// have been exchanged.",
- "\nvar frontBack=function(str) { \n\n}"
+ "\nvar frontBack = function(str) { \n\n}"
].join("\n");
setup.or35 = [
"// Return true if the given non-negative number is a multiple of 3",
"// or a multiple of 5. (Hint: Use the % 'mod' operator)",
- "\nvar or35=function(n) { \n\n}"
+ "\nvar or35 = function(n) { \n\n}"
].join("\n");
setup.icyHot = [
"// Given two temperatures, return true if one is less than 0 and ",
"// the other is greater than 100.",
- "\nvar icyHot=function(temp1, temp2) { \n\n}"
+ "\nvar icyHot = function(temp1, temp2) { \n\n}"
].join("\n");
setup.loneTeen = [
"// We'll say that a number is 'teen' if it is in the range 13..19 inclusive.",
"// Given 2 int values, return true if one or the other is teen, but not both",
- "\nvar loneTeen=function(a, b) { \n\n}"
+ "\nvar loneTeen = function(a, b) { \n\n}"
].join("\n");
setup.startOz = [
"// Given a string, return a string made of the first 2 chars (if present),",
"// however include first char only if it is 'o' and include the second only",
"// if it is 'z', so 'ozymandias' yields 'oz'.",
- "\nvar startOz=function(str) { \n\n}"
+ "\nvar startOz = function(str) { \n\n}"
].join("\n");
setup.in3050 = [
"// Given 2 int values, return true if they are both in the range 30..40 inclusive,",
"// or they are both in the range 40..50 inclusive.",
- "\nvar in3050=function(a ,b) { \n\n}"
+ "\nvar in3050 = function(a ,b) { \n\n}"
].join("\n");
setup.lastDigit = [
"// Given two non-negative int values, return true if they have the same last digit,",
"// such as with 27 and 57. Note that the % 'mod' operator computes remainders,",
"// so 17 % 10 is 7.",
- "\nvar lastDigit=function(a ,b) { \n\n}"
+ "\nvar lastDigit = function(a ,b) { \n\n}"
].join("\n");
setup.sumDouble = [
"// Given two int values, return their sum. Unless the two values are the same,",
"// then return double their sum.",
- "\nvar sumDouble=function(a ,b) { \n\n}"
+ "\nvar sumDouble = function(a ,b) { \n\n}"
].join("\n");
setup.makes10 = [
"// Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.",
- "\nvar makes10=function(a ,b) { \n\n}"
+ "\nvar makes10 = function(a ,b) { \n\n}"
].join("\n");
setup.notString = [
"// Given a string, return a new string where 'not ' has been added to the front.",
"// However, if the string already begins with 'not', return the string unchanged.",
- "\nvar notString=function(str) { \n\n}"
+ "\nvar notString = function(str) { \n\n}"
].join("\n");
setup.front3 = [
"// Given a string, we'll say that the front is the first 3 chars of the string.",
"// If the string length is less than 3, the front is whatever is there.",
"// Return a new string which is 3 copies of the front.",
- "\nvar front3=function(str) { \n\n}"
+ "\nvar front3 = function(str) { \n\n}"
].join("\n");
setup.front22 = [
"// Given a string, take the first 2 chars and return the string with the 2",
"// chars added at both the // front and back, so 'kitten' yields 'kikittenki'",
"// chars are there.",
- "\nvar front22=function(str) { \n\n}"
+ "\nvar front22 = function(str) { \n\n}"
].join("\n");
setup.in1020 = [
"// Given 2 int values, return true if either of them is in the range 10..20 inclusive.",
- "\nvar in1020=function(a, b) { \n\n}"
+ "\nvar in1020 = function(a, b) { \n\n}"
].join("\n");
setup.delDel = [
"// Given a string, if the string \"del\" appears starting at index 1, return a string " +
"// where that \"del\" has been deleted. Otherwise, return the string unchanged.",
- "\nvar delDel=function(str) { \n\n}"
+ "\nvar delDel = function(str) { \n\n}"
].join("\n");
setup.intMax = [
"// Given three int values, a b c, return the largest.",
- "\nvar intMax=function(a, b, c) { \n\n}"
+ "\nvar intMax = function(a, b, c) { \n\n}"
].join("\n");
setup.max1020 = [
"// Given 2 positive int values, return the larger value that is in the range 10..20",
"// inclusive, or return 0 if neither is in that range.",
- "\nvar max1020=function(a, b) { \n\n}"
+ "\nvar max1020 = function(a, b) { \n\n}"
].join("\n");
setup.endUp = [
"// Given a string, return a new string where the last 3 chars are now in upper case.",
"// If the string has less than 3 chars, uppercase whatever is there. Note that",
"// str.toUpperCase() returns the uppercase version of a string.",
- "\nvar endUp=function(str) { \n\n}"
+ "\nvar endUp = function(str) { \n\n}"
].join("\n");
// setup for string-1 java problems
setup.helloName = [
"// Given a string name, e.g. 'bob', return a greeting of the form 'Hello Bob!.",
- "\nvar helloName=function(name) { \n\n}"
+ "\nvar helloName = function(name) { \n\n}"
].join("\n");
setup.makeAbba = [
"// Given two strings, a and b, return the result of putting them together in the",
"// order abba, e.g. 'Hi' and 'Bye' returns 'HiByeByeHi'.",
- "\nvar makeAbba=function(a, b) { \n\n}"
+ "\nvar makeAbba = function(a, b) { \n\n}"
].join("\n");
setup.makeTags = [
@@ -213,201 +213,234 @@ setup.makeTags = [
"// In this example, the 'i' tag makes and which surround the word 'Yay'.",
"// Given tag and word strings, create the HTML string with tags around the word,",
"// e.g. 'Yay'",
- "\nvar makeTags=function(tag, word) { \n\n}"
+ "\nvar makeTags = function(tag, word) { \n\n}"
].join("\n");
setup.makeOutWord = [
"// Given an 'out' string length 4, such as '<<>>', and a word, return a new string where",
"// the word is in the middle of the out string, e.g. '<>'. Note: use str.substring(i, j)",
"// to extract the String starting at index i and going up to but not including index j.",
- "\nvar makeOutWord=function(out, word) { \n\n}"
+ "\nvar makeOutWord = function(out, word) { \n\n}"
].join("\n");
setup.extraEnd = [
"// Given a string, return a new string made of 3 copies of the last 2 chars",
"// of the original string. The string length will be at least 2.",
- "\nvar extraEnd=function(str) { \n\n}"
+ "\nvar extraEnd = function(str) { \n\n}"
].join("\n");
setup.withoutEnd = [
"// Given a string, return a version without the first and last char, so 'Hello' yields 'ell'.",
- "\nvar withoutEnd=function(str) { \n\n}"
+ "\nvar withoutEnd = function(str) { \n\n}"
].join("\n");
setup.comboString = [
"// Given 2 strings, a and b, return a string of the form short+long+short, with",
"// the shorter string on the outside and the longer string on the inside. The",
"// strings will not be the same length, but they may be empty (length 0).",
- "\nvar comboString=function(a, b) { \n\n}"
+ "\nvar comboString = function(a, b) { \n\n}"
].join("\n");
setup.nonStart = [
"// Given 2 strings, return their concatenation, except omit the first char",
"// of each. The strings will be at least length 1.",
- "\nvar nonStart=function(a, b) { \n\n}"
+ "\nvar nonStart = function(a, b) { \n\n}"
].join("\n");
setup.firstHalf = [
"// Given a string of even length, return the first half.",
"// So the string 'WooHoo' yields 'Woo'.",
- "\nvar firstHalf=function(str) { \n\n}"
+ "\nvar firstHalf = function(str) { \n\n}"
].join("\n");
setup.firstTwo = [
"// Given a string, return the string made of its first two chars, so the String",
"// 'Hello' yields 'He'. If the string is shorter than length 2, return whatever",
- "\nvar firstTwo=function(str) { \n\n}"
+ "\nvar firstTwo = function(str) { \n\n}"
].join("\n");
setup.left2 = [
"// Given a string, return a 'rotated left 2' version where the first 2 chars are",
"// moved to the end. The string length will be at least 2.",
- "\nvar left2=function(str) { \n\n}"
+ "\nvar left2 = function(str) { \n\n}"
].join("\n");
setup.right2 = [
"// Given a string, return a 'rotated right 2' version where the last 2 chars are",
"// moved to the start. The string length will be at least 2.",
- "\nvar right2=function(str) { \n\n}"
+ "\nvar right2 = function(str) { \n\n}"
].join("\n");
setup.theEnd = [
"// Given a string, return a string length 1 from its front, unless front is false,",
"// in which case return a string length 1 from its back. The string will be non-em",
- "\nvar theEnd=function(str, front) { \n\n}"
+ "\nvar theEnd = function(str, front) { \n\n}"
].join("\n");
setup.withoutEnd2 = [
"// Given a string, return a version without both the first and last char of the",
"// string. The string may be any length, including 0.",
- "\nvar withoutEnd2=function(str) { \n\n}"
+ "\nvar withoutEnd2 = function(str) { \n\n}"
].join("\n");
setup.middleTwo = [
"// Given a string of even length, return a string made of the middle two chars,",
"// so the string 'string' yields 'ri'. The string length will be at least 2.",
- "\nvar middleTwo=function(str) { \n\n}"
+ "\nvar middleTwo = function(str) { \n\n}"
].join("\n");
setup.endsLy = [
"// Given a string, return true if it ends in 'ly'.",
- "\nvar endsLy=function(str) { \n\n}"
+ "\nvar endsLy = function(str) { \n\n}"
].join("\n");
setup.stringTimes = [
"// Given a string and a non-negative int n, return a larger string that is n",
"// copies of the original string.",
- "\nvar stringTimes=function(str, n) { \n\n}"
- ].join("\n");
+ "\nvar stringTimes = function(str, n) { \n\n}"
+].join("\n");
setup.arrayCount9 = [
"// Given an array of ints, return the number of 9's in the array.",
" \nvar arrayCount9 = function(nums){ \n\n}"
- ].join("\n");
- setup.doubleX = [
+].join("\n");
+setup.doubleX = [
"// Given a string, return true if the first instance of 'x' in the string is",
"// immediately followed by another 'x'.",
- "\nvar doubleX=function(str) { \n\n}"
- ].join("\n");
+ "\nvar doubleX = function(str) { \n\n}"
+].join("\n");
- setup.last2 = [
+setup.last2 = [
"// Given a string, return the count of the number of times that a substring ",
"// length 2 appears in the string and also as the last 2 chars of the string,",
"// so 'hixxxhi' yields 1 (we won't count the end substring). ",
- "\nvar last2=function(str) { \n\n}"
- ].join("\n");
+ "\nvar last2 = function(str) { \n\n}"
+].join("\n");
setup.altPairs = [
"// Given a string, return a string made of the chars at indexes ",
- "0,1, 4,5, 8,9 ...so 'kittens' yields 'kien'. ",
- "\nvar altPairs=function(str) { \n\n}"
- ].join("\n");
+ "// 0,1, 4,5, 8,9 ...so 'kittens' yields 'kien'. ",
+ "\nvar altPairs = function(str) { \n\n}"
+].join("\n");
- setup.noTriples = [
- "// Given an array of ints, we'll say that a triple is a value appearing",
- "// 3 times in a row in the array. Return true if the array does not contain",
- "// any triples.",
- "\nvar noTriples=function(nums) { \n\n}"
- ].join("\n");
+setup.noTriples = [
+ "// Given an array of ints, we'll say that a triple is a value appearing",
+ "// 3 times in a row in the array. Return true if the array does not contain",
+ "// any triples.",
+ "\nvar noTriples = function(nums) { \n\n}"
+].join("\n");
setup.frontTimes = [
"// Given a string and a non-negative int n, we'll say that the front of the string is",
"// the first 3 chars, or whatever is there if the string is less than length 3.",
"// Return n copies of the front;",
" \nvar frontTimes = function(str, n){ \n\n}"
- ].join("\n");
+].join("\n");
setup.stringBits = [
"// Given a string, return a new string made of every other char ",
"// starting with the first, so 'Hello' yields 'Hlo'.",
"// Return n copies of the front;",
- " \nvar stringBits = function(n){ \n\n}"
- ].join("\n");
+ " \nvar stringBits = function(str){ \n\n}"
+].join("\n");
setup.arrayCount9 = [
"// Given an array of ints, return the number of 9's in the array.",
" \nvar arrayCount9 = function(nums){ \n\n}"
- ].join("\n");
+].join("\n");
setup.stringMatch = [
"// Given 2 strings, a and b, return the number of the positions where they contain",
"// the same length 2 substring. So 'xxcaazz' and 'xxbaaz' yields 3, since the 'xx', ",
+ "// 'aa', and 'az' substrings appear in the same place in both strings.",
" \nvar stringMatch = function(a,b){ \n\n}"
- ].join("\n");
+].join("\n");
setup.stringYak = [
"// Suppose the string 'yak' is unlucky. Given a string, return a version where all ",
"// the 'yak' are removed, but the 'a' can be any char. The 'yak' strings will not overlap.",
" \nvar stringYak = function(str){ \n\n}"
- ].join("\n");
+].join("\n");
- setup.has271 = [
+setup.has271 = [
"// Given an array of ints, return true if it contains a 2, 7, 1 pattern -- a value, ",
"// followed by the value plus 5, followed by the value minus 1. Additionally the 271",
"// counts even if the '1' differs by 2 or less from the correct value.",
" \nvar has271 = function(nums){ \n\n}"
- ].join("\n");
+].join("\n");
- setup.countXX = [
+setup.countXX = [
"// Count the number of 'xx' in the given string. We'll say that overlapping is allowed,",
"// so 'xxx' contains 2 'xx'.",
" \nvar countXX = function(str){ \n\n}"
- ].join("\n");
-
- setup.arrayFront9 = [
- "// Given an array of ints, return true if one of the first 4 elements in ",
- "// the array is a 9. The array length may be less than 4",
- " \nvar arrayFront9 = function(nums){ \n\n}"
- ].join("\n");
-
- setup.stringX = [
- "// Given a string, return a version where all the 'x' have been removed.",
- "// Except an 'x' at the very start or end should not be removed.",
- " \nvar stringX = function(str){ \n\n}"
- ].join("\n");
-
- setup.array667 = [
- "// are next to each other in the array. Also count instances where",
- "// the second '6' is actually a 7.",
- " \nvar array667 = function(nums){ \n\n}"
- ].join("\n");
-
- setup.isHere = [
- "// Given a string of letters, write a function that outputs string of 1's",
- "// and 0's of the same size corresponding to if a selected letter is in ",
- "// that position of the input string. Be sure to make x and input lowercase.",
- "// For example isHere('l', 'hello') would output 00110. ",
- " \nvar isHere = function(x, input){ \n\n}"
- ].join("\n");
-
- setup.biggestPre = [
- "// Given an array of strings, find the longest common prefix each string has.",
- "// i.e. a list of yes, yodel, yeah should output y.",
- " \nvar biggestPre = function(input){ \n\n}"
- ].join("\n");
-
- setup.nTwice = [
- "// Given a string and an int n, return a string made of the first and last n chars",
- "// from the string. The string length will be at least n.",
- " \nvar nTwice = function(str, n){ \n\n}"
- ].join("\n");
+].join("\n");
+
+setup.arrayFront9 = [
+ "// Given an array of ints, return true if one of the first 4 elements in ",
+ "// the array is a 9. The array length may be less than 4",
+ " \nvar arrayFront9 = function(nums){ \n\n}"
+].join("\n");
+
+setup.stringX = [
+ "// Given a string, return a version where all the 'x' have been removed.",
+ "// Except an 'x' at the very start or end should not be removed.",
+ " \nvar stringX = function(str){ \n\n}"
+].join("\n");
+
+setup.array667 = [
+ "// are next to each other in the array. Also count instances where",
+ "// the second '6' is actually a 7.",
+ " \nvar array667 = function(nums){ \n\n}"
+].join("\n");
+
+setup.isHere = [
+ "// Given a string of letters, write a function that outputs string of 1's",
+ "// and 0's of the same size corresponding to if a selected letter is in ",
+ "// that position of the input string. Be sure to make x and input lowercase.",
+ "// For example isHere('l', 'hello') would output 00110. ",
+ " \nvar isHere = function(x, input){ \n\n}"
+].join("\n");
+
+setup.biggestPre = [
+ "// Given an array of strings, find the longest common prefix each string has.",
+ "// i.e. a list of yes, yodel, yeah should output y.",
+ " \nvar biggestPre = function(input){ \n\n}"
+].join("\n");
+
+setup.nTwice = [
+ "// Given a string and an int n, return a string made of the first and last n chars",
+ "// from the string. The string length will be at least n.",
+ " \nvar nTwice = function(str, n){ \n\n}"
+].join("\n");
+
+setup.makeTags = [
+ '// The web is built with HTML strings like "Yay" which draws Yay as italic',
+ '// text. In this example, the "i" tag makes and which surround the word',
+ '// "Yay". Given tag and word strings, create the HTML string with tags around',
+ '// the word, e.g. "Yay".',
+ ' \nvar makeTags = function(tag, word){ \n\n}'
+].join('\n');
+
+setup.twoChar = [
+ '// Given a string and an index, return a string length 2 starting at the given',
+ '// index. If the index is too big or too small to define a string length 2, use',
+ '// the first 2 chars. The string length will be at least 2.',
+ ' \nvar twoChar = function(str, index){ \n\n}'
+].join('\n');
+
+setup.middleThree = [
+ '// Given a string of odd length, return the string length 3 from its middle, so',
+ '// "Candy" yields "and". The string length will be at least 3.',
+ ' \nvar middleThree = function(str, index){ \n\n}'
+].join('\n');
+
+setup.array123 = [
+ '// Given an array of ints, return true if the sequence of numbers 1, 2, 3',
+ '// appears in the array somewhere.',
+ ' \nvar array123 = function(nums){ \n\n}'
+].join('\n');
+
+setup.stringSplosion = [
+ '// Given a non-empty string like "Code" return a string like "CCoCodCode".',
+ ' \nvar stringSplosion = function(str){ \n\n}'
+].join('\n');
diff --git a/server/server.js b/server/server.js
index 6ab5b8d..75d6319 100755
--- a/server/server.js
+++ b/server/server.js
@@ -7,330 +7,346 @@ Accounts.onCreateUser(function(options, user) {
});
Meteor.publish("allUserData", function() {
- return Meteor.users.find({}, {fields: {
- 'bats': 1,
- 'rank': 1
- }});
+ return Meteor.users.find({}, {
+ fields: {
+ 'bats': 1,
+ 'rank': 1
+ }
+ });
});
- Meteor.startup(function () {
- Meteor.methods({
- newMessage: function(body, ceID){
- if(!messageObjector.user())
- return;
- var messageObject = {
- body:body,
- modalID:ceID,
- user:Meteor.user(),
- timestamp:(new Date()).getTime()
- }
- Chatter.insert(messageObject);
- },
- userUpdate: function (name) {
- if(!Meteor.user())
- return;
- if(! _.find(Meteor.user().bats, function(bat){ return bat == name; }))
- Meteor.users.update({_id:Meteor.user()._id}, {$push:{"bats": name}});
-
- },
- addComment: function(comment, user, exerciseName) {
- var messageObject = {
- body: comment,
- username: user,
- exerciseName: exerciseName,
- timestamp:moment().format("dddd, MMMM Do YYYY, h:mm:ss a"),
- upvoters: [],
- votes: 0
+Meteor.startup(function() {
+ Meteor.methods({
+ newMessage: function(body, ceID) {
+ if (!messageObjector.user())
+ return;
+ var messageObject = {
+ body: body,
+ modalID: ceID,
+ user: Meteor.user(),
+ timestamp: (new Date()).getTime()
+ }
+ Chatter.insert(messageObject);
+ },
+ userUpdate: function(name) {
+ if (!Meteor.user())
+ return;
+ if (!_.find(Meteor.user().bats, function(bat) {
+ return bat == name;
+ }))
+ Meteor.users.update({
+ _id: Meteor.user()._id
+ }, {
+ $push: {
+ "bats": name
}
- Comments.insert(messageObject);
- },
+ });
- upvote: function(commentId) {
- check(this.userId, String);
- check(commentId, String);
+ },
+ addComment: function(comment, user, exerciseName) {
+ var messageObject = {
+ body: comment,
+ username: user,
+ exerciseName: exerciseName,
+ timestamp: moment().format("dddd, MMMM Do YYYY, h:mm:ss a"),
+ upvoters: [],
+ votes: 0
+ }
+ Comments.insert(messageObject);
+ },
- var affected = Comments.update({
- _id: commentId,
- upvoters: {$ne: this.userId}
- }, {
- $addToSet: {upvoters: this.userId},
- $inc: {votes: 1}
- });
+ upvote: function(commentId) {
+ check(this.userId, String);
+ check(commentId, String);
- if (! affected)
- throw new Meteor.Error('invalid', "You weren't able to upvote that post");
+ var affected = Comments.update({
+ _id: commentId,
+ upvoters: {
+ $ne: this.userId
+ }
+ }, {
+ $addToSet: {
+ upvoters: this.userId
+ },
+ $inc: {
+ votes: 1
}
- })
- });
- // database of each coding bat exercise
- if (Exercises.find().count() === 0) {
- Exercises.insert({
- "section":"warm-up1",
- "name":"sleepIn",
- "inputs":[
- "(true, true)",
- "(true, false)",
- "(false, true)",
- "(false, false)"
- ],
- "setup": setup.sleepIn
- });
- Exercises.insert({
- "section":"warm-up1",
- "name":"diff21",
- "inputs":[
- "(19)",
- "(10)",
- "(21)",
- "(22)",
- "(25)",
- "(30)",
- "(0)",
- "(1)",
- "(2)",
- "(-1)",
- "(-2)",
- "(50)",
- ],
- "setup": setup.diff21
- });
- Exercises.insert({
- "section":"warm-up1",
- "name":"nearHundred",
- "inputs":[
- "(93)",
- "(90)",
- "(89)",
- "(110)",
- "(111)",
- "(121)",
- "(0)",
- "(5)",
- "(191)",
- "(189)"
- ],
- "setup": setup.nearHundred
- });
- Exercises.insert({
- "section":"warm-up1",
- "name":"missingChar",
- "inputs":[
- "('kitten', 1)",
- "('kitten', 0)",
- "('kitten', 4)",
- "('Hi', 0)",
- "('Hi', 1)",
- "('code', 0)",
- "('code', 1)",
- "('code', 2)",
- "('code', 3)",
- "('chocolate', 8)"
- ],
- "setup":setup.missingChar
- });
- Exercises.insert({
- "section":"warm-up1",
- "name":"backAround",
- "inputs":[
- "('cat')",
- "('Hello')",
- "('a')",
- "('abc')",
- "('read')",
- "('boo')"
- ],
- "setup": setup.backAround
- });
- Exercises.insert({
- "section":"warm-up1",
- "name":"startHi",
- "inputs":[
- "('hi there')",
- "('hi')",
- "('hello hi')",
- "('he')",
- "('h')",
- "('')",
- "('ho hi')",
- "('hi ho')"
- ],
- "setup": setup.startHi
- });
- Exercises.insert({
- "section":"warm-up1",
- "name":"hasTeen",
- "inputs":[
- "(13, 20, 10)",
- "(20, 19, 10)",
- "(20, 10, 13)",
- "(1, 20, 12)",
- "(19, 20, 12)",
- "(12, 20, 19)",
- "(12, 9, 20)",
- "(12, 18, 20)",
- "(14, 2, 20)",
- "(4, 2, 20)",
- "(11, 22, 22)"
- ],
- "setup": setup.hasTeen
- });
- Exercises.insert({
- "section":"warm-up1",
- "name":"mixStart",
- "inputs":[
- "('mix snacks')",
- "('pix snacks')",
- "('piz snacks')",
- "('nix')",
- "('ni')",
- "('n')"
- ],
- "setup": setup.mixStart
- });
- Exercises.insert({
- "section":"warm-up1",
- "name":"close10",
- "inputs":[
- "(8, 13)",
- "(13, 8)",
- "(13, 7)",
- "(7, 13)",
- "(9, 13)",
- "(13, 8)",
- "(10, 12)",
- "(11, 10)",
- "(5, 21)",
- "(0, 20)",
- "(0, 20)",
- "(10, 10)"
- ],
- "setup": setup.close10
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "stringE",
- "inputs":[
- "('Hello')",
- "('Heelle')",
- "('Heelele')",
- "('HII')",
- "('e')",
- "('')"
- ],
- "setup": setup.stringE
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "everyNth",
- "inputs":[
- "('Miracle', 2)",
- "('abcdefg', 2)",
- "('abcdefg', 3)",
- "('Chocolate', 3)",
- "('Chocolates', 3)",
- "('Chocolates', 4)",
- "('Chocolates', 100)"
- ],
- "setup": setup.everyNth
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "monkeyTrouble",
- "inputs":[
- "(true, true)",
- "(false, false)",
- "(true, false)",
- "(false, true)"
- ],
- "setup": setup.monkeyTrouble
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "parrotTrouble",
- "inputs": [
- "(true, 6)",
- "(true, 7)",
- "(false, 6)",
- "(true, 21)",
- "(false, 21)",
- "(true, 23)",
- "(false, 23)",
- "(true, 20)",
- "(false, 12)"
- ],
- "setup": setup.parrotTrouble
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "frontBack",
- "inputs": [
- "('code')",
- "('a')",
- "('ab')",
- "('abc')",
- "('')",
- "('Chocolate')",
- "('aavj')",
- "('hello')"
- ],
- "setup": setup.frontBack
});
- Exercises.insert({
- "section": "warmup-1",
- "name": "or35",
- "inputs": [
- "(3)",
- "(10)",
- "(8)",
- "(15)",
- "(5)",
- "(4)",
- "(9)",
- "(4)",
- "(7)",
- "(6)",
- "(17)",
- "(18)",
- "(29)",
- "(20)",
- "(21)",
- "(22)",
- "(45)",
- "(99)",
- "(100)",
- "(101)",
- "(121)",
- "(122)",
- "(123)"
- ],
- "setup": setup.or35
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "posNeg",
- "inputs": [
- "(1, -1, false)",
- "(-1, 1, false)",
- "(-4, -5, true)",
- "(-4, -5, false)",
- "(-4, 5, false)",
- "(-4, 5, true)",
- "(1, 1, false)",
- "(-1, -1, false)",
- "(1, -1, true)",
- "(-1, 1, true)",
- "(1, 1, true)",
- "(-1, -1, true)",
- "(5, -5, false)",
- "(-6, 6, false)",
- "(-5, -6, false)",
- "(-2, -1, false)",
- "(1, 2, false)",
- "(-5, 6, true)",
- "(-5, -5, true)"
- ],
- "setup": setup.posNeg
- });
- Exercises.insert({
+
+ if (!affected)
+ throw new Meteor.Error('invalid', "You weren't able to upvote that post");
+ }
+ })
+});
+// database of each coding bat exercise
+if (Exercises.find().count() === 0) {
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "sleepIn",
+ "inputs": [
+ "(true, true)",
+ "(true, false)",
+ "(false, true)",
+ "(false, false)"
+ ],
+ "setup": setup.sleepIn
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "diff21",
+ "inputs": [
+ "(19)",
+ "(10)",
+ "(21)",
+ "(22)",
+ "(25)",
+ "(30)",
+ "(0)",
+ "(1)",
+ "(2)",
+ "(-1)",
+ "(-2)",
+ "(50)",
+ ],
+ "setup": setup.diff21
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "nearHundred",
+ "inputs": [
+ "(93)",
+ "(90)",
+ "(89)",
+ "(110)",
+ "(111)",
+ "(121)",
+ "(0)",
+ "(5)",
+ "(191)",
+ "(189)"
+ ],
+ "setup": setup.nearHundred
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "missingChar",
+ "inputs": [
+ "('kitten', 1)",
+ "('kitten', 0)",
+ "('kitten', 4)",
+ "('Hi', 0)",
+ "('Hi', 1)",
+ "('code', 0)",
+ "('code', 1)",
+ "('code', 2)",
+ "('code', 3)",
+ "('chocolate', 8)"
+ ],
+ "setup": setup.missingChar
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "backAround",
+ "inputs": [
+ "('cat')",
+ "('Hello')",
+ "('a')",
+ "('abc')",
+ "('read')",
+ "('boo')"
+ ],
+ "setup": setup.backAround
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "startHi",
+ "inputs": [
+ "('hi there')",
+ "('hi')",
+ "('hello hi')",
+ "('he')",
+ "('h')",
+ "('')",
+ "('ho hi')",
+ "('hi ho')"
+ ],
+ "setup": setup.startHi
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "hasTeen",
+ "inputs": [
+ "(13, 20, 10)",
+ "(20, 19, 10)",
+ "(20, 10, 13)",
+ "(1, 20, 12)",
+ "(19, 20, 12)",
+ "(12, 20, 19)",
+ "(12, 9, 20)",
+ "(12, 18, 20)",
+ "(14, 2, 20)",
+ "(4, 2, 20)",
+ "(11, 22, 22)"
+ ],
+ "setup": setup.hasTeen
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "mixStart",
+ "inputs": [
+ "('mix snacks')",
+ "('pix snacks')",
+ "('piz snacks')",
+ "('nix')",
+ "('ni')",
+ "('n')"
+ ],
+ "setup": setup.mixStart
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "close10",
+ "inputs": [
+ "(8, 13)",
+ "(13, 8)",
+ "(13, 7)",
+ "(7, 13)",
+ "(9, 13)",
+ "(13, 8)",
+ "(10, 12)",
+ "(11, 10)",
+ "(5, 21)",
+ "(0, 20)",
+ "(0, 20)",
+ "(10, 10)"
+ ],
+ "setup": setup.close10
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "stringE",
+ "inputs": [
+ "('Hello')",
+ "('Heelle')",
+ "('Heelele')",
+ "('HII')",
+ "('e')",
+ "('')"
+ ],
+ "setup": setup.stringE
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "everyNth",
+ "inputs": [
+ "('Miracle', 2)",
+ "('abcdefg', 2)",
+ "('abcdefg', 3)",
+ "('Chocolate', 3)",
+ "('Chocolates', 3)",
+ "('Chocolates', 4)",
+ "('Chocolates', 100)"
+ ],
+ "setup": setup.everyNth
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "monkeyTrouble",
+ "inputs": [
+ "(true, true)",
+ "(false, false)",
+ "(true, false)",
+ "(false, true)"
+ ],
+ "setup": setup.monkeyTrouble
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "parrotTrouble",
+ "inputs": [
+ "(true, 6)",
+ "(true, 7)",
+ "(false, 6)",
+ "(true, 21)",
+ "(false, 21)",
+ "(true, 23)",
+ "(false, 23)",
+ "(true, 20)",
+ "(false, 12)"
+ ],
+ "setup": setup.parrotTrouble
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "frontBack",
+ "inputs": [
+ "('code')",
+ "('a')",
+ "('ab')",
+ "('abc')",
+ "('')",
+ "('Chocolate')",
+ "('aavj')",
+ "('hello')"
+ ],
+ "setup": setup.frontBack
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "or35",
+ "inputs": [
+ "(3)",
+ "(10)",
+ "(8)",
+ "(15)",
+ "(5)",
+ "(4)",
+ "(9)",
+ "(4)",
+ "(7)",
+ "(6)",
+ "(17)",
+ "(18)",
+ "(29)",
+ "(20)",
+ "(21)",
+ "(22)",
+ "(45)",
+ "(99)",
+ "(100)",
+ "(101)",
+ "(121)",
+ "(122)",
+ "(123)"
+ ],
+ "setup": setup.or35
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "posNeg",
+ "inputs": [
+ "(1, -1, false)",
+ "(-1, 1, false)",
+ "(-4, -5, true)",
+ "(-4, -5, false)",
+ "(-4, 5, false)",
+ "(-4, 5, true)",
+ "(1, 1, false)",
+ "(-1, -1, false)",
+ "(1, -1, true)",
+ "(-1, 1, true)",
+ "(1, 1, true)",
+ "(-1, -1, true)",
+ "(5, -5, false)",
+ "(-6, 6, false)",
+ "(-5, -6, false)",
+ "(-2, -1, false)",
+ "(1, 2, false)",
+ "(-5, 6, true)",
+ "(-5, -5, true)"
+ ],
+ "setup": setup.posNeg
+ });
+ Exercises.insert({
"section": "warmup-1",
"name": "icyHot",
"inputs": [
@@ -344,525 +360,525 @@ Meteor.publish("allUserData", function() {
"setup": setup.icyHot
});
Exercises.insert({
- "section": "warmup-1",
- "name": "loneTeen",
- "inputs": [
- "(13, 99)",
- "(21, 19)",
- "(13, 13)",
- "(14, 20)",
- "(20, 15)",
- "(16, 17)",
- "(16, 9)",
- "(16, 18)",
- "(13, 19)",
- "(13, 20)",
- "(6, 18)",
- "(99, 13)",
- "(99, 99)"
- ],
- "setup": setup.loneTeen
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "startOz",
- "inputs": [
- "('ozymandias')",
- "('bzoo')",
- "('oxx')",
- "('ounce')",
- "('o')",
- "('abc')",
- "('')",
- "('zoo')",
- "('aztec')",
- "('zzzz')",
- "('oznic')"
- ],
- "setup": setup.startOz
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "in3050",
- "inputs": [
- "(30, 31)",
- "(30, 41)",
- "(40, 50)",
- "(40, 51)",
- "(39, 50)",
- "(50, 39)",
- "(40, 39)",
- "(49, 48)",
- "(50, 40)",
- "(50, 51)",
- "(35, 36)",
- "(35, 45)"
- ],
- "setup": setup.in3050
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "lastDigit",
- "inputs": [
- "(7, 17)",
- "(6, 17)",
- "(3, 113)",
- "(114, 113)",
- "(114, 4)",
- "(10, 0)",
- "(11, 0)"
- ],
- "setup": setup.lastDigit
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "sumDouble",
- "inputs": [
- "(1, 2)",
- "(3, 2)",
- "(2, 2)",
- "(-1, 0)",
- "(3, 3)",
- "(0, 0)",
- "(0, 1)",
- "(3, 4)"
- ],
- "setup": setup.sumDouble
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "makes10",
- "inputs": [
- "(9, 10)",
- "(9, 9)",
- "(1, 9)",
- "(10, 1)",
- "(10, 10)",
- "(8, 2)",
- "(8, 3)",
- "(10, 42)",
- "(12, -2)"
- ],
- "setup": setup.makes10
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "notString",
- "inputs": [
- "('candy')",
- "('x')",
- "('not bad')",
- "('bad')",
- "('not')",
- "('is not')",
- "('no')"
- ],
- "setup": setup.notString
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "front3",
- "inputs": [
- "('Java')",
- "('Chocolate')",
- "('abc')",
- "('abcXYZ')",
- "('ab')",
- "('a')",
- "('')"
- ],
- "setup": setup.front3
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "front22",
- "inputs": [
- "('kitten')",
- "('Ha')",
- "('abc')",
- "('ab')",
- "('a')",
- "('')",
- "('Logic')"
- ],
- "setup": setup.front22
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "in1020",
- "inputs": [
- "(12, 99)",
- "(21, 12)",
- "(8, 99)",
- "(99, 10)",
- "(20, 20)",
- "(21, 21)",
- "(9, 9)",
- ],
- "setup": setup.in1020
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "delDel",
- "inputs": [
- "('adelbc')",
- "('adelHello')",
- "('abcdel')",
- "('add')",
- "('ad')",
- "('a')",
- "('')",
- "('del')",
- "('adel')",
- "('aadelbb')"
- ],
- "setup": setup.delDel
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "intMax",
- "inputs": [
- "(1, 2, 3)",
- "(1, 3, 2)",
- "(3, 2, 1)",
- "(9, 3, 3)",
- "(3, 9, 3)",
- "(3, 3, 9)",
- "(8, 2, 3)",
- "(-3, -1, -2)",
- "(6, 2, 5)",
- "(5, 6, 2)",
- "(5, 2, 6)"
- ],
- "setup": setup.intMax
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "max1020",
- "inputs": [
- "(11, 19)",
- "(19, 11)",
- "(11, 9)",
- "(9, 21)",
- "(10, 21)",
- "(21, 10)",
- "(9, 11)",
- "(23, 10)",
- "(20, 10)",
- "(7, 20)",
- "(17, 16)"
- ],
- "setup": setup.max1020
- });
- Exercises.insert({
- "section": "warmup-1",
- "name": "endUp",
- "inputs": [
- "('Hello')",
- "('hi there')",
- "('hi')",
- "('woo hoo')",
- "('xyz12')",
- "('x')",
- "('')"
- ],
- "setup": setup.endUp
+ "section": "warmup-1",
+ "name": "loneTeen",
+ "inputs": [
+ "(13, 99)",
+ "(21, 19)",
+ "(13, 13)",
+ "(14, 20)",
+ "(20, 15)",
+ "(16, 17)",
+ "(16, 9)",
+ "(16, 18)",
+ "(13, 19)",
+ "(13, 20)",
+ "(6, 18)",
+ "(99, 13)",
+ "(99, 99)"
+ ],
+ "setup": setup.loneTeen
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "startOz",
+ "inputs": [
+ "('ozymandias')",
+ "('bzoo')",
+ "('oxx')",
+ "('ounce')",
+ "('o')",
+ "('abc')",
+ "('')",
+ "('zoo')",
+ "('aztec')",
+ "('zzzz')",
+ "('oznic')"
+ ],
+ "setup": setup.startOz
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "in3050",
+ "inputs": [
+ "(30, 31)",
+ "(30, 41)",
+ "(40, 50)",
+ "(40, 51)",
+ "(39, 50)",
+ "(50, 39)",
+ "(40, 39)",
+ "(49, 48)",
+ "(50, 40)",
+ "(50, 51)",
+ "(35, 36)",
+ "(35, 45)"
+ ],
+ "setup": setup.in3050
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "lastDigit",
+ "inputs": [
+ "(7, 17)",
+ "(6, 17)",
+ "(3, 113)",
+ "(114, 113)",
+ "(114, 4)",
+ "(10, 0)",
+ "(11, 0)"
+ ],
+ "setup": setup.lastDigit
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "sumDouble",
+ "inputs": [
+ "(1, 2)",
+ "(3, 2)",
+ "(2, 2)",
+ "(-1, 0)",
+ "(3, 3)",
+ "(0, 0)",
+ "(0, 1)",
+ "(3, 4)"
+ ],
+ "setup": setup.sumDouble
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "makes10",
+ "inputs": [
+ "(9, 10)",
+ "(9, 9)",
+ "(1, 9)",
+ "(10, 1)",
+ "(10, 10)",
+ "(8, 2)",
+ "(8, 3)",
+ "(10, 42)",
+ "(12, -2)"
+ ],
+ "setup": setup.makes10
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "notString",
+ "inputs": [
+ "('candy')",
+ "('x')",
+ "('not bad')",
+ "('bad')",
+ "('not')",
+ "('is not')",
+ "('no')"
+ ],
+ "setup": setup.notString
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "front3",
+ "inputs": [
+ "('Java')",
+ "('Chocolate')",
+ "('abc')",
+ "('abcXYZ')",
+ "('ab')",
+ "('a')",
+ "('')"
+ ],
+ "setup": setup.front3
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "front22",
+ "inputs": [
+ "('kitten')",
+ "('Ha')",
+ "('abc')",
+ "('ab')",
+ "('a')",
+ "('')",
+ "('Logic')"
+ ],
+ "setup": setup.front22
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "in1020",
+ "inputs": [
+ "(12, 99)",
+ "(21, 12)",
+ "(8, 99)",
+ "(99, 10)",
+ "(20, 20)",
+ "(21, 21)",
+ "(9, 9)",
+ ],
+ "setup": setup.in1020
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "delDel",
+ "inputs": [
+ "('adelbc')",
+ "('adelHello')",
+ "('abcdel')",
+ "('add')",
+ "('ad')",
+ "('a')",
+ "('')",
+ "('del')",
+ "('adel')",
+ "('aadelbb')"
+ ],
+ "setup": setup.delDel
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "intMax",
+ "inputs": [
+ "(1, 2, 3)",
+ "(1, 3, 2)",
+ "(3, 2, 1)",
+ "(9, 3, 3)",
+ "(3, 9, 3)",
+ "(3, 3, 9)",
+ "(8, 2, 3)",
+ "(-3, -1, -2)",
+ "(6, 2, 5)",
+ "(5, 6, 2)",
+ "(5, 2, 6)"
+ ],
+ "setup": setup.intMax
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "max1020",
+ "inputs": [
+ "(11, 19)",
+ "(19, 11)",
+ "(11, 9)",
+ "(9, 21)",
+ "(10, 21)",
+ "(21, 10)",
+ "(9, 11)",
+ "(23, 10)",
+ "(20, 10)",
+ "(7, 20)",
+ "(17, 16)"
+ ],
+ "setup": setup.max1020
+ });
+ Exercises.insert({
+ "section": "warmup-1",
+ "name": "endUp",
+ "inputs": [
+ "('Hello')",
+ "('hi there')",
+ "('hi')",
+ "('woo hoo')",
+ "('xyz12')",
+ "('x')",
+ "('')"
+ ],
+ "setup": setup.endUp
});
// start of the string-1 java problems
Exercises.insert({
- "section": "string-1",
- "name": "helloName",
- "inputs": [
- "('Bob')",
- "('Alice')",
- "('X')",
- "('Dolly')",
- "('Alpha')",
- "('Omega')",
- "('Goodbye')",
- "('ho ho ho')",
- "('xyz!')",
- "('Hello!')"
- ],
- "setup": setup.helloName
- });
- Exercises.insert({
- "section": "string-1",
- "name": "makeAbba",
- "inputs": [
- "('Hi', 'Bye')",
- "('Yo', 'Alice')",
- "('What', 'Up')",
- "('aaa', 'bbb')",
- "('x', 'y')",
- "('x', '')",
- "('ba', 'Ya')",
- "('Ya', 'Ya')"
- ],
- "setup": setup.makeAbba
- });
- Exercises.insert({
- "section": "string-1",
- "name": "makeOutWord",
- "inputs": [
- "('<<>>', 'Yay')",
- "('<<>>', 'WooHoo')",
- "('[[]]', 'word')",
- "('HHoo', 'Hello')",
- "('abyz', 'YAY')"
- ],
- "setup": setup.makeOutWord
- });
- Exercises.insert({
- "section": "string-1",
- "name": "extraEnd",
- "inputs": [
- "('Hello')",
- "('ab')",
- "('Hi')",
- "('Candy')",
- "('Code')"
- ],
- "setup": setup.extraEnd
- });
- Exercises.insert({
- "section": "string-1",
- "name": "withoutEnd",
- "inputs": [
- "('Hello')",
- "('java')",
- "('coding')",
- "('code')",
- "('ab')",
- "('Chocolate!')",
- "('kitten')",
- "('woohoo')"
- ],
- "setup": setup.withoutEnd
- });
- Exercises.insert({
- "section": "string-1",
- "name": "comboString",
- "inputs": [
- "('Hello', 'hi')",
- "('Hi', 'Hello')",
- "('aaa', 'b')",
- "('b', 'aaa')",
- "('aaa', '')",
- "('', 'bb')",
- "('aaa', '1234')",
- "('aaa', 'bb')",
- "('a', 'bb')",
- "('bb', 'a')",
- "('a', 'bb')",
- "('xyz', 'ab')"
- ],
- "setup": setup.comboString
- });
- Exercises.insert({
- "section": "string-1",
- "name": "nonStart",
- "inputs": [
- "('Hello', 'There')",
- "('java', 'code')",
- "('shotl', 'java')",
- "('ab', 'xy')",
- "('ab', 'x')",
- "('x', 'ac')",
- "('a', 'x')",
- "('kit', 'kat')",
- "('mart', 'dart')"
- ],
- "setup": setup.nonStart
- });
- Exercises.insert({
- "section": "string-1",
- "name": "firstHalf",
- "inputs": [
- "('WooHoo')",
- "('HelloThere')",
- "('abcdefg')",
- "('ab')",
- "('')",
- "('0123456789')",
- "('kitten')"
- ],
- "setup": setup.firstHalf
- });
- Exercises.insert({
- "section": "string-1",
- "name": "firstTwo",
- "inputs": [
- "('Hello')",
- "('abcdefg')",
- "('ab')",
- "('a')",
- "('')",
- "('kitten')",
- "('hi')",
- "('hiya')"
- ],
- "setup": setup.firstTwo
- });
- Exercises.insert({
- "section": "string-1",
- "name": "left2",
- "inputs": [
- "('Hello')",
- "('java')",
- "('Hi')",
- "('code')",
- "('cat')",
- "('12345')",
- "('Chocolate')",
- "('bricks')"
- ],
- "setup": setup.left2
- });
- Exercises.insert({
- "section": "string-1",
- "name": "right2",
- "inputs": [
- "('Hello')",
- "('java')",
- "('Hi')",
- "('code')",
- "('cat')",
- "('12345')"
- ],
- "setup": setup.right2
- });
- Exercises.insert({
- "section": "string-1",
- "name": "theEnd",
- "inputs": [
- "('Hello', true)",
- "('Hello', false)",
- "('oh', true)",
- "('oh', false)",
- "('x', true)",
- "('x', false)",
- "('java', true)",
- "('chocolate', false)",
- "('1234', true)",
- "('code', false)"
- ],
- "setup": setup.theEnd
- });
- Exercises.insert({
- "section": "string-1",
- "name": "withoutEnd2",
- "inputs": [
- "('Hello')",
- "('abc')",
- "('ab')",
- "('a')",
- "('')",
- "('coldy')",
- "('java code')"
- ],
- "setup": setup.withoutEnd2
- });
- Exercises.insert({
- "section": "string-1",
- "name": "middleTwo",
- "inputs": [
- "('string')",
- "('code')",
- "('Practice')",
- "('ab')",
- "('123456789')"
- ],
- "setup": setup.middleTwo
- });
- Exercises.insert({
- "section": "string-1",
- "name": "endsLy",
- "inputs": [
- "('oddly')",
- "('y')",
- "('oddl')",
- "('olydd')",
- "('ly')",
- "('')",
- "('falsely')",
- "('evenly')"
- ],
- "setup": setup.endsLy
- });
- Exercises.insert({
- "section": "warm-up2",
- "name": "stringTimes",
- "inputs": [
- "('Hi', 2)",
- "('Hi', 3)",
- "('Hi', 1)",
- "('Hi', 0)",
- "('Hi', 5)",
- "('Oh Boy!', 2)",
- "('x', 4)",
- "('', 4)",
- "('code', 2)",
- "('code', 3)"
- ],
- "setup": setup.stringTimes
-});
+ "section": "string-1",
+ "name": "helloName",
+ "inputs": [
+ "('Bob')",
+ "('Alice')",
+ "('X')",
+ "('Dolly')",
+ "('Alpha')",
+ "('Omega')",
+ "('Goodbye')",
+ "('ho ho ho')",
+ "('xyz!')",
+ "('Hello!')"
+ ],
+ "setup": setup.helloName
+ });
Exercises.insert({
- "section": "warm-up2",
- "name": "doubleX",
- "inputs": [
- "('axxbb')",
- "('axaxax')",
- "('xxxxx')",
- "('xaxxx')",
- "('aaaax')",
- "('')",
- "('abc')",
- "('x')",
- "('xx')",
- "('xaxx')"
- ],
- "setup": setup.doubleX
-});
- Exercises.insert({
- "section": "warm-up2",
- "name": "last2",
- "inputs": [
- "('hixxhi')",
- "('xaxxaxaxx')",
- "('axxaaxx')",
- "('xxaxxaxxaxx')",
- "('xaxaxaa')",
- "('xxxx')",
- "('13121312')",
- "('11212')",
- "('13121311')",
- "('hi')",
- "('h')",
- "('')"
- ],
- "setup": setup.last2
-});
-Exercises.insert({
- "section": "warm-up2",
- "name": "altPairs",
- "inputs": [
- "('kitten')",
- "('Chocolate')",
- "('CodingHorror')",
- "('yak')",
- "('ya')",
- "('y')",
- "('')",
- "('ThisThatTheOther')"
- ],
- "setup": setup.altPairs
-});
+ "section": "string-1",
+ "name": "makeAbba",
+ "inputs": [
+ "('Hi', 'Bye')",
+ "('Yo', 'Alice')",
+ "('What', 'Up')",
+ "('aaa', 'bbb')",
+ "('x', 'y')",
+ "('x', '')",
+ "('ba', 'Ya')",
+ "('Ya', 'Ya')"
+ ],
+ "setup": setup.makeAbba
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "makeOutWord",
+ "inputs": [
+ "('<<>>', 'Yay')",
+ "('<<>>', 'WooHoo')",
+ "('[[]]', 'word')",
+ "('HHoo', 'Hello')",
+ "('abyz', 'YAY')"
+ ],
+ "setup": setup.makeOutWord
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "extraEnd",
+ "inputs": [
+ "('Hello')",
+ "('ab')",
+ "('Hi')",
+ "('Candy')",
+ "('Code')"
+ ],
+ "setup": setup.extraEnd
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "withoutEnd",
+ "inputs": [
+ "('Hello')",
+ "('java')",
+ "('coding')",
+ "('code')",
+ "('ab')",
+ "('Chocolate!')",
+ "('kitten')",
+ "('woohoo')"
+ ],
+ "setup": setup.withoutEnd
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "comboString",
+ "inputs": [
+ "('Hello', 'hi')",
+ "('Hi', 'Hello')",
+ "('aaa', 'b')",
+ "('b', 'aaa')",
+ "('aaa', '')",
+ "('', 'bb')",
+ "('aaa', '1234')",
+ "('aaa', 'bb')",
+ "('a', 'bb')",
+ "('bb', 'a')",
+ "('a', 'bb')",
+ "('xyz', 'ab')"
+ ],
+ "setup": setup.comboString
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "nonStart",
+ "inputs": [
+ "('Hello', 'There')",
+ "('java', 'code')",
+ "('shotl', 'java')",
+ "('ab', 'xy')",
+ "('ab', 'x')",
+ "('x', 'ac')",
+ "('a', 'x')",
+ "('kit', 'kat')",
+ "('mart', 'dart')"
+ ],
+ "setup": setup.nonStart
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "firstHalf",
+ "inputs": [
+ "('WooHoo')",
+ "('HelloThere')",
+ "('abcdefg')",
+ "('ab')",
+ "('')",
+ "('0123456789')",
+ "('kitten')"
+ ],
+ "setup": setup.firstHalf
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "firstTwo",
+ "inputs": [
+ "('Hello')",
+ "('abcdefg')",
+ "('ab')",
+ "('a')",
+ "('')",
+ "('kitten')",
+ "('hi')",
+ "('hiya')"
+ ],
+ "setup": setup.firstTwo
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "left2",
+ "inputs": [
+ "('Hello')",
+ "('java')",
+ "('Hi')",
+ "('code')",
+ "('cat')",
+ "('12345')",
+ "('Chocolate')",
+ "('bricks')"
+ ],
+ "setup": setup.left2
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "right2",
+ "inputs": [
+ "('Hello')",
+ "('java')",
+ "('Hi')",
+ "('code')",
+ "('cat')",
+ "('12345')"
+ ],
+ "setup": setup.right2
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "theEnd",
+ "inputs": [
+ "('Hello', true)",
+ "('Hello', false)",
+ "('oh', true)",
+ "('oh', false)",
+ "('x', true)",
+ "('x', false)",
+ "('java', true)",
+ "('chocolate', false)",
+ "('1234', true)",
+ "('code', false)"
+ ],
+ "setup": setup.theEnd
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "withoutEnd2",
+ "inputs": [
+ "('Hello')",
+ "('abc')",
+ "('ab')",
+ "('a')",
+ "('')",
+ "('coldy')",
+ "('java code')"
+ ],
+ "setup": setup.withoutEnd2
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "middleTwo",
+ "inputs": [
+ "('string')",
+ "('code')",
+ "('Practice')",
+ "('ab')",
+ "('123456789')"
+ ],
+ "setup": setup.middleTwo
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "endsLy",
+ "inputs": [
+ "('oddly')",
+ "('y')",
+ "('oddl')",
+ "('olydd')",
+ "('ly')",
+ "('')",
+ "('falsely')",
+ "('evenly')"
+ ],
+ "setup": setup.endsLy
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "stringTimes",
+ "inputs": [
+ "('Hi', 2)",
+ "('Hi', 3)",
+ "('Hi', 1)",
+ "('Hi', 0)",
+ "('Hi', 5)",
+ "('Oh Boy!', 2)",
+ "('x', 4)",
+ "('', 4)",
+ "('code', 2)",
+ "('code', 3)"
+ ],
+ "setup": setup.stringTimes
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "doubleX",
+ "inputs": [
+ "('axxbb')",
+ "('axaxax')",
+ "('xxxxx')",
+ "('xaxxx')",
+ "('aaaax')",
+ "('')",
+ "('abc')",
+ "('x')",
+ "('xx')",
+ "('xaxx')"
+ ],
+ "setup": setup.doubleX
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "last2",
+ "inputs": [
+ "('hixxhi')",
+ "('xaxxaxaxx')",
+ "('axxaaxx')",
+ "('xxaxxaxxaxx')",
+ "('xaxaxaa')",
+ "('xxxx')",
+ "('13121312')",
+ "('11212')",
+ "('13121311')",
+ "('hi')",
+ "('h')",
+ "('')"
+ ],
+ "setup": setup.last2
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "altPairs",
+ "inputs": [
+ "('kitten')",
+ "('Chocolate')",
+ "('CodingHorror')",
+ "('yak')",
+ "('ya')",
+ "('y')",
+ "('')",
+ "('ThisThatTheOther')"
+ ],
+ "setup": setup.altPairs
+ });
-Exercises.insert({
- "section": "warm-up2",
- "name": "noTriples",
- "inputs": [
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "noTriples",
+ "inputs": [
"([1,1,2,2,1])",
"([1,1,2,2,2,1])",
"([1,1,2,2,2,1])",
@@ -872,160 +888,160 @@ Exercises.insert({
"([1])",
"([1])",
"([])"
- ],
- "setup": setup.noTriples
-});
+ ],
+ "setup": setup.noTriples
+ });
Exercises.insert({
- "section": "warm-up2",
- "name": "frontTimes",
- "inputs": [
- "('Chocolate', 2)",
- "('Chocolate', 3)",
- "('Abc', 3)",
- "('Ab', 4)",
- "('A', 4)",
- "('',4)",
- "('Abc', 0)"
- ],
- "setup": setup.frontTimes
- });
- Exercises.insert({
- "section": "warm-up2",
- "name": "stringBits",
- "inputs": [
- "('Hello')",
- "('Hi')",
- "('Heeololeo')",
- "('HiHiHi')",
- "('')",
- "('Greetings')",
- "('Chocolate')",
- "('pi')",
- "('Hello Kitten')",
- "('hxaxpxpxy')"
- ],
- "setup": setup.stringBits
- });
- Exercises.insert({
- "section": "warm-up2",
- "name": "arrayCount9",
- "inputs": [
- "([1,2,9])",
- "([1,9,9])",
- "([1,9,9,3,9])",
- "([1,2,3])",
- "([])",
- "([4,2,4,3,1])",
- "([9,2,4,3,1])",
- ],
- "setup": setup.arrayCount9
- });
- Exercises.insert({
- "section": "warm-up2",
- "name": "stringMatch",
- "inputs": [
- "('xxcaazz', 'xxbaaz')",
- "('abc', 'abc')",
- "('abc', 'axc')",
- "('hello', 'he')",
- "('he', 'hello')",
- "('', 'hello')",
- "('aabbccdd', 'abbbxxd')",
- "('aaxxaaxx', 'iaxxai')",
- "('iaxxai', 'aaxxaaxx')"
- ],
- "setup": setup.stringMatch
- });
- Exercises.insert({
- "section": "warm-up2",
- "name": "stringYak",
- "inputs": [
- "('yakpak')",
- "('pakyak')",
- "('yak123ya')",
- "('yak')",
- "('yakxxxyak')",
- "('xxcaazz', 'hiyakHi')",
- "(xxxyakyyyakzzz')"
- ],
- "setup": setup.stringYak
- });
- Exercises.insert({
- "section": "warm-up2",
- "name": "has271",
- "inputs": [
- "([1,2,7,1])",
- "([1,2,8,1])",
- "([2,7,1])",
- "([3,8,2])",
- "([2,7,3])",
- "([2,7,4])",
- "([2,7,-1])",
- "([2,7,-2])",
- "([4,5,3,8,0])",
- "([2,7,5,10,4])",
- "([2,7,-2,4,9,3])",
- "([2,7,5,10,1])",
- "([2,7,-2,10,2])"
- ],
- "setup": setup.has271
- });
- Exercises.insert({
- "section": "warm-up2",
- "name": "countXX",
- "inputs": [
- "('abcxx')",
- "('xxx')",
- "('xxxx')",
- "('abc')",
- "('Hello There')",
- "('Hexxo Thxxe')",
- "('')",
- "('Kittens')",
- "('Kittensxxx')"
- ],
- "setup": setup.countXX
- });
- Exercises.insert({
- "section": "warm-up2",
+ "section": "warmup-2",
+ "name": "frontTimes",
+ "inputs": [
+ "('Chocolate', 2)",
+ "('Chocolate', 3)",
+ "('Abc', 3)",
+ "('Ab', 4)",
+ "('A', 4)",
+ "('',4)",
+ "('Abc', 0)"
+ ],
+ "setup": setup.frontTimes
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "stringBits",
+ "inputs": [
+ "('Hello')",
+ "('Hi')",
+ "('Heeololeo')",
+ "('HiHiHi')",
+ "('')",
+ "('Greetings')",
+ "('Chocolate')",
+ "('pi')",
+ "('Hello Kitten')",
+ "('hxaxpxpxy')"
+ ],
+ "setup": setup.stringBits
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "arrayCount9",
+ "inputs": [
+ "([1,2,9])",
+ "([1,9,9])",
+ "([1,9,9,3,9])",
+ "([1,2,3])",
+ "([])",
+ "([4,2,4,3,1])",
+ "([9,2,4,3,1])",
+ ],
+ "setup": setup.arrayCount9
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "stringMatch",
+ "inputs": [
+ "('xxcaazz', 'xxbaaz')",
+ "('abc', 'abc')",
+ "('abc', 'axc')",
+ "('hello', 'he')",
+ "('he', 'hello')",
+ "('', 'hello')",
+ "('aabbccdd', 'abbbxxd')",
+ "('aaxxaaxx', 'iaxxai')",
+ "('iaxxai', 'aaxxaaxx')"
+ ],
+ "setup": setup.stringMatch
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "stringYak",
+ "inputs": [
+ "('yakpak')",
+ "('pakyak')",
+ "('yak123ya')",
+ "('yak')",
+ "('yakxxxyak')",
+ "('xxcaazz', 'hiyakHi')",
+ "(xxxyakyyyakzzz')"
+ ],
+ "setup": setup.stringYak
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "has271",
+ "inputs": [
+ "([1,2,7,1])",
+ "([1,2,8,1])",
+ "([2,7,1])",
+ "([3,8,2])",
+ "([2,7,3])",
+ "([2,7,4])",
+ "([2,7,-1])",
+ "([2,7,-2])",
+ "([4,5,3,8,0])",
+ "([2,7,5,10,4])",
+ "([2,7,-2,4,9,3])",
+ "([2,7,5,10,1])",
+ "([2,7,-2,10,2])"
+ ],
+ "setup": setup.has271
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "countXX",
+ "inputs": [
+ "('abcxx')",
+ "('xxx')",
+ "('xxxx')",
+ "('abc')",
+ "('Hello There')",
+ "('Hexxo Thxxe')",
+ "('')",
+ "('Kittens')",
+ "('Kittensxxx')"
+ ],
+ "setup": setup.countXX
+ });
+ Exercises.insert({
+ "section": "warmup-2",
"name": "arrayFront9",
"inputs": [
- "([1,2,9,3,4])",
- "([1,2,3,4,9])",
- "([1,2,3,4,5])",
- "([9,2,3])",
- "([1,9,9])",
- "([1,2,3])",
- "([1,9])",
- "([5,5])",
- "([2])",
- "([9])",
- "([])",
- "([3,9,2,3,3])"
+ "([1,2,9,3,4])",
+ "([1,2,3,4,9])",
+ "([1,2,3,4,5])",
+ "([9,2,3])",
+ "([1,9,9])",
+ "([1,2,3])",
+ "([1,9])",
+ "([5,5])",
+ "([2])",
+ "([9])",
+ "([])",
+ "([3,9,2,3,3])"
],
"setup": setup.arrayFront9
- });
+ });
Exercises.insert({
- "section": "warm-up2",
+ "section": "warmup-2",
"name": "stringX",
"inputs": [
- "('xxHxix')",
- "('abxxxcd')",
- "('xabxxxcdx')",
- "('xKittenx')",
- "('Hello')",
- "('xx')",
- "('x')",
- "('')"
+ "('xxHxix')",
+ "('abxxxcd')",
+ "('xabxxxcdx')",
+ "('xKittenx')",
+ "('Hello')",
+ "('xx')",
+ "('x')",
+ "('')"
],
"setup": setup.stringX
- });
- Exercises.insert({
- "section": "warm-up2",
- "name": "array667",
- "inputs": [
+ });
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "array667",
+ "inputs": [
"([6,6,2])",
"([6,6,2,6])",
"([6,7,2,6])",
@@ -1039,60 +1055,156 @@ Exercises.insert({
"([6,7,6,6])",
"([1,2,3,5,6])",
"([1,2,3,6,6])",
- ],
- "setup": setup.array667
- });
- // start just adding indexes after this loop
- allExer = Exercises.find().fetch();
- for (var i = 0; i < allExer.length; i++) {
- Exercises.update(allExer[i]._id, {$set: {index: i}});
+ ],
+ "setup": setup.array667
+ });
+ // start just adding indexes after this loop
+ allExer = Exercises.find().fetch();
+ for (var i = 0; i < allExer.length; i++) {
+ Exercises.update(allExer[i]._id, {
+ $set: {
+ index: i
}
- Exercises.insert({
- "section":"Interview Questions",
- "name": "isHere",
- "inputs": [
- "('l', 'hello')",
- "('L', 'hello')",
- "('f', 'FooFiff')",
- "('d', 'DavidBowied')",
- "('A', 'AlanAackman')",
- "('o', 'coolZOO')",
- "('s', 'secksysocks')",
- "('y', 'tylersmith')",
- "('t', 'tatmatt')",
- ],
- "setup": setup.isHere,
- "index": 60
- });
- Exercises.insert({
- "section":"Interview Questions",
- "name": "biggestPre",
- "inputs": [
- "(['yes', 'yodel', 'yeah'])",
- "(['we', 'were', 'when', 'weat'])",
- "(['me', 'meat', 'meander', 'mexico'])",
- "(['tyler', 'tyedye', 'tinder', 'texting'])",
- "(['cameron', 'camera', 'cameleon', 'cameroon'])",
- "(['asha', 'ash ketchum', 'acid', 'ass'])"
- ],
- "setup": setup.biggestPre,
- "index": 61
- });
- Exercises.insert({
- "section":"string-1",
- "name": "nTwice",
- "inputs": [
- "('hello', 2)",
- "('Chocolate', 3)",
- "('Chocolate', 1)",
- "('Chocolate', 0)",
- "('Hello', 4)",
- "('Code', 4)",
- "('Code', 2)"
- ],
- "setup": setup.nTwice,
- "index": 62
- });
+ });
+ }
+ Exercises.insert({
+ "section": "Interview Questions",
+ "name": "isHere",
+ "inputs": [
+ "('l', 'hello')",
+ "('L', 'hello')",
+ "('f', 'FooFiff')",
+ "('d', 'DavidBowied')",
+ "('A', 'AlanAackman')",
+ "('o', 'coolZOO')",
+ "('s', 'secksysocks')",
+ "('y', 'tylersmith')",
+ "('t', 'tatmatt')",
+ ],
+ "setup": setup.isHere,
+ "index": 60
+ });
+ Exercises.insert({
+ "section": "Interview Questions",
+ "name": "biggestPre",
+ "inputs": [
+ "(['yes', 'yodel', 'yeah'])",
+ "(['we', 'were', 'when', 'weat'])",
+ "(['me', 'meat', 'meander', 'mexico'])",
+ "(['tyler', 'tyedye', 'tinder', 'texting'])",
+ "(['cameron', 'camera', 'cameleon', 'cameroon'])",
+ "(['asha', 'ash ketchum', 'acid', 'ass'])"
+ ],
+ "setup": setup.biggestPre,
+ "index": 61
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "nTwice",
+ "inputs": [
+ "('hello', 2)",
+ "('Chocolate', 3)",
+ "('Chocolate', 1)",
+ "('Chocolate', 0)",
+ "('Hello', 4)",
+ "('Code', 4)",
+ "('Code', 2)"
+ ],
+ "setup": setup.nTwice,
+ "index": 62
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "makeTags",
+ "inputs": [
+ "('i','Yay')",
+ "('i','Hello')",
+ "('cite','Yay')",
+ "('address','here')",
+ "('body','Heart')",
+ "('i','i')",
+ "('i','')"
+ ],
+ "setup": setup.makeTags,
+ "index": 63
+ });
+ Exercises.insert({
+ "section": "string-1",
+ "name": "twoChar",
+ "inputs": [
+ '("java", 0)',
+ '("java", 2)',
+ '("java", 3)',
+ '("java", 4)',
+ '("java", -1)',
+ '("Hello", 0)',
+ '("Hello", 1)',
+ '("Hello", 99)',
+ '("Hello", 3)',
+ '("Hello", 4)',
+ '("Hello", 5)',
+ '("Hello", -7)',
+ '("Hello", 6)',
+ '("Hello", -1)',
+ '("yay", 0)'
+ ],
+ "setup": setup.twoChar,
+ "index": 64
+ });
+
+ Exercises.insert({
+ "section": "string-1",
+ "name": "middleThree",
+ "inputs": [
+ '("Candy")',
+ '("and")',
+ '("solving")',
+ '("Hi yet Hi")',
+ '("java yet java")',
+ '("Chocolate")',
+ '("XabcxyzabcX")'
+ ],
+ "setup": setup.middleThree,
+ "index": 65
+ });
+
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "array123",
+ "inputs": [
+ '([1, 1, 2, 3, 1])',
+ '([1, 1, 2, 4, 1])',
+ '([1, 1, 2, 1, 2, 3])',
+ '([1, 1, 2, 1, 2, 1])',
+ '([1, 2, 3, 1, 2, 3])',
+ '([1, 2, 3])',
+ '([1, 1, 1])',
+ '([1, 2])',
+ '([1])',
+ '([])'
+ ],
+ "setup": setup.array123,
+ "index": 66
+ });
+
+ Exercises.insert({
+ "section": "warmup-2",
+ "name": "stringSplosion",
+ "inputs": [
+ '("Code")',
+ '("abc")',
+ '("ab")',
+ '("x")',
+ '("fade")',
+ '("There")',
+ '("Kitten")',
+ '("Bye")',
+ '("Good")',
+ '("Bad")'
+ ],
+ "setup": setup.stringSplosion,
+ "index": 67
+ });
-// end of if data base empty ( if exercise is already in cloud databse, don't add again!)
+ // end of if data base empty ( if exercise is already in cloud database, don't add again!)
}
diff --git a/solutions.js b/solutions.js
index e31f214..f8b029c 100755
--- a/solutions.js
+++ b/solutions.js
@@ -5,325 +5,235 @@
solutions = {}
solutions.sleepIn = function(weekday, vacation) {
- return !weekday || vacation;
+ return !weekday || vacation;
}
-// Java > Warm-up1 > diff21
+// Java > Warmup-1 > diff21
// Given an int n, return the absolute difference between n and 21,
// except return double the absolute difference if n is over 21.
solutions.diff21 = function(n) {
- if (n <= 21){
- return 21 - n;
- }
- else{
- return (n - 21) * 2;
- }
+ if (n <= 21) return 21 - n;
+ else return (n - 21) * 2;
}
-// Java > Warm-up1 > nearHundred
+// Java > Warmup-1 > nearHundred
// Given an int n, return True if it is within 10 of 100 or 200.
// Note: abs(num) computes the absolute value of a number.
solutions.nearHundred = function(n) {
- return ((Math.abs(100 - n) <= 10) ||
- (Math.abs(200 - n) <= 10));
- }
+ return ((Math.abs(100 - n) <= 10) ||
+ (Math.abs(200 - n) <= 10));
+}
-// Java > Warm-up1 > missingChar
+// Java > Warmup-1 > missingChar
//Given a non-empty string and an int n, return a new string where the char at
//index n has been removed. The value of n will be a valid index of a char in the
//original string (i.e. n will be in the range 0..str.length()-1 inclusive).
solutions.missingChar = function(str, n) {
- front = str.substring(0,n);
- back = str.substring(n+1, str.length);
- return front + back;
+ return str.substring(0, n) + str.substring(n + 1);
}
// console.log(missingChar("kitten", 1));
// console.log(missingChar("kitten", 0));
-// Java > Warm-up1 > backAround
+// Java > Warmup-1 > backAround
//Given a string, take the last char and return a new string with the last char added at
//the front and back, so "cat" yields "tcatt". The original string will be length 1 or more.
-solutions.backAround = function(str){
- last = str.substring(str.length-1);
- return last + str + last;
+solutions.backAround = function(str) {
+ var last = str.slice(-1);
+ return last + str + last;
}
-// console.log(backAround("cat"));
-// console.log(backAround("Hello"));
-// console.log(backAround("a"));
+// console.log(solutions.backAround("cat"));
+// console.log(solutions.backAround("Hello"));
+// console.log(solutions.backAround("a"));
-// Java > Warm-up1 > startHi
+// Java > Warmup-1 > startHi
// Given a string, return true if the string starts with "hi" and false otherwise.
-solutions.startHi = function(str){
- if (str.length < 2){
- return false;
- }
- front = str.substring(0,2);
- if (front == "hi"){
- return true;
- }
- else {
- return false;
- }
-}
-// console.log(startHi("hi there"));
-// console.log(startHi("hi"));
-// console.log(startHi("hello hi"));
-
-// Java > Warm-up1 > hasTeen
+solutions.startHi = function(str) {
+ return !str.indexOf('hi');
+}
+// console.log(solutions.startHi("hi there"));
+// console.log(solutions.startHi("hi"));
+// console.log(solutions.startHi("hello hi"));
+
+// Java > Warmup-1 > hasTeen
// We'll say that a number is "teen" if it is in the range 13..19 inclusive.
// Given 3 int values, return true if 1 or more of them are teen.
-solutions.hasTeen = function(a, b, c){
- return (a>=13 && a<=19) || (b>=13 && b<=19) || (c>=13 && c<=19);
+solutions.hasTeen = function(a, b, c) {
+ return [a, b, c].some(function(n) {
+ return n >= 13 && n <= 19
+ });
}
// console.log(solutions.hasTeen(13, 20, 10));
// console.log(solutions.hasTeen(20, 19, 10));
// console.log(solutions.hasTeen(20, 10, 13));
-// Java > Warm-up1 > mixStart
+// Java > Warmup-1 > mixStart
// Return true if the given string begins with "mix", except the 'm' can be anything,
//so "pix", "9ix" .. all count.
-solutions.mixStart = function(str){
- if (str.length<3){
- return false;
- }
- two = str.substring(1,3);
- if (two == "ix"){
- return true;
- }
- else{
- return false;
- }
+solutions.mixStart = function(str) {
+ return str.indexOf('ix') === 1;
}
// console.log(mixStart("mix snacks"));
// console.log(mixStart("piz snacks"));
-// Java > Warm-up1 > close10
+// Java > Warmup-1 > close10
// Given 2 int values, return whichever value is nearest to the value 10,
// or return 0 in the event of a tie. Note that Math.abs(n) returns the absolute value
// of a number.
-solutions.close10 = function(a, b){
- aDiff = Math.abs(a-10);
- bDiff = Math.abs(b-10);
-
- if (aDiff < bDiff){
- return a;
- }
- if (bDiff < aDiff){
- return b;
- }
- return 0;
-}
-// console.log(close10(8,13));
-// console.log(close10(13,8));
-
-// Java > Warm-up1 > stringE
+solutions.close10 = function(a, b) {
+ var aDiff = Math.abs(a - 10);
+ var bDiff = Math.abs(b - 10);
+
+ if (aDiff < bDiff) return a;
+ if (bDiff < aDiff) return b;
+ return 0;
+}
+// console.log(solutions.close10(8,13));
+// console.log(solutions.close10(13,8));
+// console.log(solutions.close10(13,7));
+
+// Java > Warmup-1 > stringE
// Return true if the given string contains between 1 and 3 'e' chars.
-solutions.stringE = function(str){
- count = 0;
- for(var i=0; i= 1 && count <= 3);
-}
-// console.log(stringE("Hello"));
-// console.log(stringE("Heelle"));
-// console.log(stringE("Heelele"));
-
-// Java > Warm-up1 > everyNth
+solutions.stringE = function(str) {
+ var eCount = str.replace(/[^e]/g, '').length;
+ return (eCount >= 1 && eCount <= 3);
+}
+// console.log(solutions.stringE("Hello"));
+// console.log(solutions.stringE("Heelle"));
+// console.log(solutions.stringE("Heelele"));
+
+// Java > Warmup-1 > everyNth
// Given a non-empty string and an int N, return the string made starting with char 0,
// and then every Nth char of the string. So if N is 3, use char 0, 3, 6, ... and so on.
// N is 1 or more.
-solutions.everyNth = function(str, n){
- result = "";
- for(var i=0; i Warm-up1 > monkeyTrouble
+solutions.everyNth = function(str, n) {
+ return str.split('').filter(function(c, i) {
+ return !(i % n)
+ }).join('');
+}
+// console.log(solutions.everyNth("Miracle", 2));
+// console.log(solutions.everyNth("abcdefg", 2));
+// console.log(solutions.everyNth("abcdefg", 3));
+
+// Java > Warmup-1 > monkeyTrouble
// We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if each
// is smiling. We are in trouble if they are both smiling or if neither of them is smiling.
// Return true if we are in trouble.
-solutions.monkeyTrouble = function(aSmile, bSmile){
- if(aSmile && bSmile){
- return true;
- }
- if(!aSmile && !bSmile){
- return true;
- }
- return false;
+solutions.monkeyTrouble = function(aSmile, bSmile) {
+ return aSmile === bSmile;
}
// console.log(monkeyTrouble(true, true));
// console.log(monkeyTrouble(false, false));
// console.log(monkeyTrouble(true, false));
-// Java > Warm-up1 > parrotTrouble
+// Java > Warmup-1 > parrotTrouble
// We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23.
//We are in trouble if the parrot is talking and the hour is before 7 or after 20.
//Return True if we are in trouble.
solutions.parrotTrouble = function(talking, hour) {
- if (talking === true && (hour < 7 || hour > 20)) {
- return true;
- }
- else {
- return false;
- }
+ return talking && (hour < 7 || hour > 20);
}
// console.log(parrotTrouble(true, 6));
// console.log(parrotTrouble(true, 7));
// console.log(parrotTrouble(false, 6));
-// Java > Warm-up1 > posNeg
+// Java > Warmup-1 > posNeg
//Given 2 int values, return True if one is negative and one is positive.
//Except if the parameter "negative" is True, then return True only if
//both are negative.
solutions.posNeg = function(a, b, negative) {
- if (negative === true) {
- return a < 0 && b < 0;
- }
- if ((a < 0 && b > 0) || a > 0 && b < 0) {
- return true;
- } else {
- return false;
- }
+ if (negative) return a < 0 && b < 0;
+ return (a < 0 && b > 0) || (a > 0 && b < 0);
};
// console.log(posNeg(1, -1, false));
// console.log(posNeg(-1, 1, false));
// console.log(posNeg(-4, -5, true));
-// Java > Warm-up1 > frontBack
+// Java > Warmup-1 > frontBack
// Given a string, return a new string where the first and last chars have been exchanged.
-solutions.frontBack = function(str){
- if (str.length <= 1){
- return str;
- }
- mid = str.substring(1, str.length-1);
-
- return (str.charAt(str.length-1)) + mid + str.charAt(0);
+solutions.frontBack = function(str) {
+ if (str.length < 2) return str;
+ return str.slice(-1) + str.slice(1, -1) + str[0];
}
-//console.log(solutions.frontBack("code"));
-//console.log(solutions.frontBack("a"));
-//console.log(solutions.frontBack("ab"));
+// console.log(solutions.frontBack("code"));
+// console.log(solutions.frontBack("a"));
+// console.log(solutions.frontBack("ab"));
-// Java > Warm-up1 > or35
+// Java > Warmup-1 > or35
// Return true if the given non-negative number is a multiple of 3 or a multiple of 5.
//Use the % "mod" operator
-solutions.or35 = function(n){
- if(n % 3 == 0 || n % 5 == 0){
- return true;
- }
- else{
- return false;
- }
+solutions.or35 = function(n) {
+ return (!(n % 3) || !(n % 5));
}
// console.log(or35(3));
// console.log(or35(10));
// console.log(or35(8));
-// Java > Warm-up1 > icyHot
+// Java > Warmup-1 > icyHot
// Given two temperatures, return true if one is less than 0 and the other is greater than 100.
-solutions.icyHot = function(temp1, temp2){
- if (temp1 < 0 && temp2 > 100 || temp2 < 0 && temp1 > 100){
- return true;
- }
- return false;
+solutions.icyHot = function(temp1, temp2) {
+ return (temp1 < 0 && temp2 > 100 || temp2 < 0 && temp1 > 100);
}
// console.log(icyHot(120, -1));
// console.log(icyHot(-1, 120));
// console.log(icyHot(2, 120));
-// Java > Warm-up1 > loneTeen
+// Java > Warmup-1 > loneTeen
// We'll say that a number is "teen" if it is in the range 13..19 inclusive.
// Given 2 int values, return true if one or the other is teen, but not both.
solutions.loneTeen = function(a, b) {
- var isTeen = function(num) {
- return num >= 13 && num <= 19;
- };
- var isTeenA = isTeen(a);
- var isTeenB = isTeen(b);
- return isTeenA && !isTeenB || !isTeenA && isTeenB;
+ var isTeen = function(n) {
+ return n >= 13 && n <= 19
+ };
+ return isTeen(a) !== isTeen(b);
}
-// console.log(loneTeen(13, 99));
-// console.log(loneTeen(21, 19));
-// console.log(loneTeen(13, 13));
+// console.log(solutions.loneTeen(13, 99));
+// console.log(solutions.loneTeen(21, 19));
+// console.log(solutions.loneTeen(13, 13));
-// Java > Warm-up1 > startOz
+// Java > Warmup-1 > startOz
// Given a string, return a string made of the first 2 chars (if present),
// however include first char only if it is 'o' and include the second only if it is 'z',
// so "ozymandias" yields "oz".
-solutions.startOz = function(str){
- result = "";
-
- if(str.length >= 1 && str.charAt(0) == "o"){
- result += str.charAt(0);
- }
- if(str.length >= 2 && str.charAt(1) == "z"){
- result += str.charAt(1);
- }
- return result;
-}
-// console.log(startOz("ozymandias"));
-// console.log(startOz("bzoo"));
-// console.log(startOz("oxx"));
-
-
-// Java > Warmup-1 > intTener
-//Given 2 ints, a and b, return True if one of them is 10 or if their sum is 10.
-// var intTener = function(a, b) {
-// if (a === 10 || b === 10 || a + b === 10){
-// return true;
-// }
-// else {
-// return false;
-// }
-// }
-// console.log(intTener(9, 10));
-// console.log(intTener(9, 9));
-// console.log(intTener(1, 9));
+solutions.startOz = function(str) {
+ var result = '';
+ if (str[0] === 'o') result += 'o';
+ if (str[1] === 'z') result += 'z';
+ return result;
+}
+// console.log(solutions.startOz("ozymandias"));
+// console.log(solutions.startOz("bzoo"));
+// console.log(solutions.startOz("oxx"));
// Java > Warmup-1 > in3050
// Given 2 int values, return true if they are both in the range 30..40 inclusive,
// or they are both in the range 40..50 inclusive.
solutions.in3050 = function(a, b) {
- if ((a >= 30 && a<=40 && b>=30 && b<=40) || (a >=40 && a<=50 && b>=40 && b<=50)){
- return true;
- }
- else {
- return false;
- }
+ var inRange = function(n) {
+ return n >= 0 && n <= 10
+ };
+ return (inRange(a - 30) && inRange(b - 30)) || (inRange(a - 40) && inRange(b - 40));
}
-// console.log(in3050(30, 31));
-// console.log(in3050(30, 41));
-// console.log(in3050(40, 50));
+// console.log(solutions.in3050(30, 31));
+// console.log(solutions.in3050(30, 41));
+// console.log(solutions.in3050(40, 50));
// Java > Warmup-1 > lastDigit
// Given two non-negative int values, return true if they have the same last digit,
// such as with 27 and 57. Note that the % "mod" operator computes remainders, so 17 % 10 is 7.
-solutions.lastDigit = function(a, b){
- return (a % 10 == b % 10);
+solutions.lastDigit = function(a, b) {
+ return a % 10 === b % 10;
}
-// console.log(lastDigit(7,17));
-// console.log(lastDigit(6,17));
-// console.log(lastDigit(3,113));
+// console.log(solutions.lastDigit(7,17));
+// console.log(solutions.lastDigit(6,17));
+// console.log(solutions.lastDigit(3,113));
// Java > Warmup-1 > sumDouble
// Given two int values, return their sum. Unless the two values are the same,
// then return double their sum.
-solutions.sumDouble = function(a, b){
- if(a == b){
- return 2*(a+b);
- }
- else {
- return a + b;
- }
+solutions.sumDouble = function(a, b) {
+ return (a === b) ? 2 * (a + b) : a + b;
}
// console.log(sumDouble(1,2));
// console.log(sumDouble(3,2));
@@ -331,8 +241,8 @@ solutions.sumDouble = function(a, b){
// Java > Warmup-1 > makes10
// Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.
-solutions.makes10 = function(a,b){
- return ((a == 10 || b == 10) || (a + b == 10));
+solutions.makes10 = function(a, b) {
+ return (a === 10 || b === 10) || (a + b === 10);
}
// console.log(makes10(9,10));
// console.log(makes10(9,9));
@@ -341,11 +251,9 @@ solutions.makes10 = function(a,b){
// Java > Warmup-1 > notString
// Given a string, return a new string where "not " has been added to the front.
// However, if the string already begins with "not", return the string unchanged.
-solutions.notString = function(str){
- if (str === null || str === undefined || str.substring(0,3) === "not") {
- return str;
- }
- return "not " + str;
+solutions.notString = function(str) {
+ if (!str.indexOf('not')) return str;
+ else return "not " + str;
}
// console.log(notString("candy"));
// console.log(notString("x"));
@@ -355,80 +263,53 @@ solutions.notString = function(str){
// Given a string, we'll say that the front is the first 3 chars of the string.
// If the string length is less than 3, the front is whatever is there.
// Return a new string which is 3 copies of the front.
-solutions.front3 = function(str){
- front = "";
- if (str.length >= 3){
- front = str.substring(0,3);
- }
- else {
- front = str;
- }
- return front + front + front;
-}
-// console.log(front3("Java"));
-// console.log(front3("Chocolate"));
-// console.log(front3("abc"));
+solutions.front3 = function(str) {
+ var front = str.substr(0, 3);
+ return front + front + front;
+}
+// console.log(solutions.front3("Java"));
+// console.log(solutions.front3("Chocolate"));
+// console.log(solutions.front3("abc"));
// Java > Warmup-1 > front22
// Given a string, take the first 2 chars and return the string with the 2 chars added at both the
// front and back, so "kitten" yields"kikittenki". If the string length is less than 2, use whatever
// chars are there.
-solutions.front22 = function(str){
- take = 2;
- if(take > str.length){
- take = str.length;
- }
- front = str.substring(0,take);
- return front + str + front;
-}
-// console.log(front22("kitten"));
-// console.log(front22("Ha"));
-// console.log(front22("abc"));
+solutions.front22 = function(str) {
+ var front = str.substr(0, 2);
+ return front + str + front;
+}
+// console.log(solutions.front22("kitten"));
+// console.log(solutions.front22("Ha"));
+// console.log(solutions.front22("abc"));
// Java > Warmup-1 > in1020
// Given 2 int values, return true if either of them is in the range 10..20 inclusive.
-solutions.in1020 = function(a,b){
- if ((a >= 10 && a <= 20) || (b >= 10 && b <= 20)){
- return true;
- }
- else {
- return false;
- }
-}
-// console.log(in1020(12,99));
-// console.log(in1020(21,12));
-// console.log(in1020(8,99));
+solutions.in1020 = function(a, b) {
+ var inRange = function(n) {
+ return n >= 10 && n <= 20;
+ };
+ return inRange(a) || inRange(b);
+}
+// console.log(solutions.in1020(12,99));
+// console.log(solutions.in1020(21,12));
+// console.log(solutions.in1020(8,99));
// Java > Warmup-1 > delDel
// Given a string, if the string "del" appears starting at index 1, return a string where that "del"
// has been deleted. Otherwise, return the string unchanged.
-solutions.delDel = function(str){
- if (str.length < 4) {
- return str;
- }
- var output = str;
- if (str.substring(1, 4) == "del"){
- output = str.substring(0, 1) + str.substring(4, str.length);
- }
- return output;
-}
-// console.log(delDel("adelbc"));
-// console.log(delDel("adelHello"));
-// console.log(delDel("adebc"));
+solutions.delDel = function(str) {
+ return (str.indexOf('del') === 1) ? str[0] + str.substr(4) : str;
+}
+
+// console.log(solutions.delDel("adelbc"));
+// console.log(solutions.delDel("adelHello"));
+// console.log(solutions.delDel("adedbc"));
// Java > Warmup-1 > intMax
// Given three int values, a b c, return the largest.
-solutions.intMax = function(a,b,c){
- max = 0;
- if ( a > b){
- max = a;
- } else {
- max = b;
- }
- if ( c > max ){
- max = c;
- }
- return max;
+solutions.intMax = function(a, b, c) {
+ return Math.max(a, b, c);
}
// console.log(intMax(1,2,3));
// console.log(intMax(1,3,2));
@@ -437,41 +318,26 @@ solutions.intMax = function(a,b,c){
// Java > Warmup-1 > max1020
// Given 2 positive int values, return the larger value that is in the range 10..20
// inclusive, or return 0 if neither is in that range.
-solutions.max1020 = function(a,b){
- var between1020 = function(num) {
- return 10 <= num && num <= 20;
- };
- var result = 0;
- if (between1020(a)) {
- result = a;
- }
- if (b > result && between1020(b)) {
- result = b;
- }
- return result;
-}
-// console.log(max1020(11,19));
-// console.log(max1020(19,11));
-// console.log(max1020(11,9));
+solutions.max1020 = function(a, b) {
+ var between1020 = function(n) {
+ return (10 <= n && n <= 20) ? n : 0
+ };
+ return Math.max(between1020(a), between1020(b));
+}
+// console.log(solutions.max1020(11,19));
+// console.log(solutions.max1020(19,11));
+// console.log(solutions.max1020(11,9));
// Java > Warmup-1 > endUp
// Given a string, return a new string where the last 3 chars are now in upper case.
// If the string has less than 3 chars, uppercase whatever is there. Note that
// str.toUpperCase() returns the uppercase version of a string.
-solutions.endUp = function(str){
- if(str.length <= 3){
- return str.toUpperCase();
- }
- cut = str.length - 3;
- front = str.substring(0,cut);
- back = str.substring(cut);
-
- return front + back.toUpperCase();
+solutions.endUp = function(str) {
+ return str.slice(0, -3) + str.slice(-3).toUpperCase();
}
-// console.log(endUp("Hello"));
-// console.log(endUp("hi there"));
-// console.log(endUp("hi"));
-
+// console.log(solutions.endUp("Hello"));
+// console.log(solutions.endUp("hi there"));
+// console.log(solutions.endUp("hi"));
@@ -483,8 +349,8 @@ solutions.endUp = function(str){
// Java > String-1 > helloName
// Given a string name, e.g. "Bob", return a greeting of the form "Hello Bob!".
-solutions.helloName = function(name){
- return "Hello " + name;
+solutions.helloName = function(name) {
+ return "Hello " + name;
}
// console.log(helloName("bob"));
// console.log(helloName("Alice"));
@@ -492,8 +358,8 @@ solutions.helloName = function(name){
// Java > String-1 > makeAbba
// Given two strings, a and b, return the result of putting them together in the
// order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi".
-solutions.makeAbba = function(a, b){
- return a + b + b + a;
+solutions.makeAbba = function(a, b) {
+ return a + b + b + a;
}
// console.log(solutions.makeAbba("Hi", "Bye"));
// console.log(makeAbba("Yo", "Alice"));
@@ -503,8 +369,8 @@ solutions.makeAbba = function(a, b){
// The web is built with HTML strings like "Yay" which draws Yay as italic text.
// In this example, the "i" tag makes and which surround the word "Yay".
// Given tag and word strings, create the HTML string with tags around the word, e.g. "Yay".
-solutions.makeTags = function(tag, word){
- return "<"+tag+">"+word+""+tag+">";
+solutions.makeTags = function(tag, word) {
+ return "<" + tag + ">" + word + "" + tag + ">";
}
// console.log(solutions.makeTags("i", "Yay"));
// console.log(solutions.makeTags("i", "Hello"));
@@ -514,10 +380,8 @@ solutions.makeTags = function(tag, word){
// Given an "out" string length 4, such as "<<>>", and a word, return a new string where
// the word is in the middle of the out string, e.g. "<>". Note: use str.substring(i, j)
// to extract the String starting at index i and going up to but not including index j.
-solutions.makeOutWord = function(out, word){
- front = out.substring(0,2);
- back = out.substring(2,4);
- return front + word + back
+solutions.makeOutWord = function(out, word) {
+ return out.slice(0, 2) + word + out.slice(2, 4);
}
// console.log(solutions.makeOutWord("<<>>", "Yay"));
// console.log(solutions.makeOutWord("<<>>", "WooHoo"));
@@ -526,11 +390,8 @@ solutions.makeOutWord = function(out, word){
// Java > String-1 > extraEnd
// Given a string, return a new string made of 3 copies of the last 2 chars
// of the original string. The string length will be at least 2.
-solutions.extraEnd = function(str){
- if (str.length>1){
- back = str.substring(str.length-2);
- return back+back+back;
- }
+solutions.extraEnd = function(str) {
+ return str.slice(-2).repeat(3);
}
// console.log(solutions.extraEnd("Hello"));
// console.log(solutions.extraEnd("ab"));
@@ -539,8 +400,8 @@ solutions.extraEnd = function(str){
// Java > String-1 > withoutEnd
// Given a string, return a version without the first and last char, so "Hello" yields "ell".
// The string length will be at least 2.
-solutions.withoutEnd = function(str){
- return str.substring(1, str.length-1);
+solutions.withoutEnd = function(str) {
+ return str.slice(1, -1);
}
// console.log(solutions.withoutEnd("Hello"));
// console.log(solutions.withoutEnd("java"));
@@ -550,13 +411,12 @@ solutions.withoutEnd = function(str){
// Given 2 strings, a and b, return a string of the form short+long+short, with
// the shorter string on the outside and the longer string on the inside. The
// strings will not be the same length, but they may be empty (length 0).
-solutions.comboString = function(a,b){
- if (a.length < b.length){
- return a+b+a;
- }
- else{
- return b+a+b;
- }
+solutions.comboString = function(a, b) {
+ if (a.length < b.length) {
+ return a + b + a;
+ } else {
+ return b + a + b;
+ }
}
// console.log(solutions.comboString("Hello", "hi"));
// console.log(solutions.comboString("hi", "Hello"));
@@ -565,10 +425,8 @@ solutions.comboString = function(a,b){
// Java > String-1 > nonStart
// Given 2 strings, return their concatenation, except omit the first char
// of each. The strings will be at least length 1.
-solutions.nonStart = function(a,b){
- a = a.substring(1,a.length);
- b = b.substring(1,b.length);
- return a + b;
+solutions.nonStart = function(a, b) {
+ return a.substr(1) + b.substr(1);
}
// console.log(solutions.nonStart("Hello", "There"));
// console.log(solutions.nonStart("java", "code"));
@@ -577,11 +435,8 @@ solutions.nonStart = function(a,b){
// Java > String-1 > firstHalf
// Given a string of even length, return the first half.
// So the string "WooHoo" yields "Woo".
-solutions.firstHalf = function(str){
- if(str.length % 2 == 0){
- return str.substring(0,str.length/2)
- }
- return str
+solutions.firstHalf = function(str) {
+ return str.length % 2 ? str : str.slice(0, str.length / 2);
}
// console.log(firstHalf("WooHoo"));
// console.log(firstHalf("HelloThere"));
@@ -592,11 +447,8 @@ solutions.firstHalf = function(str){
// "Hello" yields "He". If the string is shorter than length 2, return whatever
// there is, so "X" yields "X", and the empty string "" yields the
// empty string "". Note that str.length() returns the length of a string.
-solutions.firstTwo = function(str){
- if(str.length>2){
- return str.substring(0,2);
- }
- return str;
+solutions.firstTwo = function(str) {
+ return str.slice(0, 2);
}
// console.log(solutions.firstTwo("Hello"));
// console.log(solutions.firstTwo("ab"));
@@ -604,13 +456,8 @@ solutions.firstTwo = function(str){
// Java > String-1 > left2
// Given a string, return a "rotated left 2" version where the first 2 chars are
// moved to the end. The string length will be at least 2.
-solutions.left2 = function(str){
- if(str.length>1){
- front = str.substring(0,2);
- back = str.substring(2,str.length);
- return back + front;
- }
- return str;
+solutions.left2 = function(str) {
+ return str.slice(2) + str.slice(0, 2);
}
// console.log(solutions.left2("Hello"));
// console.log(solutions.left2("java"));
@@ -619,13 +466,8 @@ solutions.left2 = function(str){
// Java > String-1 > right2
// Given a string, return a "rotated right 2" version where the last 2 chars are
// moved to the start. The string length will be at least 2.
-solutions.right2 = function(str){
- if(str.length>1){
- back = str.substring(str.length-2,str.length);
- front = str.substring(0,str.length-2);
- return back + front;
- }
- return str;
+solutions.right2 = function(str) {
+ return str.slice(-2) + str.slice(0, -2);
}
// console.log(solutions.right2("Hello"));
// console.log(solutions.right2("java"));
@@ -634,33 +476,22 @@ solutions.right2 = function(str){
// Java > String-1 > theEnd
// Given a string, return a string length 1 from its front, unless front is false,
// in which case return a string length 1 from its back. The string will be non-empty.
-solutions.theEnd = function(str, front){
- if(front){
- return str.substring(0,1);
- }
- return str.substring(str.length-1);
+solutions.theEnd = function(str, front) {
+ return front ? str[0] : str.slice(-1);
}
// Java > String-1 > withouEnd2
// Given a string, return a version without both the first and last char of the
// string. The string may be any length, including 0.
-solutions.withoutEnd2 = function(str){
- if(str.length<=1){
- return "";
- }
- return str.substring(1,str.length-1);
+solutions.withoutEnd2 = function(str) {
+ return str.slice(1, -1);
}
// Java > String-1 > middleTwo
// Given a string of even length, return a string made of the middle two chars,
// so the string "string" yields "ri". The string length will be at least 2.
-solutions.middleTwo = function(str){
- if(str.length % 2 == 0){
- temp = str.substring(str.length/2 -1);
- mid = temp.substring(0,2);
- return mid;
- }
- return str;
+solutions.middleTwo = function(str) {
+ return str.length % 2 ? str : str.substr(str.length / 2 - 1, 2);
}
// console.log(solutions.middleTwo("string"));
// console.log(solutions.middleTwo("code"));
@@ -668,13 +499,8 @@ solutions.middleTwo = function(str){
// Java > String-1 > endsLy
// Given a string, return true if it ends in "ly".
-solutions.endsLy = function(str){
- if(str.substring(str.length-2, str.length) == "ly"){
- return true;
- }
- else{
- return false;
- }
+solutions.endsLy = function(str) {
+ return (str.slice(-2) === "ly");
}
// console.log(solutions.endsLy("oddly"));
// console.log(solutions.endsLy("y"));
@@ -688,10 +514,8 @@ solutions.endsLy = function(str){
// Java > String-1 > nTwice
// Given a string and an int n, return a string made of the first and last n chars
// from the string. The string length will be at least n.
-solutions.nTwice = function(str, n){
- first = str.substring(0, n);
- end = str.substring(str.length-n)
- return first + end;
+solutions.nTwice = function(str, n) {
+ return str.slice(0, n) + str.slice(-1 * n);
}
// console.log(solutions.nTwice("hello", 2));
// console.log(solutions.nTwice("Chocolate", 3));
@@ -705,15 +529,12 @@ solutions.nTwice = function(str, n){
// Given a string and an index, return a string length 2 starting at the given index.
// If the index is too big or too small to define a string length 2, use the first
// 2 chars. The string length will be at least 2.
-// solutions.twoChar = function(str, index){
-// if(str.length>1){
-// x = str.substring(index, index+2);
-// return x;
-// }
-// if(index > str.length-2) {
-// return str.charAt(0) + str.charAt(1);
-// }
-// }
+solutions.twoChar = function(str, index) {
+ if (index > str.length - 2) {
+ index = 0;
+ }
+ return str.substr(index, 2);
+}
// console.log(solutions.twoChar("java", 0));
// console.log(solutions.twoChar("java", 2));
// console.log(solutions.twoChar("java", 3));
@@ -721,143 +542,108 @@ solutions.nTwice = function(str, n){
// Java > String-1 > middleThree
// Given a string of odd length, return the string length 3 from its middle, so
// "Candy" yields "and". The string length will be at least 3.
-// solutions.middleThree = function(str){
-// if(str.length <= 3){
-// return str;
-// }
-// if(str.length % 2 != 0){
-// temp = str.length/2;
-// mid = str.substring(temp, temp + 2);
-// }
-// }
+solutions.middleThree = function(str) {
+ return str.substr((str.length / 2) - 1, 3);
+}
// console.log(solutions.middleThree("Candy"));
// console.log(solutions.middleThree("and"));
// console.log(solutions.middleThree("solving"));
+// console.log(solutions.middleThree(""));
+// console.log(solutions.middleThree("a"));
-// Java > Warm-up2 > stringTimes
+// Java > Warmup-2 > stringTimes
// Given a string and a non-negative int n, return a larger string that is n
// copies of the original string.
-solutions.stringTimes = function(str, n){
- result = "";
- for(i=0; i Warm-up2 > doubleX
+// Java > Warmup-2 > doubleX
// Given a string, return true if the first instance of "x" in the string is
// immediately followed by another "x".
-solutions.doubleX = function(str){
- str.toLowerCase();
- x = str.indexOf('x');
- if (x == -1){
- return false;
- }
- if (x >= str.length){
- return false;
- }
- return str.substring(x+1, x+2) == "x";
+solutions.doubleX = function(str) {
+ var i = str.indexOf('x');
+ return i >= 0 && i === str.indexOf('xx');
}
// console.log(solutions.doubleX("axxbb"));
// console.log(solutions.doubleX("axaxax"));
// console.log(solutions.doubleX("xxxxxx"));
-// Java > Warm-up2 > last2
+// Java > Warmup-2 > last2
// Given a string, return the count of the number of times that a substring
// length 2 appears in the string and also as the last 2 chars of the string,
// so "hixxxhi" yields 1 (we won't count the end substring).
-solutions.last2 = function(str){
- count = 0;
- if(str.length<2){
- return 0;
- }
- end = str.substring(str.length-2);
- for(x=0; x Warm-up2 > array123
+// Java > Warmup-2 > array123
// Given an array of ints, return true if .. 1, 2, 3, .. appears in the array somewhere.
-solutions.array123 = function(nums){
- return !!(nums.join("").match(/123/g));
- // for (x=0; x <= nums.length-2; x++){
- // if(nums[x] == 1 && nums[x+1] == 2 && nums[x+2] == 3){
- // return true;
- // }
- // return false;
-
+solutions.array123 = function(nums) {
+ for (var x = 0; nums.length >= 3 && x <= nums.length - 2; x++) {
+ if (nums[x] === 1 && nums[x + 1] === 2 && nums[x + 2] === 3) {
+ return true;
+ }
+ }
+ return false;
}
+
// console.log(solutions.array123([1,2,3]));
// console.log(solutions.array123([1,1,2,3,1]));
// console.log(solutions.array123([1,1,2,4,1]));
// console.log(solutions.array123([1,1,2,1,1,2,3]));
-// Java > Warm-up2 > altPairs
+// Java > Warmup-2 > altPairs
// Given a string, return a string made of the chars at indexes 0,1, 4,5, 8,9 ...
// so "kittens" yields "kien".
-solutions.altPairs = function(str){
- result="";
- for(x=0; x str.length){
- end = str.length
- }
- result = result + str.substring(x, end);
- }
- return result;
+solutions.altPairs = function(str) {
+ var newStr = '';
+ for (var i = 0; i * 2 < str.length; i += 2) {
+ newStr += str.substr(i * 2, 2);
+ }
+ return newStr;
+ //alt solution:
+ //return str.split('').filter((c,i)=>!(~~(i/2)%2)).join('');
}
// console.log(solutions.altPairs('kitten'));
// console.log(solutions.altPairs('Chocolate'));
// console.log(solutions.altPairs('CodingHorror'));
-// Java > Warm-up2 > noTriples
+// Java > Warmup-2 > noTriples
// Given an array of ints, we'll say that a triple is a value appearing
// 3 times in a row in the array. Return true if the array does not contain
// any triples.
-solutions.noTriples = function(nums){
- for(x=0; x Warm-up2 > frontTimes
+// Java > Warmup-2 > frontTimes
// Given a string and a non-negative int n, we'll say that the front of the string is
// the first 3 chars, or whatever is there if the string is less than length 3.
// Return n copies of the front;
-solutions.frontTimes = function(str, n){
- frontLen = 3;
- if(frontLen > str.length) {
- frontLen = str.length;
- }
- front = str.substring(0, frontLen);
- result = "";
- for (x=0; x Warm-Up2 > stringBits
// Given a string, return a new string made of every other char
// starting with the first, so "Hello" yields "Hlo".
-solutions.stringBits = function(str){
- result = "";
- for(x=0; x arrayCount9
// Given an array of ints, return the number of 9's in the array.
-solutions.arrayCount9 = function(nums){
- count = 0;
- for (x=0; x stringYak
// Suppose the string "yak" is unlucky. Given a string, return a version where all
// the "yak" are removed, but the "a" can be any char. The "yak" strings will not overlap.
-solutions.stringYak = function(str){
- result = "";
- for(x=0; x countXX
// Count the number of "xx" in the given string. We'll say that overlapping is allowed,
// so "xxx" contains 2 "xx".
-solutions.countXX = function(str){
- count = 0;
- for(x=0; x stringSplosion
// Given a non-empty string like "Code" return a string like "CCoCodCode".
-solutions.stringSplosion = function(str){
- result = "";
- for(x=0; x arrayFront9
// Given an array of ints, return true if one of the first 4 elements in
// the array is a 9. The array length may be less than 4
-solutions.arrayFront9 = function(nums){
- for(x=0; x<4; x++){
- if(nums[x] == 9){
- return true;
- }
- }
- return false;
+solutions.arrayFront9 = function(nums) {
+ for (i = 0; i < 4 && i < nums.length; i++) {
+ if (nums[i] === 9) return true;
+ }
+ return false;
}
// console.log(solutions.arrayFront9([1,2,9,3,4]));
// console.log(solutions.arrayFront9([1,2,3,4,9]));
@@ -992,16 +756,11 @@ solutions.arrayFront9 = function(nums){
// Warm-Up2 > stringX
// Given a string, return a version where all the "x" have been removed.
// Except an 'x' at the very start or end should not be removed.
-solutions.stringX = function(str){
- result = "";
- front = str.substring(0,1);
- end = str.substring(str.length-1);
- for(i=1; i= input[x].length || input[x].charAt(i) !== char)
- return answer
- }
- answer = answer + char;
- }
- return answer;
-}
-// test = [
-// "we", "were", "me", "went", "why", "you"
-// ]
-// test2 = [
-// "we", "were", "we", "went", "why", "wou"
-// ]
-
-test3 = ['me', 'meat', 'meander', 'mexico'];
+solutions.biggestPre = function(input) {
+ for (var i = 0; i < input[0].length; i++) {
+ for (var x = 1; x < input.length; x++) {
+ if (i >= input[x].length || input[x][i] !== input[0][i])
+ return input[0].slice(0, i);
+ }
+ }
+ return input[0];
+}
+// test = ["we", "were", "me", "went", "why", "you"]
+// test2 = ["we", "were", "we", "went", "why", "wou"]
+// test3 = ['me', 'meat', 'meander', 'mexico'];
//
// console.log(solutions.biggestPre(test));
// console.log(solutions.biggestPre(test2));
-// console.log(solutions.biggestPre(test3));
+// console.log(solutions.biggestPre(test3));
\ No newline at end of file