//--- CODE --------------------------
var string = 'f'; // Cache string
function f(value) {
// Will append variable to string if value is a string
if (typeof value === 'string') {
value = string + value;
// Reset cached string
string = 'f';
// Return completed string
return value;
// Appends 'o' to string where no value passed to function
} else if (value === undefined) {
string = string + 'o';
return false;
}
}
//--- SPECS -------------------------
/*
It didn't look to me like the original tests would ever pass as I've never seen anyone daisy chain
the functions in this way. The test syntax is returning an error.
Maybe refactoring the tests so that they are more granular and robust is part of the test?
*/
describe("f", function() {
it("should return fl", function() {
expect(f("l")).toEqual("fl");
// And so on such that the number of calls continues
// to increase the number of letter "o" in the string
// until the function is called with a string.
});
});
describe("f", function() {
it("should return fol", function() {
f();
expect(f("l")).toEqual("fol");
});
});
describe("f", function() {
it("should return fool", function() {
f();
f();
expect(f("l")).toEqual("fool");
});
});
describe("f", function() {
it("should return foot", function() {
f();
f();
expect(f("t")).toEqual("foot");
});
});
describe("f", function() {
it("should return foooool", function() {
f();
f();
f();
f();
f();
expect(f("l")).toEqual("foooool");
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.