Write a function named repeats that returns true if the first half of the string equals the last half, and false if not
Example:
If you pass it "haha" then it should return true because "ha" (the first half) equals "ha" (the second half)
If you pass it "yay" then it should return false because it's odd
If you pass it "heehaw" then it should return false because "hee" doesn't equal "haw"
Determine if string cut in half doesn’t produce float. If it is, return false.
If string cut in half doesn’t produce float, then cut string in half, proceed with comparing both halfs of string with each other. If that is correct also. return true.
HINT: One way way to solve this challenge is to think about a string method which allows you to compare a “slice” of the first half with a “slice” of the second half.
Solved, but still very curious about your way @RandellDawson…
function repeats(str) {
if(str.length % 2 !== 0) {
return false;
}
let first = str.substr(0, str.length / 2);
let second = str.substr(str.length / 2);
return first === second;
};
Honestly, seeing your code all the time really inspires me to get better every day. Thanks a lot. Are slice and substr essentially the same for a string?