-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6421050
Showing
12 changed files
with
4,812 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# next.js build output | ||
.next | ||
|
||
# nuxt.js build output | ||
.nuxt | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>React DeCal: Debugging Exercises</title> | ||
|
||
<link | ||
rel="shortcut icon" | ||
type="image/png" | ||
href="../lib/jasmine/jasmine_favicon.png" | ||
/> | ||
<link rel="stylesheet" href="../lib/jasmine/jasmine.css" /> | ||
|
||
<script src="../lib/jasmine/jasmine.js"></script> | ||
<script src="../lib/jasmine/jasmine-html.js"></script> | ||
<script src="../lib/jasmine/boot.js"></script> | ||
|
||
<!-- Our files --> | ||
<script src="js_builtins.js"></script> | ||
<script src="js_builtins_tests.js"></script> | ||
</head> | ||
|
||
<style> | ||
body { | ||
font-family: Verdana, sans-serif; | ||
} | ||
</style> | ||
|
||
<body> | ||
<h2>Debugging Exercises</h2> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"use strict"; | ||
|
||
window.builtins = {}; | ||
|
||
// In this exercise, we'll be recreating some common JavaScript built-in | ||
// functions such as contains() and trim() using the skills we already know. | ||
|
||
// For a reference to all JavaScript built-in objects and functions, | ||
// check out this MDN reference: | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
// Exercise 1. trim() using loops and conditionals | ||
|
||
// Write a function that takes a string and returns the same string without | ||
// leading and trailing spaces. | ||
|
||
// ex. builtins.trim(' Horizons ') -> 'Horizons' | ||
// ex. builtins.trim('Hello World! ') -> 'Hello World!' | ||
|
||
builtins.trim = function(str) { | ||
let newStr = ""; | ||
for (let i = 0; i < str.length; i++) { | ||
if (str[i] !== " ") { | ||
newStr += str[i]; | ||
} | ||
} | ||
return newStr; | ||
}; | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
// Exercise 2. contains() using indexOf() | ||
|
||
// Write a function that takes a string to be searched and a string to | ||
// search for, returning true or false as to whether or not the latter | ||
// was found in the source string. | ||
|
||
// ex. builtins.search('Horizons', 'o') -> true | ||
// ex. builtins.search('Horizons', 'oz') -> false | ||
// ex. builtins.search('rizo', 'Horizons') -> false | ||
// ex. builtins.search('', 'Horizons') -> false | ||
// ex. builtins.search('Horizons', '') -> true | ||
// ex. builtins.search('Horizons', 'h') -> false | ||
|
||
builtins.search = function(sourceString, searchString) { | ||
if (searchString.indexOf(sourceString)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
// Exercise 3. Rewriting reverse() using loops | ||
|
||
// Write a function that takes an array and returns the array in reversed order | ||
// (by indices). | ||
|
||
// ex. builtins.reverse([1, 2, 3]) -> [3, 2, 1] | ||
// ex. builtins.reverse(['dogs', 'cats', 'moose']) -> ['moose', 'cats', 'dogs'] | ||
// ex. builtins.reverse([]) -> [] | ||
// ex. builtins.reverse([123]) -> [123] | ||
|
||
builtins.reverse = function(arr) { | ||
let next = arr.unshift(); | ||
return builtins.reverse(arr).concat(next); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
describe("builtins.trim(str)", function() { | ||
it("builtins.trim(' Horizons ') -> 'Horizons'", function() { | ||
expect(builtins.trim(" Horizons ")).toEqual("Horizons"); | ||
}); | ||
it("builtins.trim('Hello World! ') -> 'Hello World!'", function() { | ||
expect(builtins.trim("Hello World! ")).toEqual("Hello World!"); | ||
}); | ||
}); | ||
|
||
describe("builtins.search(sourceString, searchString)", function() { | ||
it("builtins.search('Horizons', 'o') -> true", function() { | ||
expect(builtins.search("Horizons", "o")).toEqual(true); | ||
}); | ||
it("builtins.search('Horizons', 'oz') -> false", function() { | ||
expect(builtins.search("Horizons", "oz")).toEqual(false); | ||
}); | ||
it("builtins.search('rizo', 'Horizons') -> false", function() { | ||
expect(builtins.search("rizo", "Horizons")).toEqual(false); | ||
}); | ||
it("builtins.search('', 'Horizons') -> false", function() { | ||
expect(builtins.search("", "Horizons")).toEqual(false); | ||
}); | ||
it("builtins.search('Horizons', '') -> true", function() { | ||
expect(builtins.search("Horizons", "")).toEqual(true); | ||
}); | ||
it("builtins.search('Horizons', 'h') -> false", function() { | ||
expect(builtins.search("Horizons", "h")).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe("builtins.reverse(arr)", function() { | ||
it("builtins.reverse([1, 2, 3]) -> [3, 2, 1]", function() { | ||
expect(builtins.reverse([1, 2, 3])).toEqual([3, 2, 1]); | ||
}); | ||
it("builtins.reverse(['dogs', 'cats', 'moose']) -> ['moose', 'cats', 'dogs']", function() { | ||
expect(builtins.reverse(["dogs", "cats", "moose"])).toEqual([ | ||
"moose", | ||
"cats", | ||
"dogs" | ||
]); | ||
}); | ||
it("builtins.reverse([]) -> []", function() { | ||
expect(builtins.reverse([])).toEqual([]); | ||
}); | ||
it("builtins.reverse([123]) -> [123]", function() { | ||
expect(builtins.reverse([123])).toEqual([123]); | ||
}); | ||
}); |
Oops, something went wrong.