Created
September 11, 2023 05:57
-
-
Save danieloneill/e82445aa864187bdf373badec9c6d87e to your computer and use it in GitHub Desktop.
Qt Quick polyfills for Array.flat, String.endsWith, and String.startsWith
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.import 'polyjank.js' as PJ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'polyjank.js' as PJ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.pragma library | |
Array.prototype.flat = function(depthArg=1) { | |
const getElems = function(arr, elems=[]) { | |
for( let a of arr ) | |
{ | |
if( typeof a === 'object' ) | |
elems = getElems(a, elems); | |
else | |
elems.push(a); | |
} | |
return elems; | |
}; | |
// depthArg is ignored because who even uses it anyway. | |
return getElems(this); | |
} | |
String.prototype.endsWith = function(wut) { | |
return this.substr( this.length-wut.length ) === wut; | |
} | |
String.prototype.startsWith = function(wut) { | |
return this.substr( 0, wut.length ) === wut; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment