Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 552 Bytes

count-pairs-loop-trace.md

File metadata and controls

26 lines (21 loc) · 552 Bytes

Count Pairs

Guess the output of the following code by writing a loop trace.

Note: Do not include the variable nums in the loop trace since its value never changes.

function countPairs(nums) {
    let left = 0;
    let count = 0;
    while (left < nums.length) {
        let right = left + 1;
        while (right < nums.length) {
            if (nums[left] + nums[right] === 100) {
                count++;
            }
            right++;
        }
        left++;
    }
    return count;

}
console.log(countPairs([70, 30, 70]));