-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding Anagram assignment donated by Capgemini and model answer. * Tidy up to meet PR guidelines. * Formatting change requested in PR * Removing blank lines at end to pass code review. * Removing blank lines at end to pass code review. * Removing blank lines at end to pass code review. * Removing blank lines at end to pass code review. --------- Co-authored-by: atg103 <[email protected]>
- Loading branch information
Showing
17 changed files
with
7,972 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,2 @@ | ||
node_modules | ||
|
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,21 @@ | ||
body { | ||
font-family: 'Arial', 'Tahoma', 'sans-serif'; | ||
} | ||
#form { | ||
width: 330px; | ||
text-align: right; | ||
margin-bottom: 4px; | ||
} | ||
label { | ||
display: block; | ||
width: 330px; | ||
margin-bottom: 2px; | ||
} | ||
#output { | ||
border: 1px solid #999; | ||
display: block; | ||
width: 322px; | ||
height: 25px; | ||
padding: 4px; | ||
font-size: 11pt; | ||
} |
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,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en_GB"> | ||
<head> | ||
<link rel="stylesheet" type="text/css" href="/css/global.css" /> | ||
<script type="text/javascript" src="/js/anagram.js"></script> | ||
<script type="text/javascript" src="/js/app.js"></script> | ||
<script type="text/javascript"> | ||
window.addEventListener("load", function() { | ||
new App(); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div id="form"> | ||
<label>First Word: <input type="text" id="word1"/></label> | ||
<label>Second Word: <input type="text" id="word2"/></label> | ||
<button id="submit">Check Anagrams</button> | ||
</div> | ||
<section id="output"></section> | ||
</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,17 @@ | ||
function AnagramChecker () { } | ||
|
||
AnagramChecker.prototype.checkAnagrams = function(word1, word2) { | ||
if (word1 == null || word2 == null) { | ||
return false; | ||
} | ||
return this.prepareWord(word1) === this.prepareWord(word2); | ||
}; | ||
|
||
AnagramChecker.prototype.prepareWord = function(word) { | ||
return word.split('').sort().join(''); | ||
}; | ||
|
||
if (module) { | ||
// this exists in the Node/Jest environment but not in the browser. | ||
module.exports = AnagramChecker; | ||
} |
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,27 @@ | ||
function App() { | ||
this.anagramChecker = new AnagramChecker(); | ||
|
||
var submitControl = document.querySelector('#submit'); | ||
var self = this; | ||
submitControl.onclick = function() { self.checkForAnagrams() }; | ||
|
||
console.debug("Application initialised."); | ||
} | ||
|
||
App.prototype.setOutput = function(text) { | ||
document.querySelector("#output").innerText = text; | ||
}; | ||
|
||
App.prototype.checkForAnagrams = function() { | ||
var firstWord = document.getElementById("word1").value; | ||
var secondWord = document.getElementById("word2").value; | ||
if (firstWord == "" || secondWord == "") { | ||
this.setOutput(""); | ||
} else { | ||
if (this.anagramChecker.checkAnagrams(firstWord, secondWord)) { | ||
this.setOutput("These words are anagrams of each other."); | ||
} else { | ||
this.setOutput("These words are not anagrams of each other."); | ||
} | ||
} | ||
}; |
Oops, something went wrong.