Last active
September 2, 2025 12:52
-
-
Save ahmed1hsn/e28fdb26a7375c887afa22160508f3af to your computer and use it in GitHub Desktop.
Interview Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fruits = ["Apple", "Mango", "Orange", "Banana", "Kiwi"] | |
| const characters = [ "b", "c"] | |
| // Problem: find Longest fruit name which doens't contain any of thse characters. | |
| // Fruit Element Length | |
| // Character inclusion in Fruit Element. | |
| let fruitWithHighestLength = ""; | |
| for (const fruitElement of fruits) { | |
| // console.log(fruitElement); | |
| let fruitIncludesAnyCharacter = false; | |
| const fruitElementLengthGreater = fruitElement.length > fruitWithHighestLength?.length | |
| if (fruitElementLengthGreater) { | |
| for (const characterElement of characters) { | |
| // console.log(characterElement); | |
| if (fruitElement.toLocaleLowerCase().includes(characterElement)) { | |
| fruitIncludesAnyCharacter = true | |
| } | |
| } | |
| } | |
| if (fruitElementLengthGreater && !fruitIncludesAnyCharacter) { | |
| // console.log(fruitElement) | |
| fruitWithHighestLength = fruitElement | |
| } | |
| } | |
| console.log("fruitWithHighestLength:", fruitWithHighestLength) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment