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 was able to run this code using an online compiler and it provided the right output, which is:
4
0
null
However, I installed JavaScript on Visual Studio and I can't seem to get it to produce the same output. I can see that I can change the "Show output from" to several different options, but none of them give me the output I'm looking for. The Debug option just keeps printing "Hello world."
This is the code:
function simpleSearch(target, arr) {
for (let i = 0; i < arr.length; i ) {
if (arr[i] === target) {
return i;
}
}
return null;
}
// Testing code, calls the function.
console.log(simpleSearch(5, [1, 2, 3, 4, 5])); // Should print 4
console.log(simpleSearch("a", ["a", "b", "c", "d", "e"])); // Should print 0
console.log(simpleSearch(2, ["a", "b", "c", "d", "e"])); // Should print null
Subreddit
Post Details
- Posted
- 9 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/CodingHelp/...