fwiw, another js option:
jsfiddle.net/4usxLhyo/1/
sorry, first post, not sure how to get the js syntax highlighting... Edit: thanks @elisabethgross for the syntax highlighting help!
console.clear() const one = '1,3,5,5,7,9,9'; const two = '2,4,5,6,8,9,9'; const three = '1,3,5,7,9'; const four = '2,4,6,8'; function findThings (str1, str2) { const arr1 = str1.split(','); const arr2 = str2.split(','); const result = []; for (const i of arr1) { if (arr2.indexOf(i) > -1) { result.push(i); arr2.splice(arr2.indexOf(i), 1); } } return result.length ? result : false; } console.log(findThings(one, two)); console.log(findThings(three, four )); ```
Nice! If you use the triple backticks, you can write javascript next to the top triple backticks. Check out this helpful markdown cheat sheet!
javascript
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
fwiw, another js option:
jsfiddle.net/4usxLhyo/1/
sorry, first post, not sure how to get the js syntax highlighting...
Edit: thanks @elisabethgross for the syntax highlighting help!
Nice! If you use the triple backticks, you can write
javascriptnext to the top triple backticks. Check out this helpful markdown cheat sheet!