Something basic. For me it's nice to enumerate the string as I've seen other do since it is an array of characters adjacent to one another as a solid, contiguous block of memory in most all if not every programming language known to mankind. So from there,, we can logically use the current index of the loop to set the baseline for the output string since we have to have full parity from a length and character account perspective. The two strings should be indentical in length we know for sure. They should also be identical from a composistion perspective as well. That is to say if,, we treated the string and its reverse as sets and we performed the intersection (e.g. A∩B),,,then it should be identical to A and B once we eliminate ordering. At that point we would be validating the set of characters in each string as opposed to ensuring the original order was preserved which is a more exact and stricter approach.
function reverse(input) {
if (typeof input !== 'string') {
throw new TypeError('input must be a string.');
}
var output = [];
for (var index = 0; index < input.length; index++) {
output[index] = input[input.length - index - 1];
}
return output.join('');
}
console.log(reverse('major-key'));
vKewl, 101 (not binary in this case...i literally mean the decimal value one-hundred-and-one like when we write out checks).
What is the value 101
base 2
--or---radix 2
as it is also called, tho? Do you know the answer? Sometimes it escapes me,,,it's ok if it escapes you as well.
Start from the basics and you will remember very quickly. Of course,,,use your favorite search engine to gain a discrete clue so you're
not permanently hosed or foo'bar'd or stuck in limbo. #win
#singed #saintwan
#peace