From 5598dff02088c6a371c9f8a19f9bf235c8f45c86 Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Tue, 8 Aug 2017 09:46:36 -0700 Subject: [PATCH 01/14] longestString\longestString.js --- longestString/longestString.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/longestString/longestString.js b/longestString/longestString.js index 35b887c..acaf847 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -2,3 +2,21 @@ * Write a function that accepts an array of strings. * Return the longest string in the array. */ + +console.log('Picking an OS with the highest number of characters'); +const stringLong = (strings) => { + let os = ['MacOSX', 'Linux', 'Windows10']; + console.log(os); + for(let i = 0; i < os.length; i++){ + let number = os[i]; + console.log(number.length); + if(number.length > 8){ + + console.log('Windows 10 is best OS'); + break; + }//if + }//for +}; + + +stringLong(); From a03bc79a959dfc46d05dd89c0223385be6d1d558 Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Tue, 8 Aug 2017 09:54:16 -0700 Subject: [PATCH 02/14] longestString\longestString.js --- longestString/longestString.js | 1 + 1 file changed, 1 insertion(+) diff --git a/longestString/longestString.js b/longestString/longestString.js index acaf847..3289a96 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -13,6 +13,7 @@ const stringLong = (strings) => { if(number.length > 8){ console.log('Windows 10 is best OS'); + return number; break; }//if }//for From 4b88120de24f632a411308abf3c62987acaaea6e Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Wed, 9 Aug 2017 09:35:46 -0700 Subject: [PATCH 03/14] reverseCase\reverseCase.js --- reverseCase/reverseCase.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index f1051f5..3f4fd68 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -2,4 +2,21 @@ * Write a function that reverses the case of each letter in the strings that it receives. * Example: 'Hello World' -> 'hELLO wORLD' * Assume that each string will contain only spaces and letters. - */ \ No newline at end of file + */ + +const caseChange = (str) =>{ + var newCase = ''; + for (let i = 0; i < str.length; i++){ + if(str[i] === str[i].toLowerCase()){ + newCase += str[i].toUpperCase(); + }else { + newCase += str[i].toLowerCase(); + } + } + console.log(newCase); + return newCase; +} + +let string = 'Hello World'; + +let reversedString = caseChange(string); // "sO, TODAY WE HAVE really GOOD DAY" From 4b2c67d454a16e632d79bc9d3577d9c9b4db230e Mon Sep 17 00:00:00 2001 From: rolandc5 Date: Wed, 9 Aug 2017 09:40:15 -0700 Subject: [PATCH 04/14] Update reverseCase.js --- reverseCase/reverseCase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index 3f4fd68..760a190 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -19,4 +19,4 @@ const caseChange = (str) =>{ let string = 'Hello World'; -let reversedString = caseChange(string); // "sO, TODAY WE HAVE really GOOD DAY" +let reversedString = caseChange(string); From dd999fa5c12d7d26b31afd8c5a3110b0f9cd415b Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Wed, 9 Aug 2017 10:07:48 -0700 Subject: [PATCH 05/14] reverseCase\reverseCase.js --- reverseCase/reverseCase.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index 3f4fd68..a804b3e 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -5,7 +5,7 @@ */ const caseChange = (str) =>{ - var newCase = ''; + let newCase = ''; for (let i = 0; i < str.length; i++){ if(str[i] === str[i].toLowerCase()){ newCase += str[i].toUpperCase(); @@ -19,4 +19,4 @@ const caseChange = (str) =>{ let string = 'Hello World'; -let reversedString = caseChange(string); // "sO, TODAY WE HAVE really GOOD DAY" +let reversedString = caseChange(string); From 81bf1233f14a14f85a1ac422b5fa89ebde87be02 Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Thu, 10 Aug 2017 09:30:27 -0700 Subject: [PATCH 06/14] isUnique\isUnique.js --- isUnique/isUnique.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index 6c9caf5..c5db571 100644 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -1,3 +1,19 @@ /* Implement an algorithm to determine if a string has all unique characters. * What if you cannot use additional data structures? - */ \ No newline at end of file + */ + + + + +const isUnique = (`!`, `@`, `#`, `$`, `%`); +const falsie = false; +const truthsie = true; + +if (isUnique < 100) { + console.log('this does not have unique char'); + return falsie; +} else { + console.log('This has unique char'); + console.log(isUnique); + return truthsie; +} From 218f005b17122f7a69bc94fbae4cd567175f2cdb Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Thu, 10 Aug 2017 09:44:20 -0700 Subject: [PATCH 07/14] isUnique\isUnique.js --- isUnique/isUnique.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index c5db571..8815fac 100644 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -5,15 +5,10 @@ -const isUnique = (`!`, `@`, `#`, `$`, `%`); -const falsie = false; -const truthsie = true; + const isUnique = (`!`, `@`, `#`, `$`, `%`); -if (isUnique < 100) { - console.log('this does not have unique char'); - return falsie; -} else { - console.log('This has unique char'); - console.log(isUnique); - return truthsie; -} + if (isUnique < 100) { + console.log('this does not have unique char'); + } else + console.log('This has unique char'); + console.log(isUnique); From d4c2b6927b6f7b8e0c7a8d187f2eb75093ea4dda Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Thu, 10 Aug 2017 10:34:56 -0700 Subject: [PATCH 08/14] isUnique\isUnique.js --- isUnique/isUnique.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index 8815fac..47afcc6 100644 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -3,12 +3,29 @@ */ + let isUnique = string => { + unique: 'Hello' + unique1: 'Hi' + unique2: 'This' + }; - - const isUnique = (`!`, `@`, `#`, `$`, `%`); - - if (isUnique < 100) { + /*if (isUnique < 100) { console.log('this does not have unique char'); } else console.log('This has unique char'); - console.log(isUnique); + console.log(isUnique);*/ + +switch (isUnique()) { + case (isUnique.unique): { + console.log('char hello'); + } + case(isUnique.unique1): { + console.log('char hi'); + } + case(isUnique.unique2): { + console.log('char this'); + break; + } + console.log('No other char'); +} +console.log('Program ending'); From d517fd6a5c8b19a28a5a0f81ee957632abf56c30 Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Tue, 15 Aug 2017 09:14:28 -0700 Subject: [PATCH 09/14] brainTeasers\waterJugs.md --- callBackPractice/callBackPractice.js | 54 ++++++++++++++++++---------- isUnique/isUnique.js | 50 ++++++++++++++++++++++++-- longestString/longestString.js | 14 +++++++- removeDuplicates/removeDuplicates.js | 24 +++++++++---- 4 files changed, 113 insertions(+), 29 deletions(-) diff --git a/callBackPractice/callBackPractice.js b/callBackPractice/callBackPractice.js index 8f5d9ac..e11601c 100644 --- a/callBackPractice/callBackPractice.js +++ b/callBackPractice/callBackPractice.js @@ -17,55 +17,73 @@ // Write a function called firstItem that passes the first item of the given array to the callback function - const foods = ['pineapple', 'mango', 'ribeye', 'curry', 'tacos', 'ribeye', 'mango']; -firstItem(foods, (firstItem) => { +const firstItem = (foods, (firstItem) => { + firstItem = foods[0]; console.log(`The first item is ${firstItem}.`); }); +firstItem(); // Write a function called getLength that passes the length of the array into the callback - -getLength(foods, (length) => { +const getLength = (foods, (length) => { + length = foods.length; console.log(`The length of the array is ${length}.`); }); +getLength(); // Write a function called last which passes the last item of the array into the callback - -last(foods, (lastItem) => { +const last = (foods, (lastItem) => { + lastItem = foods[6]; console.log(`The last item in the array is ${lastItem}.`); }); +last(); // Write a function called sumNums that adds two numbers and passes the result to the callback - - -sumNums(5, 10, (sum) => { +const sumNums = (5, 10, (sum) => { + sum = 5 + 10; console.log(`The sum is ${sum}.`); }); +sumNums(); // Write a function called multiplyNums that adds two numbers and passes the result to the callback - -multiplyNums(5, 10, (product) => { +const multiplyNums = (5, 10, (product) => { + product = 5 * 10; console.log(`The product is ${product}.`); }); +multiplyNums(); // Write a function called contains that checks if an item is present inside of the given array. // Pass true to the callback if it is, otherwise pass false - -contains(foods, 'ribeye', (result) => { +const contains = (foods, 'ribeye', (result) => { + for (let i = 0; i < foods.length; i++) { + if (foods[i] === 'ribeye'){ + result = foods[i]; + }//if + }//for console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array'); }); +contains(); // Write a function called removeDuplicates that removes all duplicate values from the given array. // Pass the array to the callback function. Do not mutate the original array. +const removeDuplicates = (foods, (uniqueFoods) => { + let newFoods = []; + for (let i = 0; i < foods.length; i++) { + newFoods[i] = foods[i]; + } + uniqueFoods = newFoods.slice(1,2); + console.log(uniqueFoods) -removeDuplicates(foods, (uniqueFoods) => { console.log(`foods with duplicates removed: ${uniqueFoods}`); }); +removeDuplicates(); // Write a function called forEach that iterates over the provided array and passes the value and index into the callback. - - -forEach(foods, (value, index) => { +const forEach = (foods, (value, index) => { + for (let i = 0; i < foods.length; i++) { + value(foods[i], index); + } console.log(`${value} is at index ${index}.`); -}); \ No newline at end of file +}); +forEach(); diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index 47afcc6..854b68c 100644 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -2,18 +2,18 @@ * What if you cannot use additional data structures? */ - +/* let isUnique = string => { unique: 'Hello' unique1: 'Hi' unique2: 'This' }; - /*if (isUnique < 100) { + if (isUnique < 100) { console.log('this does not have unique char'); } else console.log('This has unique char'); - console.log(isUnique);*/ + console.log(isUnique); switch (isUnique()) { case (isUnique.unique): { @@ -29,3 +29,47 @@ switch (isUnique()) { console.log('No other char'); } console.log('Program ending'); + +*/ + +/* +function isUnique structures +iterate over str +iterate over str starting at i + 1 +if we find a match return false +return true; +*/ + +/* +const isUnique = (str) => { + for (let i = 0; i < str.length; i++) { + for (let j = i + 1; j < str.length; j++) { + if (str[i] === str[j]) return false; + } + } + return true; +}; +const str1 = 'abcdefg'; +const str2 = 'abcdefgg'; +const result = isUnique(str1); +console.log(result); +*/ + + + +const isUnique = (str) => { + const set = new Set(); + for (let i = 0; i < str.length; i++) { + const character = str[i]; + const isInSet = set.has(character); + if(isInSet) return false; + if (!isInSet) set.add(character); + } + return true; +}; +const str1 = '1234567890qwertyuiopasdfghjklzxcvbnm'; +const str2 = 'abcdefgg'; + +const result = isUnique(str1); + +console.log(result); diff --git a/longestString/longestString.js b/longestString/longestString.js index 3289a96..b91478d 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -2,7 +2,7 @@ * Write a function that accepts an array of strings. * Return the longest string in the array. */ - +/* console.log('Picking an OS with the highest number of characters'); const stringLong = (strings) => { let os = ['MacOSX', 'Linux', 'Windows10']; @@ -21,3 +21,15 @@ const stringLong = (strings) => { stringLong(); +*/ + + + +const reverseCase = (string) => +string + .split('') + .map(c => c.toUpperCase() === c ? c.toLowerCase() : c.toUpperCase()) + .join('') + + +console.log(reverseCase('AHSDHWADHShsdahdhwhadhwahdHHDAWHDASHDA')); diff --git a/removeDuplicates/removeDuplicates.js b/removeDuplicates/removeDuplicates.js index 970f719..08dc697 100644 --- a/removeDuplicates/removeDuplicates.js +++ b/removeDuplicates/removeDuplicates.js @@ -1,13 +1,23 @@ /* * Write a function that takes an array and removes all duplicate items. * [1, 1, 1, 2, 2, 3, 4, 5, 5] -> [1, 2, 3, 4, 5] - * - * beast mode: try not to use two for loops. - * hint: most array methods native to JS iterate in some way. - * So if you're using 'indexOf' 'sort' 'forEach' etc, + * + * beast mode: try not to use two for loops. + * hint: most array methods native to JS iterate in some way. + * So if you're using 'indexOf' 'sort' 'forEach' etc, * you're more than likely using a for loop under the hood. */ -const removeDuplicates = (arr) => { - //code here... -}; \ No newline at end of file +const duptArray = [1, 1, 1, 2, 2, 3, 4, 5, 5]; + +const removeDuplicates = (arr, callback) => { + const set = new Set(); + arr.forEach(item => { + set.add(item); + }); + callback(Array.from(set)); +}; + +removeDuplicates(duptArray, (result) => { + console.log(result); +}); From 57063ff44c1a8a7e97073f5d3f61e3e795de39e0 Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Tue, 15 Aug 2017 09:17:10 -0700 Subject: [PATCH 10/14] brainTeasers\waterJugs.md --- brainTeasers/waterJugs.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/brainTeasers/waterJugs.md b/brainTeasers/waterJugs.md index 5276fc0..7f66aac 100644 --- a/brainTeasers/waterJugs.md +++ b/brainTeasers/waterJugs.md @@ -1 +1,13 @@ You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the jug would be impossible. + +1 five quart jug +1 three quart jug + +needs 4 quarts of water + +can't fill the water up exactly half + +Fill up the five-quart jug with 2.6 quarts of water and fill the three-quart jug with 1.4 quarts of water. +You will get exactly 4 quarts of water. + +does not say we can't go over half of the jug. Just says having exactly half is impossible. From 571ce1cb4a3dc35775ca5c0816cc38c63cb43580 Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Mon, 21 Aug 2017 09:58:10 -0700 Subject: [PATCH 11/14] complete --- commonCharacters/commonCharacters.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/commonCharacters/commonCharacters.js b/commonCharacters/commonCharacters.js index ec31d82..e09405d 100644 --- a/commonCharacters/commonCharacters.js +++ b/commonCharacters/commonCharacters.js @@ -6,3 +6,28 @@ * Example: commonCharacters('acexivou', 'aegihobu') * * Returns: 'aeiou' */ + +const commonChar = (str1, str2) => { + let string = []; + if (str1.indexOf('a') > -1 && str2.indexOf('a') > -1) { + string.push('a'); + } + if (str1.indexOf('e') > -1 && str2.indexOf('e') > -1) { + string.push('e'); + } + if (str1.indexOf('i') > -1 && str2.indexOf('i') > -1) { + string.push('i'); + } + if (str1.indexOf('o') > -1 && str2.indexOf('o') > -1) { + string.push('o'); + } + if (str1.indexOf('u') > -1 && str2.indexOf('u') > -1) { + string.push('u'); + } + return string.join(''); +} + +const str1 = 'areyiwoqu'; +const str2 = 'asedifogu'; + +console.log(commonChar(str1, str2)); \ No newline at end of file From 6c8a6c51516831239780bbe5a2b7f5d06a63bc16 Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Mon, 21 Aug 2017 10:09:36 -0700 Subject: [PATCH 12/14] complete --- constructors/constructors.js | 74 +++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/constructors/constructors.js b/constructors/constructors.js index 54801f6..80149b0 100644 --- a/constructors/constructors.js +++ b/constructors/constructors.js @@ -20,4 +20,76 @@ * * This is how you would structure the game objects in an actual game * application in Unity or another similar framework. - */ \ No newline at end of file + */ + +class NPC { + constructor() { + this.humanoid = []; + this.animal = []; + this.plant = []; + } + humanoidClass(selectClass) { + const humanoidClass = [`human`, 'Elf', 'Orc']; + let selectedHumanClass = humanoidClass[selectClass]; + if (selectedHumanClass === `human`) { + class Stats { + constructor() { + this.hp = 125; + this.stregnth = 2; + this.agility = 3; + this.mana = 5; + } + } + const stats = new Stats(); + this.humanoid.push(selectedHumanClass, new Stats); + } + if (selectedHumanClass === 'Elf') { + class Stats { + constructor() { + this.hp = 125; + this.stregnth = 2; + this.agility = 3; + this.mana = 5; + } + } + this.humanoid.push(selectedHumanClass, new Stats); + } + if (selectedHumanClass === 'Orc') { + class Stats { + constructor() { + this.hp = 200; + this.strength = 5; + this.agility = 4; + this.mana = 0; + } + } + this.humanoid.push(selectedHumanClass, new Stats); + } + } + animalClass(selectClass) { + const animalClass = ['Bear', 'Wolf']; + let selectedAnimalClass = animalCLass[selectClass]; + if (selectedAnimalClass === 'Bear') { + class Stats { + constructor() { + this.hp = 1000; + this.strength = 6; + this.agility = 4; + this.mana = 0; + } + } + this.animal.push(selectedAnimalClass, new Stats); + } + } + plantClass(selectClass) { + const plantClass = ['Flesh Eating Daisy']; + this.animal.push(plantClass[selectClass]); + } +} + +const npc = new NPC(); +npc.humanoidClass(0); +//npc.humanoidClass(1); +//npc.humanoidClass(2); +console.log(npc.humanoid); + From 0fc0b77d1caa5a7fe52693e7eafed2a6e30bba1e Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Wed, 23 Aug 2017 09:01:10 -0700 Subject: [PATCH 13/14] update --- brainTeasers/waterJugs.md | 5 ++++- commonCharacters/commonCharacters.js | 19 ++++++++++++++-- evenOccurences/evenOccurences.js | 18 ++++++++++++++- forLoopTimeout/forLoopTimeout.js | 4 +--- .../longestString}/longestString.js | 0 .../longestString}/solution.js | 0 .../largestPrimePalindrome.js | 22 ++++++++++++++++++- 7 files changed, 60 insertions(+), 8 deletions(-) rename {longestString => isUnique/longestString}/longestString.js (100%) rename {longestString => isUnique/longestString}/solution.js (100%) diff --git a/brainTeasers/waterJugs.md b/brainTeasers/waterJugs.md index 7f66aac..0a62ae4 100644 --- a/brainTeasers/waterJugs.md +++ b/brainTeasers/waterJugs.md @@ -7,7 +7,10 @@ needs 4 quarts of water can't fill the water up exactly half -Fill up the five-quart jug with 2.6 quarts of water and fill the three-quart jug with 1.4 quarts of water. +Fill up the five-quart jug with 3 quarts of water and fill the three-quart jug with 1 quarts of water. You will get exactly 4 quarts of water. +Step 1: Fill the 5 quarts pour all of the water inside the 3 quarts jug +Step 2: + does not say we can't go over half of the jug. Just says having exactly half is impossible. diff --git a/commonCharacters/commonCharacters.js b/commonCharacters/commonCharacters.js index e09405d..0f726b2 100644 --- a/commonCharacters/commonCharacters.js +++ b/commonCharacters/commonCharacters.js @@ -6,7 +6,7 @@ * Example: commonCharacters('acexivou', 'aegihobu') * * Returns: 'aeiou' */ - +/* const commonChar = (str1, str2) => { let string = []; if (str1.indexOf('a') > -1 && str2.indexOf('a') > -1) { @@ -30,4 +30,19 @@ const commonChar = (str1, str2) => { const str1 = 'areyiwoqu'; const str2 = 'asedifogu'; -console.log(commonChar(str1, str2)); \ No newline at end of file +console.log(commonChar(str1, str2)); +*/ + + +const commonChars = (str1, str2) => { + let common = []; + + + str1.split('').forEach((letter) => { + if (str2.split('').includes(letter) && !common.includes(letter)) { + common.push(letter); + } + }); + return common.join('').replace(' ', ''); +} +console.log(commonChars('axei ou', 'aeidou')); \ No newline at end of file diff --git a/evenOccurences/evenOccurences.js b/evenOccurences/evenOccurences.js index 35da569..048bca1 100644 --- a/evenOccurences/evenOccurences.js +++ b/evenOccurences/evenOccurences.js @@ -10,6 +10,22 @@ * * console.log(onlyEven); // 4 * */ + const evenOccurence = (arr) => { - // Your code here. + let arrStorage = {}; + + arr.forEach = (value) => { + arrStorage[value] = storage[value] + 1 || 1; + }; + + for (let i = 0; i < arr.length; i++) { + let even = arr[i]; + + if (arrStorage[even] % 2 === 0) { + return even; + } + } + return null; }; + +const randomArray = evenOccurence([1, 7, 2, 4, 5, 1, 6, 8, 9, 6, 4, 1]); diff --git a/forLoopTimeout/forLoopTimeout.js b/forLoopTimeout/forLoopTimeout.js index 87522c2..195e79d 100644 --- a/forLoopTimeout/forLoopTimeout.js +++ b/forLoopTimeout/forLoopTimeout.js @@ -6,8 +6,6 @@ for (var i = 1; i <= 10; i++) { setTimeout(function() { - // From looking at the code you would assume it would print 1 - 10 - // It doesn't. Why? How can you make it print 1 - 10. - console.log(i); + console.log(i++); }, 0); } \ No newline at end of file diff --git a/longestString/longestString.js b/isUnique/longestString/longestString.js similarity index 100% rename from longestString/longestString.js rename to isUnique/longestString/longestString.js diff --git a/longestString/solution.js b/isUnique/longestString/solution.js similarity index 100% rename from longestString/solution.js rename to isUnique/longestString/solution.js diff --git a/largestPrimePalindrome/largestPrimePalindrome.js b/largestPrimePalindrome/largestPrimePalindrome.js index 4cc99c0..ebfed60 100644 --- a/largestPrimePalindrome/largestPrimePalindrome.js +++ b/largestPrimePalindrome/largestPrimePalindrome.js @@ -3,4 +3,24 @@ * Hint: it's 929 * You will first want to determine if the number is a palindrome and then determine if it is prime. * A palindrome is a number that is the same forwards and backwards: 121, 323, 123454321, etc. - */ \ No newline at end of file + */ + + + const largestPrimePalindrome = () => { + + const isPalindrome = (n) => { + if (n === n.toString().split(''.reverse().join(''))) return true; + } + const isPrime = (n) => { + if (n % 2 === 0) { + for (let j = 3; j <= Math.sqrt(n); j++) { + if (n % k === 0) return false; + } + return true; + } + } + + for (let i = 1000; i > 0; i--) { + if (isPalindrome(i) && isPrime(i)) return i; + } + } From a840d25178fb32c31db08aee74ee8453bc6d91a8 Mon Sep 17 00:00:00 2001 From: Roland Canuto Date: Wed, 23 Aug 2017 09:02:18 -0700 Subject: [PATCH 14/14] update --- {isUnique/longestString => longestString}/longestString.js | 0 {isUnique/longestString => longestString}/solution.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {isUnique/longestString => longestString}/longestString.js (100%) rename {isUnique/longestString => longestString}/solution.js (100%) diff --git a/isUnique/longestString/longestString.js b/longestString/longestString.js similarity index 100% rename from isUnique/longestString/longestString.js rename to longestString/longestString.js diff --git a/isUnique/longestString/solution.js b/longestString/solution.js similarity index 100% rename from isUnique/longestString/solution.js rename to longestString/solution.js