Javascript Algorithms and Data Structures Challenge: Day 4

const arr = [];
for (let i = 0; i < 100; i++) {
arr.push(i + 1);
}
//You can use fill method to create the array, but I don't want to // memorize too many methods.function cycle(array) {
let last;
if (array.lenghth === 2) {
return array;
}

let short = array.filter((v, i, r) => {
if ((i + 1) % 3 === 0) {
last = i;
return false;
} else {
return true;
}
})


if (!last) {
return short ;
}

for (let i = 0; i < (array.length - 1 - last); i++) {
let tmp = short.pop(); //pop returns the actual ele.
short.unshift(tmp);
}


cycle(short);
}

console.log(remove(arr))

//[58,91]
var a = new Array(100).fill(0).map(function (ele, index) { return index + 1 });

var numberOff = 0;
var index = 0;

while (a.length > 2) {
numberOff++;
if (numberOff !== 3) {
index++;
} else {
numberOff = 0;
var number = a.splice(index, 1);
console.log(number); // [3], [6], [9], …
}
if (index >= a.length) index = 0;
}

console.log(a); // [58, 91]

coder, founder and explorer.

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

Recommended from Medium

Javascript Tutorial

A look into the new Keele University website search

How to get more traffic to your Javascript posts

https://medium.com/streamrblog/streamr-testnet-review-530e3bbaedf 最新的交換+質押的網ㄓㄢ

How to write a browser game in pure Elixir — Part 1

Typescript: Tips and Tricks for Improving Your Coding skills [Part 2]

A Little Bit Easier with Each Step…

Remove Rich Text Formatting in Flows

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
FRANK GO

FRANK GO

coder, founder and explorer.

More from Medium

What is a Linked List? How to Implement Singly Linked List in JavaScript

A visual represenataion of a linked list

JavaScript : Hosing Explained Well…

What is Functions vs Methods w.r.t. JS? 🤔

React JS and its Advantages: A Quick Guide