31 lines
596 B
JavaScript
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)
|
|
)
|
|
})()
|