Interview Question

Technical Support Specialist Interview

-San Diego, CA

ServiceNow

"You have a string of numbers, and you would like to return every even number within the set" A: to iterate thru the string, and modulus each number by 2, if it returns 0, the number is even and thus should be added to a list/array and output at the end"

Tags:http://www.w3schools.com/jsref/jsref_indexof.asp
AnswerAdd Tags

Interview Answers

2 Answers

2

Create a javascript to index and print. Must give a written example

Anonymous on

0

Split the string using the separator into an Array. Iterate through the Array members and perform type conversion on number from string to number and do a modulus by 2 operation. If the result returns 0, then number is even else its odd. If even, then push the number into a result array. Once all the elements gets processed, loop through the result array and print the resultant output.

Anonymous on

Add Answers or Comments

To comment on this, Sign In or Sign Up.