-
Posts
6034 -
Joined
-
Last visited
-
Days Won
23
CoderDrag0n8's Achievements
3.2k
Reputation
Single Status Update
See all updates by CoderDrag0n8
-
// list {list} list that is being searched // index {var} variable that the list is being searched for // return {num} index of the variable that was searched for, if index did not exist in list, then it outputs the length of the list function backwardsList(list, index){ var backwardsOutput = list.length; for(var i=0;i<list.length;i++){ if (backwardsOutput==list[i]){ backwardsOutput = i; } } if (backwardsOutput==list.length) { console.log("No index found - backwardsList " + index); } return backwardsOutput; } // string {string} the input string // return {list} a list of all the individual words function splitStringSpaces(string){ var list = []; var singleWord = ""; var fullString = string + " "; for(var i=0; i<fullString.length; i++){ if (fullString[i]==" "){ appendItem(list, singleWord); singleWord = ""; } else { singleWord = singleWord + fullString[i]; } } return list; }
Just some code I made
def backwardsList(forwardsList, index): backwardsListOutput = "Not found" for i in forIndex(forwardsList): if (forwardsList[i]==index): backwardsListOutput = i if (backwardsListOutput=="Not found"): print(backwardsListOutput) backwardsListOutput = len(forwardsList) return backwardsListOutput def forIndex(indexList): return range(len(indexList))
This python one doesn't have splitStringSpaces, because I was to lazy, but it does have forIndex (In an attempt to make for loops easier in python, they are honestly better in javascript (Python loops are sometimes easier, but it isn't too hard to set up a javascript for loop that does basically the same thing, but trying to make a javascript for loop in python is just a pain)).
The python one also doesn't have comments, I'm too lazy to make them.
