iT邦幫忙

2023 iThome 鐵人賽

DAY 2
0
Software Development

LELECOCODE 每一天系列 第 2

Day2: Leetcode 小挑戰,30 Days of JavaScript

  • 分享至 

  • xImage
  •  

Day2 : Counter

Given an integer n, return a counter function. This counter function initially returns n and then returns 1 more than the previous value every subsequent time it is called (n, n + 1, n + 2, etc).

var createCounter = function(n) {
    
    return function() {
        return n++;
    };
};

Example 1:
Input:
n = 10
["call","call","call"]
Output: [10,11,12]

Example 2:
Input:
n = -2
["call","call","call","call","call"]
Output: [-2,-1,0,1,2]

開始覺得這個 js 30天挑戰有點瞧不起人...
希望後面會變難,不然我花在文章排版的時間,還比較多==

var createCounter = function(n) {
    
    return function() {
        return n++;
    };
};

上一篇
Day1: Leetcode 小挑戰,30 Days of JavaScript
下一篇
Day3 : Leetcode 小挑戰,30 Days of JavaScript
系列文
LELECOCODE 每一天30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言