Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reverses a string w/o being to fancy or clever or asinine af in #js

My approach

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('');


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

Copy link

armw4 commented Mar 3, 2021

Am I having a stroke ???

tf type question is that

bye insult head maniac propeller engine Hawkeye looking people

I hope Sarah Silverman is single asfff!!! We dating if so brb


Copy link

armw4 commented Mar 7, 2021

Clinic Mayo

don’t ask me about why I don’t do stuff or offer me alcohol or controlled substances- I will go off in you I consider this a threat

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