Javascript counting valleys
function countingValleys(n, s) {
const min = 2;
const max = 1000000;
let isInValley = false;
let valleys = 0;
s = (typeof s === "string") ? s.split('') : s;
if (s.length >= min
&& s.length <= max
&& n === parseInt(n, 0)
&& n >= min
&& n <= max
&& n === s.length) {
s.map(steps => ((steps === "U") ? 1 : -1))
.reduce((prev, next) => {
if (prev < 0 && !isInValley) {
isInValley = true;
}
if ((prev + next) === 0 && isInValley) {
valleys++;
isInValley = false;
}
return prev + next;
});
}
return valleys;
}
Also in JavaScript:
- shadow elevation react native
- javascript get current month start and end date
- format money javascript commas
- javascript take first element of array
- if javascript
- javascript to uppercase
- add firebase javascript
- how to swap two images in javascript
- repeat a function javascript
- Authentication handling in javascript
- fire change event jquery
- difference between type and method in ajax
- decimal to base 32 javascript
- vue get height of element ref
- rotation in p5 play
- jquery check valid link
- how to check if a number is even or odd in javascript
- js combine two arrays
- ng has unexpectedly closed (exit code 127).
- remove first char javascript
- javascript prepend element to array
- javascript add minutes to date
- updatable time js
- node js + mongoose