Balanced brackets: Difference between revisions

Content added Content deleted
(→‎{{header|JavaScript}}: ES6 functional version)
m (→‎ES6 Functional: Added semi-colon preferred by JSHint after 'use strict')
Line 3,019: Line 3,019:
With visual indication of where the balance fails:
With visual indication of where the balance fails:
<lang JavaScript>(() => {
<lang JavaScript>(() => {
'use strict'
'use strict';


// Int -> String
// Int -> String
Line 3,041: Line 3,041:
else return tail.length ? errorIndex(
else return tail.length ? errorIndex(
tail, iNext, iIndex + 1
tail, iNext, iIndex + 1
) : iNext === 0 ? -1 : iIndex // balanced ? problem index ?
) : iNext === 0 ? -1 : iIndex; // balanced ? problem index ?


} else return iDepth === 0 ? -1 : iIndex;
} else return iDepth === 0 ? -1 : iIndex;
}
};


return errorIndex(strBrackets.split(''), 0, 0);
return errorIndex(strBrackets.split(''), 0, 0);
}
};




Line 3,077: Line 3,077:
})
})
.join('\n');
.join('\n');
})();</lang>
})();
</lang>


{{Out}}
{{Out}}