This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I recently started learning more and more about Javascript and have found some practice questions/scenarios and I sometimes google stuff on how to approach it or learn new commands, parameters, etc through the searches
I'm currently working on finding all instances of "waldo" within a string that I've set to lowercase. During my searches I found this and kind of want to rubberduck to see if my understanding is correct.
'a' is set as an empty array while the index value is set to -1 so it looks at the end of the string.
while the index value is equal to the index value of the substring location, it will add 1 to the index, as long as the index position is >=0.
It will push the accepted positions into 'a' and then return a'
function locations(substring,string){ var a=[],i=-1; while((i=string.indexOf(substring,i 1)) >= 0) a.push(i); return a; } console.log(locations("s","scissors")); //-> [0, 3, 4, 7]
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnjavasc...