2222 * A function that takes a single input value and returns a single value.
2323 * Returns a simple concatenation of Strings.
2424 *
25- * @param {String } name A name to greet.
26- * @return {String } A greeting.
25+ * @param {string } name A name to greet.
26+ * @return {string } A greeting.
2727 * @customfunction
2828 */
2929function SAY_HELLO ( name ) {
@@ -35,8 +35,8 @@ function SAY_HELLO(name) {
3535 * range of cells.
3636 * Returns a range with all the input values incremented by one.
3737 *
38- * @param {Array } input The range of numbers to increment.
39- * @return {Array } The incremented values.
38+ * @param {any } input The range of numbers to increment.
39+ * @return {any } The incremented values.
4040 * @customfunction
4141 */
4242function INCREMENT ( input ) {
@@ -55,8 +55,8 @@ function INCREMENT(input) {
5555 * Returns the sum the corner values in the range; for a single cell,
5656 * this is equal to (4 * the cell value).
5757 *
58- * @param {Array } input The Range of numbers to sum the corners of.
59- * @return {Number } The calculated sum.
58+ * @param {number | number[][] } input The Range of numbers to sum the corners of.
59+ * @return {number } The calculated sum.
6060 * @customfunction
6161 */
6262function CORNER_SUM ( input ) {
@@ -65,8 +65,8 @@ function CORNER_SUM(input) {
6565 return CORNER_SUM ( [ [ input ] ] ) ; // eslint-disable-line new-cap
6666 }
6767 // Range processing here.
68- var maxRowIndex = input . length - 1 ;
69- var maxColIndex = input [ 0 ] . length - 1 ;
68+ const maxRowIndex = input . length - 1 ;
69+ const maxColIndex = input [ 0 ] . length - 1 ;
7070 return input [ 0 ] [ 0 ] + input [ 0 ] [ maxColIndex ] +
7171 input [ maxRowIndex ] [ 0 ] + input [ maxRowIndex ] [ maxColIndex ] ;
7272}
@@ -76,20 +76,21 @@ function CORNER_SUM(input) {
7676 * Returns a range consisting of the first 10 powers and roots of that
7777 * number (with column headers).
7878 *
79- * @param {Number } input The number to calculate from.
80- * @return {Array } The first ten powers and roots of that number,
81- * with associated labels.
79+ * @param {number } input The number to calculate from.
80+ * @return {Array<Array<string|number>> } The first ten powers and roots of that
81+ * number, with associated labels.
8282 * @customfunction
8383 */
8484function POWERS_AND_ROOTS ( input ) {
85- if ( input instanceof Array ) {
86- throw new Error ( 'Invalid: Range input not permitted ' ) ;
85+ if ( typeof input !== 'number' ) {
86+ throw new Error ( 'Invalid: A single number is required. ' ) ;
8787 }
8888 // Value processing and range generation here.
89- var headers = [ 'x' , input + '^x' , input + '^(1/x)' ] ;
90- var result = [ headers ] ;
91- for ( var i = 1 ; i <= 10 ; i ++ ) {
92- result . push ( [ i , Math . pow ( input , i ) , Math . pow ( input , 1 / i ) ] ) ;
89+ const headers = [ 'x' , input . toString ( ) + '^x' , input . toString ( ) + '^(1/x)' ] ;
90+ /** @type {Array<Array<string|number>> } */
91+ const result = [ headers ] ;
92+ for ( let i = 1 ; i <= 10 ; i ++ ) {
93+ result . push ( [ i , Math . pow ( input , i ) , Math . pow ( input , 1 / i ) ] ) ;
9394 }
9495 return result ;
9596}
@@ -99,17 +100,17 @@ function POWERS_AND_ROOTS(input) {
99100 * Returns the day of the year represented by the provided date.
100101 *
101102 * @param {Date } date A Date to examine.
102- * @return {Number } The day of year for that date.
103+ * @return {number } The day of year for that date.
103104 * @customfunction
104105 */
105106function GET_DAY_OF_YEAR ( date ) {
106107 if ( ! ( date instanceof Date ) ) {
107108 throw new Error ( 'Invalid: Date input required' ) ;
108109 }
109110 // Date processing here.
110- var firstOfYear = new Date ( date . getFullYear ( ) , 0 , 0 ) ;
111- var diff = date - firstOfYear ;
112- var oneDay = 1000 * 60 * 60 * 24 ;
111+ const firstOfYear = new Date ( date . getFullYear ( ) , 0 , 0 ) ;
112+ const diff = date . getTime ( ) - firstOfYear . getTime ( ) ;
113+ const oneDay = 1000 * 60 * 60 * 24 ;
113114 return Math . floor ( diff / oneDay ) ;
114115}
115116
@@ -118,7 +119,7 @@ function GET_DAY_OF_YEAR(date) {
118119 * Returns the number of seconds measured by that duration.
119120 *
120121 * @param {Date } duration A duration to convert.
121- * @return {Number } Number of seconds in that duration.
122+ * @return {number } Number of seconds in that duration.
122123 * @customfunction
123124 */
124125function CONVERT_DURATION_TO_SECONDS ( duration ) {
0 commit comments