Complete the function caffeineBuzz, which takes a non-zero integerasit's one argument.
If theintegeris divisible by3, returnthestring"Java".
If theintegeris divisible by3and divisible by4, returnthestring"Coffee"
If theintegeris one oftheaboveandis even, add "Script"totheendofthestring.
Otherwise, returnthestring"mocha_missing!"
caffeineBuzz(1) => "mocha_missing!"
caffeineBuzz(3) => "Java"
caffeineBuzz(6) => "JavaScript"
caffeineBuzz(12) => "CoffeeScript"
Your task isto add a new property usersAnswer toevery object inthe array questions. The value of usersAnswer should be setto null. The solution should work for array of any length.
For example:
var questions = [{
question: "What's the currency of the USA?",
choices: ["US dollar", "Ruble", "Horses", "Gold"],
corAnswer: 0
}, {
question: "Where was the American Declaration of Independence signed?",
choices: ["Philadelphia", "At the bottom", "Frankie's Pub", "China"],
corAnswer: 0
}];
After adding thepropertytheresult should be:
var questions = [{
question: "What's the currency of the USA?",
choices: ["US dollar", "Ruble", "Horses", "Gold"],
corAnswer: 0,
usersAnswer: null
}, {
question: "Where was the American Declaration of Independence signed?",
choices: ["Philadelphia", "At the bottom", "Frankie's pub", "China"],
corAnswer: 0,
usersAnswer: null
}];
In this kata, you must create a function powers that takes an array, and returns thenumberof subsets possible to create fromthatlist. In other words, counts the power sets.
For instance
powers([1,2,3]) => 8
...due to...
powerSet([1,2,3]) =>
[[],
[1],
[2],
[3],
[1,2],
[2,3],
[1,3],
[1,2,3]]
Your function should be able tocount sets up tothe size of500, so watch out; pretty big numbers occur there!
For comparison, my Haskell solution can compute thenumberof sets for an array oflength90000inless than a second, so be quick!
You should treat each array passed as a setof unique values for this kata.
In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a classto one object. This is useful when exactly one object is needed to coordinate actions across the system.
Create an Singleton pattern, so there is one object in system.
Example:
var obj1 = new Singleton();
var obj2 = new Singleton();
obj1 === obj2; // => true
obj1.test = 1;
obj2.test; // => 1
//my:错的var Singleton = function(){// implement singleton Class
Singleton.prototype.test=1;
};
//right:var Singleton = functionSingleton() {// Returns singleton in case it was already definedif (Singleton.prototype._singletonInstance) {
return Singleton.prototype._singletonInstance;
}
// Otherwise defines singleton (to be returned next time around)
Singleton.prototype._singletonInstance = this;
// Defining propertiesthis.test = 1;
};