<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body><script> //封装一个函数, 求数组的和. //实例: console.log( sum([1, 2, 3, 4, 5]) ); 返回结果: 15; function sum(arr) { var res = 0; for (var i = 0; i < arr.length; i++) { res += arr[i]; } return res; } console.log(sum([1, 2, 3, 4, 5, 6, 7]));</script></body></html>
原文地址:https://www.cnblogs.com/yxs1530/p/10242463.html
时间: 2024-10-07 11:34:42