<meta name="description" content="anagram checker and reduce example">
<meta name="viewport" content="width=device-width">
<script id="jsbin-javascript">
var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice'];
var countedNames = names.reduce(function (allNames, name) {
console.log(countedNames);
// { 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 }
// convert strings to LC for case insensitivity
// split strings into arrays
// sort the arrays (spaces will sort first and be trimmed later)
// join the arrays back into strings
// we're only concerned about the printable characters in the anagram so,
// trim() to remove any spaces and then compare the resulting strings
var str1 = this.word1.toLowerCase().split('').sort().join('').trim();
var str2 = this.word2.toLowerCase().split('').sort().join('').trim();
if (str1 === str2) { console.log("true");
} else { console.log("fff");
<script id="jsbin-source-javascript" type="text/javascript">
var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice'];
var countedNames = names.reduce(function (allNames, name) {
console.log(countedNames);
// { 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 }
// convert strings to LC for case insensitivity
// split strings into arrays
// sort the arrays (spaces will sort first and be trimmed later)
// join the arrays back into strings
// we're only concerned about the printable characters in the anagram so,
// trim() to remove any spaces and then compare the resulting strings
var str1 = this.word1.toLowerCase().split('').sort().join('').trim();
var str2 = this.word2.toLowerCase().split('').sort().join('').trim();
if (str1 === str2) { console.log("true");
} else { console.log("fff");