Skip to content

Commit 34836d4

Browse files
committed
add Space Complexity examples
1 parent 1615933 commit 34836d4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

big-o/double.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Space Complexity: O(n)space!
2+
3+
function double(arr){
4+
let newArr = [];
5+
6+
for(let i = 0; i < arr.length; i++){
7+
newArr.push(2 * arr[i]);
8+
}
9+
10+
return newArr;
11+
}

big-o/sum.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Space Complexity: O(1)space!
2+
3+
function sum(arr){
4+
let total = 0;
5+
6+
for(let i = 0 ; i < arr.length; i++){
7+
total += arr[i];
8+
}
9+
10+
return total;
11+
}

0 commit comments

Comments
 (0)