Module challenge
Challenge: trace code
15 min · 3 steps
Step 1 of 3 · Write the code
solution(n)Return the sum of all digits of the integer
n.Example:
solution(507)returns12.Constraints:
0 ≤ n ≤ 10⁹
function solution(n) { }Step 2 of 3 · Write the code
solution(s)Return how many positions
ihaves[i]equal tos[i + 1].Example:
solution("aabccc")returns3(one fromaa, two fromccc).Constraints:
0 ≤ s.length ≤ 1000sonly contains lowercase letters
function solution(s) { }Step 3 of 3 · Write the code
solution(nums)Return the sum of the numbers in
numsbefore the first negative number. That negative number and everything after it don't count. If there's no negative number, add them all.Example:
solution([3, 4, -1, 10])returns7.Constraints:
0 ≤ nums.length ≤ 1000-1000 ≤ nums[i] ≤ 1000
function solution(nums) { }