Stackline interview question

Given a function that takes in a variable that can be a nested object, an array or a primitive and another variable that represents a target value, write a function that returns true if it finds the target value within the object (or array or primitive), else returns false.

Interview Answer

Anonymous

16 Feb 2025

Used recursion to solve the problem. Set up a base case that returned true if the input needing to be checked was equal to the target value. Otherwise iterated through the array or object, having the function call itself recursively, and returned false if nothing was found.