learn-co-curriculum / phase-1-algorithms-palindrome Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
https://learning.flatironschool.com/courses/6806/assignments/247610?module_item_id=584048
The student noticed that none of the failed test start and end with the same letter (Something like denied). They had returned true if the first and last letter were true instead of continuing to check and thus ran into issues where all the test passed although their solution wasn't correct. I think adding an example of this case (a non palindrome with a first and last letter being similar) could be a good idea to hound in the idea of scoping and where returns lie
No response
Adding more test to fix these workarounds
https://learning.flatironschool.com/courses/6190/assignments/225637?module_item_id=526926
When using test (and submitting the lab), the test deems my solution as not passing. However, when using the words provided from the lab, the return result is what was expected (true or false)
Furthermore, on next page which contains the solution, that solution is considered incorrect as well per this labs test.
I can't submit this lab until the test code is corrected
my code
function isPalindrome (word){
const wordArray = [...word]
const ansArray = []
for (let i = wordArray.length -1; i >= 0; i--){
ansArray.push(wordArray[i])
}
for (let i = wordArray.length -1; i>=0; i--){
if (ansArray[i] !== wordArray[i]){
return false;
}
}
return true
}
and the solution, which your own tests show it's incorrect.
function reverseString(word) {
// create an array from the input string
const wordArray = word.split("");
// reverse the array
const reversedWordArray = wordArray.reverse();
// create a string from the reversed array
const reversedWord = reversedWordArray.join("");
// return the reversed string
return reversedWord;
}
function isPalindrome(word) {
// reverse the input string
const reversedWord = reverseString(word);
// if the reversed string is the same as the input
if (word === reversedWord) {
return true;
} else {
return false;
}
}
No response
fix the behavior of how test is testing code.
https://learning.flatironschool.com/courses/6190/assignments/225637?module_item_id=526926
If you check out my code. When lines 5-10 are commented out. The palindromes always return false. Even though when you console.log them in the DOM you can see they equal each other. Then when I comment lines 5-10 back in to change the array back into a string I pass the tests. Its very strange because the code logic makes sense. A palindrome is a palindrome whether its in an array format or a string format. I'm thinking it might be because I used to the .map function? If you check this out could you send me a slack? I'm just kinda curious about it.
function isPalindrome(string) {
const arrayForward = string.split('')
const arrayBackward = []
arrayForward.map(letter => arrayBackward.unshift(letter))
// console.log(arrayForward)
// console.log(arrayBackward)
// const arrayForward2 = arrayForward.join('')
// const arrayBackward2 = arrayBackward.join('')
// console.log(arrayForward2)
// console.log(arrayBackward2)
if (arrayForward === arrayBackward) {
return true
console.log('true')
} else {
return false
console.log('false')
}
}
module.exports = isPalindrome;
I failed all the tests that should return true. Until I changed the array back into a string
Maybe its the .map() I used?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.