Created
October 13, 2022 14:14
-
-
Save sundicide/a16cee2914b3bf8ead06e6a0ce4e3bb6 to your computer and use it in GitHub Desktop.
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
| function solution(paramArr1, goal) { | |
| let result = 0; | |
| let lt = 0; | |
| let sum = 0; | |
| for (let rt = 0; rt < paramArr1.length; rt++) { | |
| sum += paramArr1[rt]; | |
| if (sum === goal) result++; | |
| while (sum >= goal) { | |
| sum -= paramArr1[lt++]; | |
| if (sum === goal) result++; | |
| } | |
| } | |
| return result; | |
| } | |
| const result = solution([1, 2, 1, 3, 1, 1, 1, 2], 6); | |
| expectEqualTest(result, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment