Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- IBM
- isSquare
- DB2
- TypeScript
- react
- manifest.json
- type
- codewar
- java api
- codewars
- TABLESPACE
- useEffect
- custom hook
- JDBC
- react hook
- Debug
- descendingOrder
Archives
- Today
- Total
taesik
Write a function called maxSubarraySum which accepts an array of integers and a number called n. 본문
functions and trick/typescript_javascript
Write a function called maxSubarraySum which accepts an array of integers and a number called n.
taesikk 2022. 4. 29. 11:39Write a function called maxSubarraySum which accepts an array of integers and a number called n.
The function should calculate the maximum sum of n consecutive elements in the array.
function maxSubarraySum(arr,num) {
let maxSum = 0;
let tempSum = 0;
if(arr.length < num) return null;
for(let i =0; i< num; i++) {
maxSum += arr[i];
}
tempSum = maxSum;
for(let i=num; i<arr.length; i++) {
tempSum = tempSum - arr[i-num] +arr[i];
maxSum = Math.max(maxSum, tempSum);
}
return maxSum;
}
'functions and trick > typescript_javascript' 카테고리의 다른 글
| isPrime (0) | 2022.05.03 |
|---|---|
| Implement a function called countUniqueValues(pointers pattern) (0) | 2022.04.29 |
| Write a function called sumZero which accepts a sorted array of integers. (0) | 2022.04.29 |
| check if two strings are ANAGRAM (using frequencyCounter) (0) | 2022.04.29 |
| retrun true if every value in the array has its corresponding value squared in the secone array. (0) | 2022.04.29 |