Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 6e28146

Browse files
committed
complete alternatingSums
1 parent 5dd331e commit 6e28146

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

alphabetSubSequence/alphabetSubSequence.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ function alphabetSubsequence(s: string): boolean {
22
s = s.split('');
33
let arr = [];
44
for (let i = 0; i < s.length; i++){
5-
arr.push(arr[i].charAt());
5+
arr.push(s[i].charCodeAt());
66
}
77
for (let j = 0; j < arr.length - 1; j++){
8-
if (arr[j] < arr[j + 1]){
8+
if (arr[j] <= arr[j + 1]){
99
continue;
1010
} else {
1111
return false;

alternatingSums/alternatingSums.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
function alternatingSums(a: number[]): number[] {
2-
2+
let odds = 0
3+
let evens = 0;
4+
for (let i = 0; i < a.length; i++){
5+
if (i % 2 !== 0){
6+
odds += a[i];
7+
} else {
8+
evens += a[i];
9+
}
10+
}
11+
return [evens, odds];
312
}
413

514
console.log(alternatingSums([50, 60, 60, 45, 70]))

0 commit comments

Comments
 (0)