CoDEVIANT #14 (9/30/20) — The 2020 Terrorscape

lol, yeah right…I barely remembered I was writing these things XD
  • N is an integer within the range [1..2,147,483,647].
My initial thoughts
function solution(N) {
let array = N.toString(2).split("")
let counter = 0
let max = 0
let spareArray = []
array.forEach(i => {
if(Number(i) === 1) {
counter = 0
} else {
max = counter

return spareArray.sort()[spareArray.length - 1]
  • Turn the number into a binary:
    I accomplish this by using toString(2) on the N argument passed into the function.
  • I then turn the binary number into an array
    I accomplish this by chaining the split(‘’) method onto binary derived from the step above
  • And we package that guy into the variable named array
Creating naming, right?
  • I set counter and max to equal 0
  • I create an empty array called spareArray.
AWWW yea.
export function solution(N) {  
const binaryString = N.toString(2);
const start = '10'; const end = '01';
let startIndex = binaryString.indexOf(start);
let endIndex = -1;
let binaryGap = 0;
// Remember that N is the
// input number, and when you iterate over its binary representation, its always
// log(N).
while (startIndex >= 0) {
endIndex = binaryString.indexOf(end, startIndex);
if (endIndex < 0) {
const tempGap = endIndex - startIndex;
binaryGap = tempGap > binaryGap ? tempGap : binaryGap;
startIndex = binaryString.indexOf(start, endIndex + 1);
endIndex = -1;
return binaryGap;
It’s so busy….and I hate it.
  • start is ‘10’
  • end is ‘01’
  • binaryString is like how we handled N in our solution.
  • We have startIndex equal the indexOf where ‘10’ (aka start) is at in the binaryString.

if(endIndex < 0 ) {
  • N and K are integers within the range [0..100];
  • each element of array A is an integer within the range [−1,000..1,000].
function solution(A, K) {
let arr = []
if(K === A.length) {
arr = A
} else {
A.forEach((i, index) => {
let numba = index - K
if(numba < 0) {
numba = index + (K - 1)
return arr
  • We make an empty array called arr.
  • If K equals the length of the A array, arr will be the A array.
  • If K isn’t the same as A’s length, then for each element in A, we’ll have numba equal the index of the A-element being looped through at that moment minus K.
  • If numba is less than 0, numba is going to equal { index + (K — 1) }
  • Then we push A[numba] into the arr array.
  • Then we return the arr array.
function solution(A, K) {     
K = (A.length > K) ? K : K % A.length;
var d = A.slice(0, A.length - K);
var e = A.splice(A.length - K);
return e.concat(d);
  • If the length of A is more than the argument passed in for K at the outset, then K stays as it is. Otherwise, K is going to be the remainder of K divided by A’s length.
  • d equals a slice of the A-array starting at the zero-index position ending at the index before the A.length-K .
  • e equals a splice of the A-array passing in A.length — K.
    This means that we will get the values of A from the zero-index position of the argument forward.
  • We return e concatenated with d.
This is a bit strange…but I’m rolling with it.




is a web developer, opera singer, actor, and lover of cats. (

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Being better at updating npm dependencies — part 1 of 2

Setting up Webpack, ESLint and Babel for React Applications

6 Majestic Google Chrome Extensions for Web Developers

Search and Filter Data in React Using Hooks

Desktop with cup that reads “Life begins at the end of your comfort zone.”

Everything You Need to Know about Angular

4 Useful JavaScript ES2020 Features that You Should Know

JavaScript ES2020 Features.

Redux — What is it?

My Hooking Adventure

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Rosales

Adrian Rosales

is a web developer, opera singer, actor, and lover of cats. (

More from Medium

How to extract a single agency from a GTFS file and use that to run OTP with Docker

Instance method, Class method, and Static method

Well Euled Machines — 5

Understanding Regex in Depth with Examples Part 1