Decided to throw an error if the count is not greater than zero because a ninja won't bother spending energy on calling this secret technique for no purposes.
"use strict";/**
* Ninja secret call sound function
*
* @param {number} count The number of times the word "chirp" should be repeated
* @throws If the argument count is not valid
* @throws If the first argument is not a number
* @throws If the first argument is not greater than 0
* @return {string} The ninja secret call sound
* @example chirp(15);
*/functionchirp(count){if(arguments.length!==1){thrownewError("Expected exactly one parameter.");}if(typeofcount!=="number"){thrownewTypeError("First argument expected to be a number.");}if(count<=0){thrownewError("First argument expected to be greater or equal to 1.");}if(count===1){return"chirp.";}constdecreasedCount=count-1;return`chirp-${chirp(decreasedCount)}`;}console.log(chirp(4));console.log(chirp(3));console.log(chirp(2));console.log(chirp(1));console.log(chirp(0));
Training dojo available here (say chirp to enter).
re: Daily Challenge #88 - Recursive Ninjas VIEW POST
FULL DISCUSSIONJavaScript
Decided to throw an error if the count is not greater than zero because a ninja won't bother spending energy on calling this secret technique for no purposes.
Training dojo available here (say
chirp
to enter).