Skip to content

Instantly share code, notes, and snippets.

@Offirmo
Last active September 6, 2021 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Offirmo/0a6dde1a65c547705817575b5c5ad2ae to your computer and use it in GitHub Desktop.
Save Offirmo/0a6dde1a65c547705817575b5c5ad2ae to your computer and use it in GitHub Desktop.
AwesomeKaleGleaner
function grid(seedCount) {
const s = Math.sqrt(seedCount)
const res = [ Math.floor(s) , Math.ceil(s) ]
if (res[0] * res[1] < seedCount )
res[0]++
return res
}
/**
* The following represents all your plants' locations
* in your garden and whether they are or are not currently
* getting sun.
*
* const plant_1 = {
* gardenLocation: [1, 1],
* gettingSun: true
* };
*
* const plant_2 = {
* gardenLocation: [1, 2],
* gettingSun: false
* };
*
* const plant_3 = {
* gardenLocation: [2, 1],
* gettingSun: false
* };
*
* const plant_4 = {
* gardenLocation: [2, 2],
* gettingSun: true
* };
*
* const plants = [plant_1, plant_2, plant_3, plant_4];
*/
/**
* Write a function that takes in your array of plants and
* returns a new array of garden locations you should water.
*
* @param {array} plants - Your array of plants.
* @return {array} - An array of garden locations you should
* water.
*/
function whereToWater(plantsArray) {
return plantsArray
.filter(plant => plant.gettingSun)
.map(plant => plant.gardenLocation)
}
const plant_1 = {
gardenLocation: [1, 1],
gettingSun: true
};
const plant_2 = {
gardenLocation: [1, 2],
gettingSun: false
};
const plant_3 = {
gardenLocation: [2, 1],
gettingSun: false
};
const plant_4 = {
gardenLocation: [2, 2],
gettingSun: true
};
const plants = [plant_1, plant_2, plant_3, plant_4];
LEVEL 1.3
Give your plants CO2 by talking to them. Complete the following function that converts any string into Plant-Latin so that your plants can understand you.
NOTES: Plant-Latin has different vowels than we do. Append "tiva" after every vowel "a", "llia" after every vowel "e", "mus" after every vowel "i", "phylum" after every vowel "o", and "rea" after every vowel "u". For example: "I love water!" becomes "Imus lophyllumvellia wativatelliar!"
/**
* Converts a message into Plant-Latin.
* @param {string} message - The message to be translated.
* @return {string} - Translated Plant-Latin message.
*/
function translatePlantLatin(message) {
console.log('test')
return Array.from(message)
.reduce((acc, val) => {
return acc + val + ({
a: 'tiva',
e: 'llia',
i: 'mus',
o: 'phylum',
u: 'rea',
}[val] || '')
}, '')
}
LEVEL 2.1
Plant your new seeds. This time, write a function that takes an array of seeds and any number of rows and columns to plant your seeds in a grid represented by a 2D array.
/**
* Returns a 2D array representing all seeds in a grid of size
* row x cols.
*
* @param {array} seeds - Array of the Seeds in your packet.
* @param {number} rows - The number of rows.
* @param {number} cols = The number of columns.
* @return {array} - 2D array representing grid of planted Seeds.
*/
function grid(seeds, rows, cols) {
console.log({seeds, rows, cols})
const res = Array.from({length: rows}, () =>
Array.from({length: cols}, () =>
seeds.shift()
)
)
console.log(res)
return res
}
LEVEL 2.2
A plant needs help. Using the same rules of Plant-Latin as before, write a function that sorts through the array of plants and returns the one calling out for "help".
/**
* Converts a message from Plant-Latin.
* @param {string} message - The Plant-Latin message to be translated.
* @return {string} - Translated message.
*/
function translate(message) {
const vowelReplacements = {
tiva: "a",
llia: "e",
mus: "i",
phylum: "o",
rea: "u"
};
/* Enter your solution here! */
}
/**
* The Plant class has an instance property called message
* which is a string. The Plant's message is in Plant-Latin.
* Write a function that takes in an array of Plants, a message
* in human language, and returns all the Plants whose Plant-Latin
* matches the message.
*
* @param {array} plants - Array of Plants to be searched
* @param {string} message - The message in human language to search for
* @return {array} - Array of Plants whose Plant-Latin translates to message
*/
function searchPlantsForMessage(plants, message) {
return plants.filter(({message}) => translate(message) === 'help')
}
@satro1
Copy link

satro1 commented Jun 26, 2020

translate plant latin doesnt take care of capital letter vowels, I cant seem to get that one to work however even though I've been getting the right solutions while testing.

@santhoshivan23
Copy link

@satro1 Same issue here. Check this out :
let result = ""; const vowelMap = { a: 'tiva', e: 'llia', i: 'mus', o: 'phylum', u: 'rea', }; for(let i=0; i<message.length; i++) { const ch = message[i]; const toAppend = ch.toLowerCase() in vowelMap ? ch.concat(vowelMap[ch.toLowerCase()]) : ch; result = result.concat(toAppend); } return result;

This works fine but plantyourcode.com still shows error :/

@yogeshdrc
Copy link

@satro1, find the solution compare it with message not with help string

@yogeshdrc
Copy link

translate plant latin doesnt take care of capital letter vowels, I cant seem to get that one to work however even though I've been getting the right solutions while testing.

Did you checked for help or given message as argument?

@crossphoton
Copy link

First do message = message.toLowerCase() then proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment