This file contains 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
1. | |
// !! double exclamation it returns boolean value true/false | |
const array = [0, 1, 2, 3, 0]; | |
array.filter(num => num > 0); // bad | |
array.filter(num => !!num); // good | |
2. | |
// It checks first condition is true or not then only move on to the second condition, if both condition is fullfilling then | |
// the object spread operator to the parent object |
This file contains 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 runningSum(nums: number[]): number[] { | |
let sum = [nums[0]]; | |
for(let i=1; i<nums.length; i++) { | |
sum[i] = sum[i-1] + nums[i]; | |
} | |
return sum; | |
} | |
runningSum([1,2,3,4,5,6,7,8,9,10) // return [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]; |