Helloworld/test.js
Edhueppe 9e1c476fb3 add recursive function to get subfolders
Co-authored-by: Avior <github@avior.me>
2023-02-03 13:38:01 +01:00

31 lines
596 B
JavaScript

function pouet(liste) {
if (liste.length === 0) return []
const result = []
/**
* @type string | Array<string>
*/
const item = liste.pop()
if (typeof item === 'object') {
result.push(...pouet(item))
} else {
// typeof item === 'string'
if (item.charCodeAt(0) % 2 === 1) {
// item est pair
result.push(item)
}
}
result.push(...pouet(liste))
return result
}
(async () => {
const entree = ['a', ['b', 'c', 'd', ['e', ['f'], 'g'], 'h', 'i', 'j'], 'k', 'l', 'm', ['n', 'o', 'p'], 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
console.log(
pouet(entree)
)
})()