A Pen by Natasha Dykes on CodePen.
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
/** | |
QUESTION | |
given an array of strings, determine if the strings can be rearranged | |
to form a palindrome. | |
**/ | |
function possiblePalidrome(arr) { | |
var totalLetters = arr.reduce((total, set) => { | |
total += set.length; | |
return total; |
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
function flatten(input) { | |
let flattenArr = []; | |
for(let i = input.child.length - 1; i >= 0; i--) { | |
for(const prop in input.child[i]) { | |
if(prop === 'child') { | |
flattenArr = flattenArr.concat(flatten(input.child[i])); | |
delete input.child[i].child; | |
flattenArr.push(input.child[i]); | |
return flattenArr; | |
} |
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
// create a method that determines a winner from a given board. Manipulting matrix datasets. | |
var board = [ | |
['x','x', 'o'], | |
['x', 'o', 'x'], | |
['x',null, null], | |
]; | |
var board2 = [ | |
['o', null, 'o'], |
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
// Correct Way | |
function indexOf(str, query) { | |
for(var i = 0; i < str.length; i++) { | |
for(var q = 0; q < query.length; q++) { | |
if (str[i+q] !== query[q]) { | |
break; | |
} | |
if (q === query.length - 1) { | |
return i; | |
} |